huchiahsi commited on
Commit
943002f
·
1 Parent(s): 4fc65d7

將設定移動到建立chat的地方

Browse files
Files changed (1) hide show
  1. with_search.py +7 -8
with_search.py CHANGED
@@ -32,7 +32,12 @@ from linebot.v3.webhooks import MessageEvent, TextMessageContent
32
  # Initialize Google Gemini
33
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
34
  client = genai.Client(api_key=GOOGLE_API_KEY)
35
- chat = client.chats.create(model="gemini-2.0-flash")
 
 
 
 
 
36
 
37
  # Initialize Flask app
38
  app = Flask(__name__)
@@ -49,13 +54,7 @@ handler = WebhookHandler(channel_secret)
49
 
50
  def query(payload: str) -> str:
51
  """Send a prompt to Gemini and return the response text."""
52
- response = chat.send_message(
53
- config=GenerateContentConfig(
54
- system_instruction="你是一個中文的AI助手,請用繁體中文回答"),
55
- tools=[google_search_tool],
56
- response_modalities=["TEXT"],
57
- message=payload
58
- )
59
  return response.text
60
 
61
 
 
32
  # Initialize Google Gemini
33
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
34
  client = genai.Client(api_key=GOOGLE_API_KEY)
35
+ chat = client.chats.create(model="gemini-2.0-flash",
36
+ config=GenerateContentConfig(
37
+ system_instruction="你是一個中文的AI助手,請用繁體中文回答",
38
+ tools=[google_search_tool],
39
+ response_modalities=["TEXT"],
40
+ ))
41
 
42
  # Initialize Flask app
43
  app = Flask(__name__)
 
54
 
55
  def query(payload: str) -> str:
56
  """Send a prompt to Gemini and return the response text."""
57
+ response = chat.send_message(message=payload)
 
 
 
 
 
 
58
  return response.text
59
 
60