ajayarora1235 commited on
Commit
99abbcc
1 Parent(s): 97045b3

add timeout feature

Browse files
Files changed (1) hide show
  1. chat.py +6 -6
chat.py CHANGED
@@ -33,7 +33,7 @@ def determine_title(section_name, generated_audios):
33
  section_name = f"{section_name} {count + 1}"
34
  return section_name
35
 
36
- async def call_with_timeout(coro, timeout):
37
  try:
38
  return await asyncio.wait_for(coro, timeout)
39
  except asyncio.TimeoutError:
@@ -310,7 +310,7 @@ async def model_chat(genre_input, query: Optional[str], history: Optional[Histor
310
  sections_list = re.findall(r'\[.*?\]', current_lyrics)
311
 
312
  #current_lyrics = "\n".join(tool_query_args['sections_written'])
313
- song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags))
314
  ## filter out suno link from tool query arg
315
  while "https://audiopipe.suno.ai/?item_id=" not in song_link:
316
  print("BUGGED OUT, trying again...")
@@ -322,7 +322,7 @@ async def model_chat(genre_input, query: Optional[str], history: Optional[Histor
322
  yield '', new_history, new_messages, '', '', '', None, None, generated_audios, []
323
  return
324
  time.sleep(5)
325
- song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags))
326
 
327
  clip_id = song_link.split("https://audiopipe.suno.ai/?item_id=")[1]
328
 
@@ -358,7 +358,7 @@ async def model_chat(genre_input, query: Optional[str], history: Optional[Histor
358
 
359
  new_instrumental_tags = songwriterAssistant.revise_instrumental_tags(snippet_instrumental_tags, user_instrumental_feedback)
360
 
361
- song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags))
362
  ## filter out suno link from tool query arg
363
  while "https://audiopipe.suno.ai/?item_id=" not in song_link:
364
  print("BUGGED OUT, trying again...")
@@ -370,7 +370,7 @@ async def model_chat(genre_input, query: Optional[str], history: Optional[Histor
370
  yield '', new_history, new_messages, '', '', '', None, None, generated_audios, []
371
  return
372
  time.sleep(5)
373
- song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags))
374
  clip_id = song_link.split("https://audiopipe.suno.ai/?item_id=")[1]
375
 
376
  tool_message_instrumental = {'role': 'tool', 'tool_call_id': tool_call_id, 'name': tool_function_name, 'content': f'revised lyrics: {revised_lyrics}\nrevised instrumental tags: {new_instrumental_tags}, clip id: {clip_id}'}
@@ -389,7 +389,7 @@ async def model_chat(genre_input, query: Optional[str], history: Optional[Histor
389
  yield '', new_history, new_messages, tool_query_args["section_name"], revised_lyrics, new_instrumental_tags, clips_to_continue, f'<audio controls><source src="{song_link}" type="audio/mp3"></audio>', generated_audios, buttons
390
 
391
  elif tool_function_name == 'merge_all_snippets':
392
- updated_clip_url, updated_lyrics, updated_tags, clips_list = await call_with_timeout(run_in_executor(concat_snippets, tool_query_args['last_snippet_id']))
393
 
394
  if updated_clip_url == "Timeout":
395
  # Handle the timeout case
 
33
  section_name = f"{section_name} {count + 1}"
34
  return section_name
35
 
36
+ async def call_with_timeout(coro, timeout=45):
37
  try:
38
  return await asyncio.wait_for(coro, timeout)
39
  except asyncio.TimeoutError:
 
310
  sections_list = re.findall(r'\[.*?\]', current_lyrics)
311
 
312
  #current_lyrics = "\n".join(tool_query_args['sections_written'])
313
+ song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags), 45)
314
  ## filter out suno link from tool query arg
315
  while "https://audiopipe.suno.ai/?item_id=" not in song_link:
316
  print("BUGGED OUT, trying again...")
 
322
  yield '', new_history, new_messages, '', '', '', None, None, generated_audios, []
323
  return
324
  time.sleep(5)
325
+ song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags), 45)
326
 
327
  clip_id = song_link.split("https://audiopipe.suno.ai/?item_id=")[1]
328
 
 
358
 
359
  new_instrumental_tags = songwriterAssistant.revise_instrumental_tags(snippet_instrumental_tags, user_instrumental_feedback)
360
 
361
+ song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags), 45)
362
  ## filter out suno link from tool query arg
363
  while "https://audiopipe.suno.ai/?item_id=" not in song_link:
364
  print("BUGGED OUT, trying again...")
 
370
  yield '', new_history, new_messages, '', '', '', None, None, generated_audios, []
371
  return
372
  time.sleep(5)
373
+ song_link = await call_with_timeout(run_in_executor(make_song, current_lyrics, new_instrumental_tags), 45)
374
  clip_id = song_link.split("https://audiopipe.suno.ai/?item_id=")[1]
375
 
376
  tool_message_instrumental = {'role': 'tool', 'tool_call_id': tool_call_id, 'name': tool_function_name, 'content': f'revised lyrics: {revised_lyrics}\nrevised instrumental tags: {new_instrumental_tags}, clip id: {clip_id}'}
 
389
  yield '', new_history, new_messages, tool_query_args["section_name"], revised_lyrics, new_instrumental_tags, clips_to_continue, f'<audio controls><source src="{song_link}" type="audio/mp3"></audio>', generated_audios, buttons
390
 
391
  elif tool_function_name == 'merge_all_snippets':
392
+ updated_clip_url, updated_lyrics, updated_tags, clips_list = await call_with_timeout(run_in_executor(concat_snippets, tool_query_args['last_snippet_id']), 45)
393
 
394
  if updated_clip_url == "Timeout":
395
  # Handle the timeout case