alanchen1115 commited on
Commit
d201588
·
verified ·
1 Parent(s): 9b8e6e3

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -14
main.py CHANGED
@@ -172,26 +172,20 @@ def analyze_image_with_text(image_path: str, user_text: str) -> str:
172
  tools = [generate_and_upload_image, analyze_image_with_text]
173
 
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
- prompt_template = '''
184
  ("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
185
- ("user", "{input}")
186
- '''
 
 
187
 
188
- prompt = PromptTemplate.from_template(prompt_template)
189
-
190
- # 建立代理人,使用 create_react_agent
191
- react_agent = create_react_agent(llm, tools,prompt)
192
  agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
193
 
194
-
195
  # ==========================
196
  # FastAPI 路由
197
  # ==========================
 
172
  tools = [generate_and_upload_image, analyze_image_with_text]
173
 
174
  # 建立 LLM 模型實例
175
+ llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.5-flash", temperature=0.2)
176
 
177
  # 建立提示模板
178
+ prompt_template = ChatPromptTemplate.from_messages([
 
 
 
 
 
179
  ("system", "你是一個強大的助理,可以根據用戶的請求使用提供的工具。"),
180
+ ("user", "{input}"),
181
+ # 修正此處的語法,使用字串 "{agent_scratchpad}"
182
+ ("placeholder", "{agent_scratchpad}"),
183
+ ])
184
 
185
+ # 建立代理人
186
+ agent = create_tool_calling_agent(llm, tools, prompt_template)
 
 
187
  agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
188
 
 
189
  # ==========================
190
  # FastAPI 路由
191
  # ==========================