Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -23,7 +23,7 @@ import uvicorn
|
|
| 23 |
from langchain_core.prompts import ChatPromptTemplate
|
| 24 |
from langchain_core.tools import tool
|
| 25 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 26 |
-
from langchain.agents import
|
| 27 |
|
| 28 |
|
| 29 |
# ==========================
|
|
@@ -173,7 +173,7 @@ tools = [generate_and_upload_image, analyze_image_with_text]
|
|
| 173 |
llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.5-flash", temperature=0.2)
|
| 174 |
|
| 175 |
# 建立提示模板
|
| 176 |
-
prompt_template = ChatPromptTemplate
|
| 177 |
("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
|
| 178 |
("user", "{input}"),
|
| 179 |
("placeholder", "{agent_scratchpad}"),
|
|
@@ -245,11 +245,9 @@ def handle_message(event):
|
|
| 245 |
# 運行代理人
|
| 246 |
response = agent_executor.invoke(agent_input)
|
| 247 |
out = response["output"]
|
| 248 |
-
print('out')
|
| 249 |
if 'https' in out:
|
| 250 |
img_tmp = 'https'+out.split('https')[1]
|
| 251 |
image_url = img_tmp.split('png')[0]+'png'
|
| 252 |
-
print('image_url',image_url)
|
| 253 |
line_bot_api.push_message(
|
| 254 |
event.source.user_id,
|
| 255 |
[
|
|
|
|
| 23 |
from langchain_core.prompts import ChatPromptTemplate
|
| 24 |
from langchain_core.tools import tool
|
| 25 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 26 |
+
from langchain.agents import AgentExecutor, create_tool_calling_agent
|
| 27 |
|
| 28 |
|
| 29 |
# ==========================
|
|
|
|
| 173 |
llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.5-flash", temperature=0.2)
|
| 174 |
|
| 175 |
# 建立提示模板
|
| 176 |
+
prompt_template = ChatPromptTemplate([
|
| 177 |
("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
|
| 178 |
("user", "{input}"),
|
| 179 |
("placeholder", "{agent_scratchpad}"),
|
|
|
|
| 245 |
# 運行代理人
|
| 246 |
response = agent_executor.invoke(agent_input)
|
| 247 |
out = response["output"]
|
|
|
|
| 248 |
if 'https' in out:
|
| 249 |
img_tmp = 'https'+out.split('https')[1]
|
| 250 |
image_url = img_tmp.split('png')[0]+'png'
|
|
|
|
| 251 |
line_bot_api.push_message(
|
| 252 |
event.source.user_id,
|
| 253 |
[
|