Update app.py
Browse files
app.py
CHANGED
@@ -75,6 +75,37 @@ def chat_pdf_ep(content: Text = None):
|
|
75 |
return JSONResponse(content=content)
|
76 |
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
@app.post("/sale")
|
79 |
def sale_ep(content: Text = None):
|
80 |
url = 'https://api.openai.com/v1/chat/completions'
|
|
|
75 |
return JSONResponse(content=content)
|
76 |
|
77 |
|
78 |
+
@app.post("/dic")
|
79 |
+
def dic_ep(content: Text = None):
|
80 |
+
url = 'https://api.openai.com/v1/chat/completions'
|
81 |
+
messages = [
|
82 |
+
{
|
83 |
+
"role": "system",
|
84 |
+
"content": "你是一个小鹏汽车的数据智能中心(简称DIC)的智能助手,可以使用文章内容准确地回答问题。使用提供的文章来生成HTML格式的答案,但避免逐字复制文章。准确、有用、简洁、清晰。"
|
85 |
+
}
|
86 |
+
]
|
87 |
+
obj = json.loads(content.content)
|
88 |
+
messages.append({"role": "system", "content": "文章内容:\n" + obj['doc']})
|
89 |
+
history = obj['history']
|
90 |
+
for his in history:
|
91 |
+
messages.append({"role": "user", "content": his[0]})
|
92 |
+
messages.append({"role": "assistant", "content": his[1]})
|
93 |
+
messages.append({"role": "user", "content": obj['question']})
|
94 |
+
data = {
|
95 |
+
"model": "gpt-3.5-turbo",
|
96 |
+
"messages": messages
|
97 |
+
}
|
98 |
+
print("messages = \n", messages)
|
99 |
+
result = requests.post(url=url,
|
100 |
+
data=json.dumps(data),
|
101 |
+
headers=headers
|
102 |
+
)
|
103 |
+
res = str(result.json()['choices'][0]['message']['content']).strip()
|
104 |
+
content = {'content': res}
|
105 |
+
print('content:', content)
|
106 |
+
return JSONResponse(content=content)
|
107 |
+
|
108 |
+
|
109 |
@app.post("/sale")
|
110 |
def sale_ep(content: Text = None):
|
111 |
url = 'https://api.openai.com/v1/chat/completions'
|