cwadayi commited on
Commit
04a59fe
·
verified ·
1 Parent(s): 98c1ae1

Update ai_service.py

Browse files
Files changed (1) hide show
  1. ai_service.py +6 -5
ai_service.py CHANGED
@@ -1,10 +1,11 @@
1
- # ai_service.py (Final Version with 'Part' import fix)
2
  import json
3
  from datetime import datetime
4
  import google.generativeai as genai
5
  from gradio_client import Client
6
- # [修正] 從 google.generativeai.types 匯入 Part 類別
7
- from google.generativeai.types import Part
 
8
 
9
  # 從設定檔匯入金鑰和 URL
10
  from config import GEMINI_API_KEY, MCP_SERVER_URL
@@ -109,9 +110,9 @@ def generate_ai_text(user_prompt: str) -> str:
109
  tool_result = tool_function(**dict(function_call.args))
110
  print("--- 將工具結果回傳給 Gemini ---")
111
 
112
- # [修正] genai.Part 改為 Part (因為我們已經從 types 模組匯入)
113
  response = chat.send_message(
114
- Part(function_response={"name": function_call.name, "response": {"result": tool_result}}),
115
  )
116
 
117
  print("--- Gemini 根據工具結果生成最終回覆 ---")
 
1
+ # ai_service.py (Definitive fix for the ImportError)
2
  import json
3
  from datetime import datetime
4
  import google.generativeai as genai
5
  from gradio_client import Client
6
+
7
+ # [修正] 移除 'Part' 的 import,因為它導致了錯誤
8
+ # from google.generativeai.types import Part
9
 
10
  # 從設定檔匯入金鑰和 URL
11
  from config import GEMINI_API_KEY, MCP_SERVER_URL
 
110
  tool_result = tool_function(**dict(function_call.args))
111
  print("--- 將工具結果回傳給 Gemini ---")
112
 
113
+ # [修正] 直接傳送包含 function_response 的字典,不再使用 Part 類別
114
  response = chat.send_message(
115
+ {"function_response": {"name": function_call.name, "response": {"result": tool_result}}}
116
  )
117
 
118
  print("--- Gemini 根據工具結果生成最終回覆 ---")