izuemon commited on
Commit
3c9ecd7
·
verified ·
1 Parent(s): 4281abb

Update chatgpt.py

Browse files
Files changed (1) hide show
  1. chatgpt.py +11 -2
chatgpt.py CHANGED
@@ -101,14 +101,23 @@ def main():
101
  time.sleep(10)
102
  continue
103
 
104
- # 最新メッセージをトリガーにする
105
- latest = messages[-1]
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: