huchiahsi commited on
Commit
fffec3f
·
1 Parent(s): 277c948

提交with_search

Browse files
Files changed (1) hide show
  1. with_search.py +5 -8
with_search.py CHANGED
@@ -9,14 +9,8 @@ from flask import Flask, abort, request
9
  from bs4 import BeautifulSoup
10
  import markdown
11
 
12
- from google import genai
13
- from google.genai import types # 加入system prompot所需的types模組
14
  from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
15
 
16
- google_search_tool = Tool(
17
- google_search = GoogleSearch()
18
- )
19
-
20
  from linebot.v3 import WebhookHandler
21
  from linebot.v3.exceptions import InvalidSignatureError
22
  from linebot.v3.messaging import (
@@ -54,8 +48,11 @@ handler = WebhookHandler(channel_secret)
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
 
61
  @app.route("/", methods=["GET"])
 
9
  from bs4 import BeautifulSoup
10
  import markdown
11
 
 
 
12
  from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
13
 
 
 
 
 
14
  from linebot.v3 import WebhookHandler
15
  from linebot.v3.exceptions import InvalidSignatureError
16
  from linebot.v3.messaging import (
 
48
 
49
  def query(payload: str) -> str:
50
  """Send a prompt to Gemini and return the response text."""
51
+ try:
52
+ response = chat.send_message(message=payload)
53
+ return response.text
54
+ except Exception as e:
55
+ return f"發生錯誤:{e}"
56
 
57
 
58
  @app.route("/", methods=["GET"])