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