Spaces:
Running
Running
改成可搜尋,並且換成2.5pro模型
Browse files
gemini.py
CHANGED
|
@@ -8,8 +8,11 @@ from io import BytesIO
|
|
| 8 |
import markdown
|
| 9 |
from bs4 import BeautifulSoup
|
| 10 |
from flask import Flask, abort, request, send_from_directory
|
|
|
|
| 11 |
from google import genai
|
| 12 |
from google.genai import types
|
|
|
|
|
|
|
| 13 |
from linebot.v3 import WebhookHandler
|
| 14 |
from linebot.v3.exceptions import InvalidSignatureError
|
| 15 |
from linebot.v3.messaging import (
|
|
@@ -32,9 +35,11 @@ from PIL import Image
|
|
| 32 |
# === 初始化 Google Gemini ===
|
| 33 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
| 34 |
client = genai.Client(api_key=GOOGLE_API_KEY)
|
| 35 |
-
chat = client.chats.create(model="gemini-2.
|
| 36 |
-
config=
|
| 37 |
-
system_instruction="你是一個中文的AI助手,請用繁體中文回答"
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
)
|
| 40 |
|
|
|
|
| 8 |
import markdown
|
| 9 |
from bs4 import BeautifulSoup
|
| 10 |
from flask import Flask, abort, request, send_from_directory
|
| 11 |
+
|
| 12 |
from google import genai
|
| 13 |
from google.genai import types
|
| 14 |
+
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
|
| 15 |
+
|
| 16 |
from linebot.v3 import WebhookHandler
|
| 17 |
from linebot.v3.exceptions import InvalidSignatureError
|
| 18 |
from linebot.v3.messaging import (
|
|
|
|
| 35 |
# === 初始化 Google Gemini ===
|
| 36 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
| 37 |
client = genai.Client(api_key=GOOGLE_API_KEY)
|
| 38 |
+
chat = client.chats.create(model="gemini-2.5-pro-preview-05-06",
|
| 39 |
+
config=GenerateContentConfig(
|
| 40 |
+
system_instruction="你是一個中文的AI助手,請用繁體中文回答",
|
| 41 |
+
tools=[google_search_tool],
|
| 42 |
+
response_modalities=["TEXT"],
|
| 43 |
)
|
| 44 |
)
|
| 45 |
|