Update main.py
Browse files
main.py
CHANGED
@@ -17,7 +17,7 @@ genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
|
|
17 |
generation_config = genai.types.GenerationConfig(max_output_tokens=2048, temperature=0.2, top_p=0.5, top_k=16)
|
18 |
|
19 |
# 使用 Gemini-1.5-flash 模型
|
20 |
-
model = genai.GenerativeModel('gemini-
|
21 |
|
22 |
# 設定 Line Bot 的 API 金鑰和秘密金鑰
|
23 |
line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
@@ -98,6 +98,9 @@ def analyze_with_gemini(image_path, user_text):
|
|
98 |
organ = PIL.Image.open(image_path)
|
99 |
chat = model.start_chat(history=history)
|
100 |
response = chat.send_message([user_text, organ])
|
|
|
|
|
|
|
101 |
|
102 |
# 提取回應內容
|
103 |
return response.parts[0].text
|
@@ -143,10 +146,7 @@ def handle_image_message(event):
|
|
143 |
|
144 |
# 結合圖片與文字分析
|
145 |
out = analyze_with_gemini(image_path, user_text)
|
146 |
-
|
147 |
-
history.append({"role": "user", "parts": [user_text]})
|
148 |
-
if GeneAI:
|
149 |
-
history.append({"role": "model", "parts": [GeneAI]})
|
150 |
|
151 |
else:
|
152 |
global working_status
|
|
|
17 |
generation_config = genai.types.GenerationConfig(max_output_tokens=2048, temperature=0.2, top_p=0.5, top_k=16)
|
18 |
|
19 |
# 使用 Gemini-1.5-flash 模型
|
20 |
+
model = genai.GenerativeModel('gemini-2.0-flash-exp', system_instruction="請用繁體中文回答。你現在是個專業助理,職稱為OPEN小助理,個性活潑、樂觀,願意回答所有問題", generation_config=generation_config)
|
21 |
|
22 |
# 設定 Line Bot 的 API 金鑰和秘密金鑰
|
23 |
line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
|
|
98 |
organ = PIL.Image.open(image_path)
|
99 |
chat = model.start_chat(history=history)
|
100 |
response = chat.send_message([user_text, organ])
|
101 |
+
GeneAI = out
|
102 |
+
history.append({"role": "user", "parts": [user_text]})
|
103 |
+
history.append({"role": "model", "parts": [response.parts[0].text]})
|
104 |
|
105 |
# 提取回應內容
|
106 |
return response.parts[0].text
|
|
|
146 |
|
147 |
# 結合圖片與文字分析
|
148 |
out = analyze_with_gemini(image_path, user_text)
|
149 |
+
|
|
|
|
|
|
|
150 |
|
151 |
else:
|
152 |
global working_status
|