Spaces:
Sleeping
Sleeping
alanchen1115
commited on
Commit
•
df7b5e5
1
Parent(s):
cdb7b92
Update main.py
Browse files
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 |
-
|
62 |
|
63 |
-
|
64 |
working_status = True
|
65 |
line_bot_api.reply_message(
|
66 |
event.reply_token,
|
67 |
TextSendMessage(text="Bye!"))
|
68 |
return
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
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))
|