Spaces:
Sleeping
Sleeping
Update ai_service.py
Browse files- ai_service.py +6 -5
ai_service.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
-
# ai_service.py (
|
| 2 |
import json
|
| 3 |
from datetime import datetime
|
| 4 |
import google.generativeai as genai
|
| 5 |
from gradio_client import Client
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 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 |
-
# [修正]
|
| 113 |
response = chat.send_message(
|
| 114 |
-
|
| 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 根據工具結果生成最終回覆 ---")
|