Update main.py
Browse files
main.py
CHANGED
|
@@ -21,6 +21,27 @@ line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
|
| 21 |
line_handler = WebhookHandler(os.environ["CHANNEL_SECRET"])
|
| 22 |
# 設定是否正在與使用者交談
|
| 23 |
working_status = os.getenv("DEFALUT_TALKING", default = "true").lower() == "true"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# 建立 FastAPI 應用程式
|
| 26 |
app = FastAPI()
|
|
|
|
| 21 |
line_handler = WebhookHandler(os.environ["CHANNEL_SECRET"])
|
| 22 |
# 設定是否正在與使用者交談
|
| 23 |
working_status = os.getenv("DEFALUT_TALKING", default = "true").lower() == "true"
|
| 24 |
+
# ==========================
|
| 25 |
+
# LangChain 代理人設定
|
| 26 |
+
# ==========================
|
| 27 |
+
|
| 28 |
+
# 結合所有工具
|
| 29 |
+
tools = [generate_and_upload_image, analyze_image_with_text]
|
| 30 |
+
|
| 31 |
+
# 建立 LLM 模型實例
|
| 32 |
+
llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.5-flash-lite", temperature=0.2)
|
| 33 |
+
|
| 34 |
+
# 建立提示模板
|
| 35 |
+
prompt_template = ChatPromptTemplate([
|
| 36 |
+
("system", "你是一個強大的虛擬穿搭助理,可以根據用戶的請求使用提供的工具。當你執行 generate_and_upload_image 工具\
|
| 37 |
+
成功後,你將會獲得一個圖片的包含https的完整網址,你的任務是將這個包含https的完整網址回傳。如果工具有產生錯誤訊息請解讀回應。"),
|
| 38 |
+
("user", "{input}"),
|
| 39 |
+
("placeholder", "{agent_scratchpad}"),
|
| 40 |
+
])
|
| 41 |
+
|
| 42 |
+
# 建立代理人
|
| 43 |
+
agent = create_tool_calling_agent(llm, tools, prompt_template)
|
| 44 |
+
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
| 45 |
|
| 46 |
# 建立 FastAPI 應用程式
|
| 47 |
app = FastAPI()
|