Spaces:
Sleeping
Sleeping
修复AI发送消息显示错误、天气预报时间错误和文档回答AI回复错误
Browse files
app.py
CHANGED
|
@@ -322,14 +322,14 @@ def respond(
|
|
| 322 |
|
| 323 |
response = ""
|
| 324 |
|
| 325 |
-
for
|
| 326 |
messages,
|
| 327 |
max_tokens=max_tokens,
|
| 328 |
stream=True,
|
| 329 |
temperature=0.7, # 降低温度让回复更直接
|
| 330 |
top_p=0.9, # 调整top-p参数
|
| 331 |
):
|
| 332 |
-
choices =
|
| 333 |
token = ""
|
| 334 |
if len(choices) and choices[0].delta.content:
|
| 335 |
token = choices[0].delta.content
|
|
@@ -690,7 +690,6 @@ with gr.Blocks() as demo:
|
|
| 690 |
response += "\n\n🌫️ 今天有雾,开车请注意安全。"
|
| 691 |
elif "🌸" in response:
|
| 692 |
response += "\n\n🌸 樱花盛开的季节,适合赏花拍照。"
|
| 693 |
-
|
| 694 |
elif any(keyword in message.lower() for keyword in ["时间", "日期", "datetime", "time", "几点", "现在"]):
|
| 695 |
# 模拟时间响应
|
| 696 |
from datetime import datetime
|
|
@@ -835,9 +834,9 @@ with gr.Blocks() as demo:
|
|
| 835 |
# 发送实际请求
|
| 836 |
messages = [{"role": "user", "content": prompt}]
|
| 837 |
response = ""
|
| 838 |
-
for
|
| 839 |
-
if
|
| 840 |
-
response +=
|
| 841 |
break
|
| 842 |
except Exception as e:
|
| 843 |
print(f"模型 {model_name} 连接失败: {str(e)}")
|
|
|
|
| 322 |
|
| 323 |
response = ""
|
| 324 |
|
| 325 |
+
for message_chunk in client.chat_completion(
|
| 326 |
messages,
|
| 327 |
max_tokens=max_tokens,
|
| 328 |
stream=True,
|
| 329 |
temperature=0.7, # 降低温度让回复更直接
|
| 330 |
top_p=0.9, # 调整top-p参数
|
| 331 |
):
|
| 332 |
+
choices = message_chunk.choices
|
| 333 |
token = ""
|
| 334 |
if len(choices) and choices[0].delta.content:
|
| 335 |
token = choices[0].delta.content
|
|
|
|
| 690 |
response += "\n\n🌫️ 今天有雾,开车请注意安全。"
|
| 691 |
elif "🌸" in response:
|
| 692 |
response += "\n\n🌸 樱花盛开的季节,适合赏花拍照。"
|
|
|
|
| 693 |
elif any(keyword in message.lower() for keyword in ["时间", "日期", "datetime", "time", "几点", "现在"]):
|
| 694 |
# 模拟时间响应
|
| 695 |
from datetime import datetime
|
|
|
|
| 834 |
# 发送实际请求
|
| 835 |
messages = [{"role": "user", "content": prompt}]
|
| 836 |
response = ""
|
| 837 |
+
for doc_chunk in client.chat_completion(messages, max_tokens=150, stream=False):
|
| 838 |
+
if doc_chunk.choices and doc_chunk.choices[0].delta.content:
|
| 839 |
+
response += doc_chunk.choices[0].delta.content
|
| 840 |
break
|
| 841 |
except Exception as e:
|
| 842 |
print(f"模型 {model_name} 连接失败: {str(e)}")
|