Exploration and Practice of ChatGPT - Business Application | JD Cloud Technical Team

This article mainly introduces how to use GPT to help develop and optimize the process in the actual development process. It coincides with the 20th anniversary of JD.com this year. At the end of the article, it will introduce how to combine it with the actual business of the 618 promotion to enhance the application value. All are dry goods, and all codes and scripts in this article are generated using GPT, please rest assured to eat.

Scenario 1: Writing code

Using GPT for code development is one of the things that many people do the most. As long as you describe your needs clearly in natural language, you can let GPT write an executable code segment, or even a complete application. And as long as the description is clear and clear enough, the generated code will have no bugs and is very efficient.

To give an example of practical application, in the previous version, our project had a requirement to revise the yellow bar UI on the landing page. The specific requirement is described as follows:

UI design draft:

This is a fairly simple requirement. We are going to use Flutter for development. Now suppose I am a developer who does not know much about the dart language, or even someone who has never developed a foundation for Flutter. Through GPT, we can also perform this simple requirement. Development work. When describing GPT, try to describe your needs clearly in fluent language, and name the key information:

In this way, GPT can help us generate the required view code:

This is very friendly to developers who have not been exposed to the dart development language. Since the programming language can be specified arbitrarily, in theory, all of us can be competent for full-platform development.

I summarize the main points when using GPT for code development:

1. The main information must be clearly expressed, such as language type, target type, width, height, color, font size, spacing and other values.

2. Imagine yourself as a product manager or designer, don't stick to technical terms, such as UIview, Segment, tags, etc., and use natural language expression as much as possible.

3. Do not have contradictory descriptions, 100% will produce bugs.

4. Some students tend to be nervous when describing their needs, resulting in language barriers. Don't worry when describing, just speak slowly.

5. Do not involve in secrets! No secrets! No secrets! In the final analysis, GPT is an external tool software, not a "tree hole" where you can ask any questions, and questions involving commercial secrets cannot be asked.

Scenario 2: Writing scripts

This is an application scenario that I often use. For some highly repetitive tasks, scripting is obviously the best choice. Some of my colleagues even think that the future development direction is scripting. The development of scripts can also be handed over to GPT. For example, we have a requirement. Due to the access to the basic library of the main station, we have conflicts in the class names of some tool classes. In this case, we need to replace the class names of the entire project. This scenario is very suitable for using scripts.

Under normal circumstances, it takes at least 1 to 2 hours to write such a script, and it takes about half an hour for a skilled boss, but using GPT, a script that meets the requirements can be generated in a few seconds. Several application scenarios I have summarized are very suitable for scripting:

1. Full project-level name replacement

2. APP picture name replacement

3. Unit testing

4. Convert natural language

Let’s talk about the function of converting natural language. As a developer, it is more customary to input key values ​​to get the result, but what GPT needs is a description in natural language. After all, it is called "chat", so we can play a trick: use A simple script that inputs a value, outputs a natural language description, and then relays the description to GPT.

width = int(input("请输入宽度:"))
height = int(input("请输入高度:"))
color = input("请输入颜色:")

view = '#' * width + '\n'
view += ('#' + ' ' * (width - 2) + '#\n') * (height - 2)
view += '#' * width

description = f"生成一个宽度为{width},高度为{height}的视图,使用{color}颜色填充。"

print(view)
print(description)


Similar to this conversion script, it allows us to use GPT more efficiently.

Scenario 3: Combining with actual business

At the end of my previous article, I mentioned several ideas for combining GPT with actual business:

shopping guide

Integrate ChatGPT's service into the search function. When users search, use its powerful functions to give users buying opinions. For users who haven't decided whether to buy, what to buy, or even what to buy, Give guiding opinions to promote conversion rate.

soft text creation

In our project, there are applicable scenarios for the display of soft advertising articles. Compared with manual creation and writing, ChatGPT is not only more efficient, but also combines big data trends to provide users with more interesting article types. Creating promotional event recommendations, product reviews, new product news and other articles, using ChatGPT has a lot to do.

Inverse campaign recommendation

We can't decide what kind of answer a user will give when he asks ChatGPT, but we can do reverse deduction based on her answer, what he recommends, we will do what activities according to the trend, so that we can take advantage of the dividends brought by ChatGPT , and can save the overhead and risk of predicting the user's point of interest.

after sales

ChatGPT is essentially a conversational artificial intelligence. It is actually the most suitable to use him to access the after-sales system. With his help, it can be foreseen that users complain that the robot customer service does not answer the questions, cannot solve the problem, and the cost of manual customer service is high. become history.

I think each of these ideas can be put into practical application and landed, and they all have considerable use value. Next, I will mainly introduce how to use GPT for 618 promotion shopping guide.

First of all, users search for a certain product, mainly through the search bar. To guide GPT access to search, we need to build a basic environment by ourselves, pass the keywords entered by the user to GPT, and then output GPT The results are displayed to the user. The role of the basic environment is not only as a "server" to call GPT, but also to "process" the user's input and the output of GPT. Relevant information, and finally achieve the purpose of "big promotion and shopping guide".

The first part: Packaging the user's input, such as wrapping the user's keywords with a layer of "search with JD":

def search_keyword(keyword):
    url="https://search.jd.com/Search?keyword={keyword}"
    response = requests.get(url)
    soup = BeautifulSoup(response.text, "html.parser")

    #提取相关介绍
    introduction = soup.select_one(".p-parameter").get_text(strip=True)
    return introduction

#用户输入关键词
user_input = input("请输入关键词:")

#调用函数进行搜索和提取介绍
result = search_keyword(user_input)

prompt="打开京东网站,618大促活动商品里搜索 {user_input},并给出其相关介绍"
#这里的prompt既为向GTP提问的问题,由于GPT接受的是自然语言,所以这里我们可以任意的添加我们想要的导向性描述,例如“618大促活动商品”、“618精选活动”、“京东20周年庆优惠”等等


The second part: use the packaged copy as an input parameter, and call the API of GPT to make a request

api_endpoint = "https://api.openai.com/v1/chat/completions"
access_token = "你的access_token"
 
params = {
    "messages": [{"role": "user", "content": prompt}],
    "temperature": 0.7,
    "model": "gpt-3.5-turbo"
}
headers = {
    "Authorization": "Bearer {access_token}",
    "Content-Type": "application/json"
}
response = requests.post(api_endpoint, headers=headers, json=params)


Part 3: Parse the results returned by GPT and display them according to our needs

if response.status_code == 200:
    response_text = json.loads(response.text)["choices"][0]["message"]["content"]
    # 输出结果
    print("为您在京东推荐了如下结果: {response_text}")
    print("您商品的相关介绍:{result}”)
else:
    print(f"error: {response.status_code} - {response.text}")


Divergent thinking: GTP accepts natural language inquiries, so we can arbitrarily add the desired limited information to the questions we ask him, and even combine the configuration system to combine "618 promotional products" and "618 featured products" Activities", "Jingdong 20th Anniversary Promotion" and other activities are combined as configuration information into the prompt parameter field to realize dynamic configuration activity shopping guide.

Author: JD Retail Jiang Hai

Source: JD Cloud Developer Community

RustDesk 1.2: Using Flutter to rewrite the desktop version, supporting Wayland's alleged GPT-4 model architecture leak: Contains 1.8 trillion parameters, using a mixed expert model (MoE) Musk announced the establishment of xAI company deepin V23 successfully adapted WSL CentOS project claims " Open to all" Rust 1.71.0 Stable Release React Is it having an Angular.js moment? Microsoft launches a new default font, Aptos, to replace CalibriMicrosoft : Increase efforts to use Rust IntelliJ IDEA 2023.1.4 release on Windows 11
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4090830/blog/10089143