youngtsai commited on
Commit
92aaf71
1 Parent(s): dc2cf7e

response_text = messages[-1].content.text.value

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1002,8 +1002,8 @@ def chat_with_youtube_transcript(youtube_id, thread_id, user_message, chat_histo
1002
  client = OPEN_AI_CLIENT
1003
  instructions = f"""
1004
  你是一個擅長資料分析跟影片教學的老師,user 為學生
1005
- 請找到 file youtube_id = {youtube_id} 為資料文本,自行判斷資料的種類,
1006
- 如果 file 沒有資料,請告訴用戶沒有逐字稿資料,但仍然可以進行對話
1007
 
1008
  並進行對話,使用 zh-TW
1009
  如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
@@ -1046,12 +1046,9 @@ def chat_with_youtube_transcript(youtube_id, thread_id, user_message, chat_histo
1046
  # 等待助手响应,设定最大等待时间为 30 秒
1047
  run_status = poll_run_status(run.id, thread.id, timeout=30)
1048
  # 获取助手的响应消息
1049
- if run_status == "completed":
1050
- messages = client.beta.threads.messages.list(thread_id=thread.id)
1051
- assistant_responses = [msg for msg in messages.data if msg.role == "assistant"]
1052
- response_text = assistant_responses[-1].content if assistant_responses else "抱歉,學習精靈有點累,好像睡著了,請稍後再試。"
1053
- else:
1054
- response_text = "抱歉,學習精靈有點累,好像睡著了,請稍後再試。"
1055
 
1056
  # 更新聊天历史
1057
  new_chat_history = (user_message, response_text)
 
1002
  client = OPEN_AI_CLIENT
1003
  instructions = f"""
1004
  你是一個擅長資料分析跟影片教學的老師,user 為學生
1005
+ 請根據 assistant beta 的上傳資料 ,找到 youtube_id = {youtube_id} 為資料文本,自行判斷資料的種類,
1006
+ 如果沒有資料,請告訴用戶沒有逐字稿資料,但仍然可以進行對話
1007
 
1008
  並進行對話,使用 zh-TW
1009
  如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
 
1046
  # 等待助手响应,设定最大等待时间为 30 秒
1047
  run_status = poll_run_status(run.id, thread.id, timeout=30)
1048
  # 获取助手的响应消息
1049
+ messages = client.beta.threads.messages.list(thread_id=thread.id)
1050
+ # [MessageContentText(text=Text(annotations=[], value='您好!有什麼我可以幫助您的嗎?如果有任何問題或需要指導,請隨時告訴我!'), type='text')]
1051
+ response_text = messages[-1].content.text.value
 
 
 
1052
 
1053
  # 更新聊天历史
1054
  new_chat_history = (user_message, response_text)