Evaaaaa06 commited on
Commit
dc6b1ef
·
verified ·
1 Parent(s): 91cdf08

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -2
main.py CHANGED
@@ -113,7 +113,8 @@ def get_previous_message(user_id):
113
  # 返回最後一則訊息
114
  return user_message_history[user_id][-1]
115
  return None
116
-
 
117
  @line_handler.add(MessageEvent, message=(ImageMessage,TextMessage))
118
  def handle_image_message(event):
119
  user_id = event.source.user_id
@@ -141,9 +142,12 @@ def handle_image_message(event):
141
 
142
  # 結合圖片與文字分析
143
  out = analyze_with_gemini(image_path, user_text)
 
144
 
145
  else:
146
  global working_status
 
 
147
  # 檢查事件類型和訊息類型
148
  if event.type != "message" or event.message.type != "text":
149
  # 回覆錯誤訊息
@@ -167,7 +171,7 @@ def handle_image_message(event):
167
 
168
  history = [{"role": "user", "parts": [store_user_message]}]
169
  if out:
170
- history.append({"role": "model", "parts": [out]})
171
 
172
  # 使用 Gemini 模型生成文字
173
  chat = model.start_chat(history=history)
@@ -176,6 +180,7 @@ def handle_image_message(event):
176
  if (completion.parts[0].text != None):
177
  # 取得生成結果
178
  out = completion.parts[0].text
 
179
  else:
180
  # 回覆 "Gemini沒答案!請換個說法!"
181
  out = "我不太懂什麼意思也~"
 
113
  # 返回最後一則訊息
114
  return user_message_history[user_id][-1]
115
  return None
116
+
117
+ GeneAI = ""
118
  @line_handler.add(MessageEvent, message=(ImageMessage,TextMessage))
119
  def handle_image_message(event):
120
  user_id = event.source.user_id
 
142
 
143
  # 結合圖片與文字分析
144
  out = analyze_with_gemini(image_path, user_text)
145
+ GeneAI = out
146
 
147
  else:
148
  global working_status
149
+ global GeneAI
150
+
151
  # 檢查事件類型和訊息類型
152
  if event.type != "message" or event.message.type != "text":
153
  # 回覆錯誤訊息
 
171
 
172
  history = [{"role": "user", "parts": [store_user_message]}]
173
  if out:
174
+ history.append({"role": "model", "parts": [GeneAI]})
175
 
176
  # 使用 Gemini 模型生成文字
177
  chat = model.start_chat(history=history)
 
180
  if (completion.parts[0].text != None):
181
  # 取得生成結果
182
  out = completion.parts[0].text
183
+ GeneAI = out
184
  else:
185
  # 回覆 "Gemini沒答案!請換個說法!"
186
  out = "我不太懂什麼意思也~"