Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -177,7 +177,6 @@ llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.5-flash"
|
|
| 177 |
prompt_template = ChatPromptTemplate.from_messages([
|
| 178 |
("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
|
| 179 |
("user", "{input}"),
|
| 180 |
-
# 修正此處的語法,使用字串 "{agent_scratchpad}"
|
| 181 |
("placeholder", "{agent_scratchpad}"),
|
| 182 |
])
|
| 183 |
|
|
@@ -248,11 +247,23 @@ def handle_message(event):
|
|
| 248 |
response = agent_executor.invoke(agent_input)
|
| 249 |
out = response["output"]
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
except Exception as e:
|
| 252 |
print(f"代理人執行出錯: {e}")
|
| 253 |
out = f"代理人執行出錯!請換個說法或稍後再試!錯誤訊息:{e}"
|
| 254 |
-
|
| 255 |
-
line_bot_api.reply_message(event.reply_token, TextSendMessage(text=out))
|
| 256 |
|
| 257 |
if __name__ == "__main__":
|
| 258 |
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
|
|
|
| 177 |
prompt_template = ChatPromptTemplate.from_messages([
|
| 178 |
("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
|
| 179 |
("user", "{input}"),
|
|
|
|
| 180 |
("placeholder", "{agent_scratchpad}"),
|
| 181 |
])
|
| 182 |
|
|
|
|
| 247 |
response = agent_executor.invoke(agent_input)
|
| 248 |
out = response["output"]
|
| 249 |
|
| 250 |
+
if 'htts' in out:
|
| 251 |
+
img_tmp = out.split('https')[1]
|
| 252 |
+
image_url = img_tmp.split('png')[0]
|
| 253 |
+
|
| 254 |
+
if image_url:
|
| 255 |
+
# 使用 push message 發送圖片,避免 rep.ly token 超時
|
| 256 |
+
line_bot_api.push_message(
|
| 257 |
+
event.source.user_id,
|
| 258 |
+
[
|
| 259 |
+
TextSendMessage(text="✨ 這是我為你生成的圖片喔~"),
|
| 260 |
+
ImageSendMessage(original_content_url=image_url, preview_image_url=image_url)
|
| 261 |
+
]
|
| 262 |
+
)
|
| 263 |
except Exception as e:
|
| 264 |
print(f"代理人執行出錯: {e}")
|
| 265 |
out = f"代理人執行出錯!請換個說法或稍後再試!錯誤訊息:{e}"
|
| 266 |
+
line_bot_api.reply_message(event.reply_token, TextSendMessage(text=out))
|
|
|
|
| 267 |
|
| 268 |
if __name__ == "__main__":
|
| 269 |
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|