Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,8 @@ def get_text_emb(open_ai_key, text):
|
|
| 26 |
data=json.dumps(data),
|
| 27 |
headers=headers
|
| 28 |
)
|
| 29 |
-
|
|
|
|
| 30 |
return result.json()['data'][0]['embedding']
|
| 31 |
|
| 32 |
|
|
@@ -112,6 +113,7 @@ def get_response(open_ai_key, msg, bot, doc_text_list, doc_embeddings): # 获
|
|
| 112 |
data=json.dumps(data),
|
| 113 |
headers=headers
|
| 114 |
)
|
|
|
|
| 115 |
res = str(result.json()['choices'][0]['message']['content']).strip()
|
| 116 |
bot.append([msg, res]) # 加入历史记录
|
| 117 |
return bot[max(0, len(bot) - 3):] # 返回最近3轮的历史记录
|
|
|
|
| 26 |
data=json.dumps(data),
|
| 27 |
headers=headers
|
| 28 |
)
|
| 29 |
+
if result.status_code != 200:
|
| 30 |
+
raise Exception('API请求出错,状态码为:' + str(result.status_code) + ',错误信息为:' + result.json())
|
| 31 |
return result.json()['data'][0]['embedding']
|
| 32 |
|
| 33 |
|
|
|
|
| 113 |
data=json.dumps(data),
|
| 114 |
headers=headers
|
| 115 |
)
|
| 116 |
+
print("result = \n", result.json())
|
| 117 |
res = str(result.json()['choices'][0]['message']['content']).strip()
|
| 118 |
bot.append([msg, res]) # 加入历史记录
|
| 119 |
return bot[max(0, len(bot) - 3):] # 返回最近3轮的历史记录
|