Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -247,11 +247,19 @@ def handle_message(event):
|
|
| 247 |
agent_input = {"input": f"請分析這張圖片 {image_path},問題是:{user_text}"}
|
| 248 |
user_message_history[user_id].pop()
|
| 249 |
else:
|
| 250 |
-
agent_input = {"
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
try:
|
| 253 |
response = agent_executor.invoke(agent_input)
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
# 搜尋 URL 邏輯
|
| 257 |
urls = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', out)
|
|
|
|
| 247 |
agent_input = {"input": f"請分析這張圖片 {image_path},問題是:{user_text}"}
|
| 248 |
user_message_history[user_id].pop()
|
| 249 |
else:
|
| 250 |
+
agent_input = {"messages": [("user", user_text)]}
|
| 251 |
+
# try:
|
| 252 |
+
# response = agent_executor.invoke(agent_input)
|
| 253 |
+
# out = response["output"]
|
| 254 |
+
|
| 255 |
+
# 1. 修正輸入格式:LangGraph 預期接收 'messages',格式為 (角色, 內容) 的列表
|
| 256 |
+
agent_input = {"messages": [("user", user_text)]}
|
| 257 |
try:
|
| 258 |
response = agent_executor.invoke(agent_input)
|
| 259 |
+
|
| 260 |
+
# 2. 修正輸出解析:response 是一個字典,裡面包含了完整的 'messages' 歷史紀錄
|
| 261 |
+
# 列表中的最後一則訊息 ([-1]) 就是 Agent 最終的回答
|
| 262 |
+
out = response["messages"][-1].content
|
| 263 |
|
| 264 |
# 搜尋 URL 邏輯
|
| 265 |
urls = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', out)
|