alanchen1115 commited on
Commit
df7b5e5
1 Parent(s): cdb7b92

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -17
main.py CHANGED
@@ -58,29 +58,32 @@ def handle_message(event):
58
  global working_status
59
 
60
  if event.type != "message" or event.message.type != "text":
61
- out = "Gemini: [No response or the response does not contain text]"
62
 
63
- if event.message.text == "再見":
64
  working_status = True
65
  line_bot_api.reply_message(
66
  event.reply_token,
67
  TextSendMessage(text="Bye!"))
68
  return
69
-
70
- messages = []
71
- if working_status:
72
- message = event.message.text
73
- messages.append({
74
- "role": "user",
75
- "parts": [message],
76
- })
77
-
78
- response = model.generate_content(messages)
79
- out = response.parts[0].text
80
- # Check if response is valid
81
- if not response.parts or not response.parts[0].text:
82
- out = "Gemini: [No response or the response does not contain text]"
83
-
 
 
 
84
  line_bot_api.reply_message(
85
  event.reply_token,
86
  TextSendMessage(text=out))
 
58
  global working_status
59
 
60
  if event.type != "message" or event.message.type != "text":
61
+ TextSendMessage(text="Gemini: [No response or the response does not contain text]")
62
 
63
+ elif event.message.text == "再見":
64
  working_status = True
65
  line_bot_api.reply_message(
66
  event.reply_token,
67
  TextSendMessage(text="Bye!"))
68
  return
69
+
70
+ elif working_status:
71
+ try:
72
+ messages = []
73
+ message = event.message.text
74
+ messages.append({
75
+ "role": "user",
76
+ "parts": [message],
77
+ })
78
+
79
+ response = model.generate_content(messages)
80
+ out = response.parts[0].text
81
+ # Check if response is valid
82
+ if not response.parts or not response.parts[0].text:
83
+ out = "Gemini: [No response or the response does not contain text]"
84
+ except:
85
+ out = "Gemini: [No response or the response does not contain text]"
86
+
87
  line_bot_api.reply_message(
88
  event.reply_token,
89
  TextSendMessage(text=out))