Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -21,6 +21,7 @@ import uvicorn
|
|
| 21 |
|
| 22 |
# LangChain 相關匯入
|
| 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 create_react_agent, AgentExecutor
|
|
@@ -173,15 +174,17 @@ tools = [generate_and_upload_image, analyze_image_with_text]
|
|
| 173 |
# 建立 LLM 模型實例
|
| 174 |
llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.0-flash", temperature=0.2)
|
| 175 |
|
| 176 |
-
#
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
| 182 |
|
| 183 |
# 建立代理人,使用 create_react_agent
|
| 184 |
-
react_agent = create_react_agent(llm, tools)
|
| 185 |
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
| 186 |
|
| 187 |
|
|
|
|
| 21 |
|
| 22 |
# LangChain 相關匯入
|
| 23 |
from langchain_core.prompts import ChatPromptTemplate
|
| 24 |
+
from langchain.prompts import PromptTemplate
|
| 25 |
from langchain_core.tools import tool
|
| 26 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 27 |
from langchain.agents import create_react_agent, AgentExecutor
|
|
|
|
| 174 |
# 建立 LLM 模型實例
|
| 175 |
llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.0-flash", temperature=0.2)
|
| 176 |
|
| 177 |
+
# 建立提示模板
|
| 178 |
+
prompt_template = ChatPromptTemplate.from_messages([
|
| 179 |
+
("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
|
| 180 |
+
("user", "{input}"),
|
| 181 |
+
("placeholder", "{agent_scratchpad}"),
|
| 182 |
+
])
|
| 183 |
+
|
| 184 |
+
prompt = PromptTemplate.from_template(prompt_template)
|
| 185 |
|
| 186 |
# 建立代理人,使用 create_react_agent
|
| 187 |
+
react_agent = create_react_agent(llm, tools,prompt)
|
| 188 |
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
| 189 |
|
| 190 |
|