B2O
Browse files
app.py
CHANGED
|
@@ -6,8 +6,7 @@ import requests
|
|
| 6 |
import json
|
| 7 |
import openai
|
| 8 |
import time
|
| 9 |
-
|
| 10 |
-
import langchain
|
| 11 |
|
| 12 |
class Text(BaseModel):
|
| 13 |
content: str = ""
|
|
@@ -31,7 +30,7 @@ def home():
|
|
| 31 |
@app.post("/qa_maker")
|
| 32 |
def sentiment_analysis_ep(content: Text = None):
|
| 33 |
url = 'https://api.openai.com/v1/chat/completions'
|
| 34 |
-
prompt = '
|
| 35 |
messages = [{"role": "user", "content": prompt + content.content}]
|
| 36 |
data = {
|
| 37 |
"model": "gpt-3.5-turbo",
|
|
@@ -54,11 +53,11 @@ def chat_pdf_ep(content: Text = None):
|
|
| 54 |
messages = [
|
| 55 |
{
|
| 56 |
"role": "system",
|
| 57 |
-
"content": "
|
| 58 |
}
|
| 59 |
]
|
| 60 |
obj = json.loads(content.content)
|
| 61 |
-
messages.append({"role": "system", "content": "
|
| 62 |
history = obj['history']
|
| 63 |
for his in history:
|
| 64 |
messages.append({"role": "user", "content": his[0]})
|
|
@@ -85,11 +84,11 @@ def sale_ep(content: Text = None):
|
|
| 85 |
messages = [
|
| 86 |
{
|
| 87 |
"role": "system",
|
| 88 |
-
"content": "
|
| 89 |
}
|
| 90 |
]
|
| 91 |
obj = json.loads(content.content)
|
| 92 |
-
messages.append({"role": "system", "content": "
|
| 93 |
history = obj['history']
|
| 94 |
for his in history:
|
| 95 |
messages.append({"role": "user", "content": his[0]})
|
|
@@ -173,22 +172,6 @@ def embeddings_ep(content: Text = None):
|
|
| 173 |
return JSONResponse(content=result.json())
|
| 174 |
|
| 175 |
|
| 176 |
-
|
| 177 |
-
@app.post("/embedd")
|
| 178 |
-
def embed(content: Text = None):
|
| 179 |
-
url = 'https://api.openai.com/v1/embeddings'
|
| 180 |
-
data = {
|
| 181 |
-
"model": "text-embedding-ada-002",
|
| 182 |
-
"input": content.content
|
| 183 |
-
}
|
| 184 |
-
result = requests.post(url=url,
|
| 185 |
-
data=json.dumps(data),
|
| 186 |
-
headers=headers
|
| 187 |
-
)
|
| 188 |
-
embeddings = OpenAIEmbeddings(openai_api_key= key)
|
| 189 |
-
return key
|
| 190 |
-
|
| 191 |
-
|
| 192 |
@app.post("/create_image")
|
| 193 |
def create_image_ep(content: Text = None):
|
| 194 |
url = 'https://api.openai.com/v1/images/generations'
|
|
@@ -203,4 +186,4 @@ def create_image_ep(content: Text = None):
|
|
| 203 |
data=json.dumps(data),
|
| 204 |
headers=headers
|
| 205 |
)
|
| 206 |
-
return JSONResponse(content=result.json())
|
|
|
|
| 6 |
import json
|
| 7 |
import openai
|
| 8 |
import time
|
| 9 |
+
|
|
|
|
| 10 |
|
| 11 |
class Text(BaseModel):
|
| 12 |
content: str = ""
|
|
|
|
| 30 |
@app.post("/qa_maker")
|
| 31 |
def sentiment_analysis_ep(content: Text = None):
|
| 32 |
url = 'https://api.openai.com/v1/chat/completions'
|
| 33 |
+
prompt = '根据下面的文章,生成的“问题和回答”QA对,大于5个,以一行一个json格式({“question”:"xxx","answer":"xxx"})生成:\n'
|
| 34 |
messages = [{"role": "user", "content": prompt + content.content}]
|
| 35 |
data = {
|
| 36 |
"model": "gpt-3.5-turbo",
|
|
|
|
| 53 |
messages = [
|
| 54 |
{
|
| 55 |
"role": "system",
|
| 56 |
+
"content": "你是一个有用的助手,可以使用文章内容准确地回答问题。使用提供的文章来生成你的答案,但避免逐字复制文章。尽可能使用自己的话。准确、有用、简洁、清晰。"
|
| 57 |
}
|
| 58 |
]
|
| 59 |
obj = json.loads(content.content)
|
| 60 |
+
messages.append({"role": "system", "content": "文章内容:\n" + obj['doc']})
|
| 61 |
history = obj['history']
|
| 62 |
for his in history:
|
| 63 |
messages.append({"role": "user", "content": his[0]})
|
|
|
|
| 84 |
messages = [
|
| 85 |
{
|
| 86 |
"role": "system",
|
| 87 |
+
"content": "你是小鹏汽车资深的销售,可以参考文章内容来生成你的答案,但避免逐字复制文章,尽可能使用自己的话,突出小鹏汽车的优点、说服用户来店试驾或购买小鹏汽车。准确、有用、有销售技巧、口语化、有亲和力。"
|
| 88 |
}
|
| 89 |
]
|
| 90 |
obj = json.loads(content.content)
|
| 91 |
+
messages.append({"role": "system", "content": "文章内容:\n" + obj['doc']})
|
| 92 |
history = obj['history']
|
| 93 |
for his in history:
|
| 94 |
messages.append({"role": "user", "content": his[0]})
|
|
|
|
| 172 |
return JSONResponse(content=result.json())
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
@app.post("/create_image")
|
| 176 |
def create_image_ep(content: Text = None):
|
| 177 |
url = 'https://api.openai.com/v1/images/generations'
|
|
|
|
| 186 |
data=json.dumps(data),
|
| 187 |
headers=headers
|
| 188 |
)
|
| 189 |
+
return JSONResponse(content=result.json())
|