hazelhh commited on
Commit
f0c8815
·
verified ·
1 Parent(s): 66bc22e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -0
main.py CHANGED
@@ -217,6 +217,21 @@ def analyze_image_with_text(image_url: str, user_text: str) -> str:
217
 
218
  return out
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  # ==========================# FastAPI 路由# ==========================#
221
  @app.get("/")
222
  def root():
 
217
 
218
  return out
219
 
220
+ # ==========================# LangChain 代理人設定# ==========================#
221
+ # 結合所有工具
222
+ tools = [generate_outfit_from_clothes, analyze_image_with_text]
223
+ # 建立 LLM 模型實例
224
+ llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.5-flash", temperature=0.2)
225
+ # 建立提示模板
226
+ prompt_template = ChatPromptTemplate([
227
+ ("system", "你是一個強大的圖像生成與問答助理,可以根據用戶的請求使用提供的工具。當你執行 generate_and_upload_image 工具\ 成功後會獲得一個 URL,然後你回答的 output 要包含有這個 URL 的完整資訊。如果工具有產生錯誤訊息請解讀並回應。"),
228
+ ("user", "{input}"),
229
+ ("placeholder", "{agent_scratchpad}"),
230
+ ])
231
+ # 建立代理人
232
+ agent = create_tool_calling_agent(llm, tools, prompt_template)
233
+ agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
234
+
235
  # ==========================# FastAPI 路由# ==========================#
236
  @app.get("/")
237
  def root():