Spaces:
Sleeping
Sleeping
Update chatgpt.py
Browse files- chatgpt.py +11 -2
chatgpt.py
CHANGED
|
@@ -101,14 +101,23 @@ def main():
|
|
| 101 |
time.sleep(10)
|
| 102 |
continue
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
latest = messages
|
| 106 |
msg_id = latest.get("id")
|
|
|
|
| 107 |
|
|
|
|
| 108 |
if msg_id in processed:
|
| 109 |
time.sleep(10)
|
| 110 |
continue
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
chat_messages = build_chat_messages(messages)
|
| 113 |
|
| 114 |
if not chat_messages:
|
|
|
|
| 101 |
time.sleep(10)
|
| 102 |
continue
|
| 103 |
|
| 104 |
+
# createdAt が最大のメッセージを「最後のメッセージ」とする
|
| 105 |
+
latest = max(messages, key=lambda m: m.get("createdAt", 0))
|
| 106 |
msg_id = latest.get("id")
|
| 107 |
+
latest_person_id = latest.get("personId")
|
| 108 |
|
| 109 |
+
# すでに処理済みなら待機
|
| 110 |
if msg_id in processed:
|
| 111 |
time.sleep(10)
|
| 112 |
continue
|
| 113 |
|
| 114 |
+
# 最後のメッセージがアシスタントなら GPT に送らず待機
|
| 115 |
+
if latest_person_id == ASSISTANT_PERSON_ID:
|
| 116 |
+
print("最後のメッセージがアシスタントのため待機")
|
| 117 |
+
processed.add(msg_id)
|
| 118 |
+
time.sleep(10)
|
| 119 |
+
continue
|
| 120 |
+
|
| 121 |
chat_messages = build_chat_messages(messages)
|
| 122 |
|
| 123 |
if not chat_messages:
|