Update app.py
Browse files
app.py
CHANGED
@@ -14,12 +14,13 @@ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
|
14 |
def respond(message, history):
|
15 |
# 將當前訊息與歷史訊息合併
|
16 |
input_text = message if not history else history[-1]["content"] + " " + message
|
|
|
17 |
# 獲取模型的回應
|
18 |
-
response = pipe(input_text, max_length=100, num_return_sequences=1)
|
19 |
reply = response[0]['generated_text']
|
20 |
|
21 |
# 返回新的消息格式
|
22 |
-
return
|
23 |
|
24 |
# 設定 Gradio 的聊天界面
|
25 |
demo = gr.ChatInterface(fn=respond, title="Chat with Qwen 2.5", description="與 HelloSun/Qwen2.5-0.5B-Instruct-openvino 聊天!", type='messages')
|
|
|
14 |
def respond(message, history):
|
15 |
# 將當前訊息與歷史訊息合併
|
16 |
input_text = message if not history else history[-1]["content"] + " " + message
|
17 |
+
|
18 |
# 獲取模型的回應
|
19 |
+
response = pipe(input_text, max_length=100, truncation=True, num_return_sequences=1)
|
20 |
reply = response[0]['generated_text']
|
21 |
|
22 |
# 返回新的消息格式
|
23 |
+
return [{"role": "user", "content": message}, {"role": "assistant", "content": reply}]
|
24 |
|
25 |
# 設定 Gradio 的聊天界面
|
26 |
demo = gr.ChatInterface(fn=respond, title="Chat with Qwen 2.5", description="與 HelloSun/Qwen2.5-0.5B-Instruct-openvino 聊天!", type='messages')
|