3v324v23 commited on
Commit
f4e61f3
·
1 Parent(s): 04897f8

使用gemini的chat函式可以記得多輪對話

Browse files
Files changed (1) hide show
  1. gemini.py +5 -4
gemini.py CHANGED
@@ -28,6 +28,10 @@ from PIL import Image
28
  GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
29
  google_client = genai.Client(api_key=GOOGLE_API_KEY)
30
  text_system_prompt = "你是一個中文的AI助手,請用繁體中文回答"
 
 
 
 
31
 
32
  # === 初始設定 ===
33
  static_tmp_path = tempfile.gettempdir()
@@ -50,10 +54,7 @@ handler = WebhookHandler(channel_secret)
50
 
51
  # === AI Query 包裝 ===
52
  def query(payload):
53
- response = google_client.models.generate_content(
54
- model="gemini-2.0-flash",
55
- contents=f"{text_system_prompt}:{payload}",
56
- )
57
  return response.text
58
 
59
 
 
28
  GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
29
  google_client = genai.Client(api_key=GOOGLE_API_KEY)
30
  text_system_prompt = "你是一個中文的AI助手,請用繁體中文回答"
31
+ chat = google_client.chats.create(
32
+ model="gemini-2.0-flash",
33
+ system_prompt=text_system_prompt,
34
+ )
35
 
36
  # === 初始設定 ===
37
  static_tmp_path = tempfile.gettempdir()
 
54
 
55
  # === AI Query 包裝 ===
56
  def query(payload):
57
+ response = chat.send_message(payload)
 
 
 
58
  return response.text
59
 
60