hampters commited on
Commit
23d1277
·
verified ·
1 Parent(s): 3514048
Files changed (1) hide show
  1. main.py +5 -5
main.py CHANGED
@@ -12,10 +12,10 @@ from linebot.models import MessageEvent, TextMessage, TextSendMessage, ImageSend
12
  genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
13
 
14
  # 設定生成文字的參數
15
- generation_config = genai.types.GenerationConfig(max_output_tokens=2048, temperature=0.2, top_p=0.5, top_k=16)
16
 
17
  # 使用 Gemini-1.5-flash 模型
18
- model = genai.GenerativeModel('gemini-1.5-flash', system_instruction="你是聖誕老人,請使用招牌笑聲做開頭,然後以爽朗愉悅的口氣回答問題。") # 或是使用 "你是博通古今的萬應機器人!"
19
 
20
  # 設定 Line Bot 的 API 金鑰和秘密金鑰
21
  line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
@@ -88,11 +88,11 @@ def handle_message(event):
88
  # 取得使用者輸入的文字
89
  prompt = event.message.text
90
  # 使用 Gemini 模型生成文字
91
- completion = model.generate_content(prompt, generation_config=generation_config)
92
  # 檢查生成結果是否為空
93
- if (completion.parts[0].text != None):
94
  # 取得生成結果
95
- out = completion.parts[0].text
96
  else:
97
  # 回覆 "Gemini沒答案!請換個說法!"
98
  out = "Gemini沒答案!請換個說法!"
 
12
  genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
13
 
14
  # 設定生成文字的參數
15
+ generation_config = genai.types.GenerationConfig(max_output_tokens=4000, temperature=1, top_p=0.95, top_k=40)
16
 
17
  # 使用 Gemini-1.5-flash 模型
18
+ model = genai.GenerativeModel('gemini-2.0-flash-exp', system_instruction="請使用招牌笑聲做開頭,然後以爽朗愉悅的口氣回答問題。") # 或是使用 "你是博通古今的萬應機器人!"
19
 
20
  # 設定 Line Bot 的 API 金鑰和秘密金鑰
21
  line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
 
88
  # 取得使用者輸入的文字
89
  prompt = event.message.text
90
  # 使用 Gemini 模型生成文字
91
+ response = model.start_chat(prompt, generation_config=generation_config)
92
  # 檢查生成結果是否為空
93
+ if (response.parts[0].text != None):
94
  # 取得生成結果
95
+ out = response.parts[0].text
96
  else:
97
  # 回覆 "Gemini沒答案!請換個說法!"
98
  out = "Gemini沒答案!請換個說法!"