youngtsai commited on
Commit
2f6a936
1 Parent(s): 3341bca

while time.time() - start_time < max_wait_time:

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1043,13 +1043,21 @@ def chat_with_youtube_transcript(youtube_id, thread_id, user_message, chat_histo
1043
  instructions=instructions,
1044
  )
1045
 
1046
- # check run status
1047
- while run.status == "running":
1048
- time.sleep(3)
1049
- run = client.beta.threads.runs.retrieve(
1050
- thread_id=thread.id,
 
 
 
 
 
1051
  run_id=run.id
1052
  )
 
 
 
1053
 
1054
  # 获取助手的响应消息
1055
  messages = client.beta.threads.messages.list(thread_id=thread.id)
 
1043
  instructions=instructions,
1044
  )
1045
 
1046
+ # 等待助手响应,设定最大等待时间为 30
1047
+ max_wait_time = 30
1048
+ start_time = time.time()
1049
+ while time.time() - start_time < max_wait_time:
1050
+ print("=== 等待助手响应 ===")
1051
+ print(f"run.status: {run.status}")
1052
+ print(f"time.time() - start_time: {time.time() - start_time}")
1053
+ print("=== 等待助手响应 ===")
1054
+ run_status = client.beta.threads.runs.retrieve(
1055
+ thread_id=thread_id,
1056
  run_id=run.id
1057
  )
1058
+ if run_status.status != "running":
1059
+ break
1060
+ time.sleep(3) # 每3秒检查一次状态
1061
 
1062
  # 获取助手的响应消息
1063
  messages = client.beta.threads.messages.list(thread_id=thread.id)