Shreyas094 commited on
Commit
8142ec6
·
verified ·
1 Parent(s): a322a99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -528,16 +528,20 @@ Write a detailed and complete response that answers the following user question:
528
  response = ""
529
  for i in range(num_calls):
530
  logging.info(f"API call {i+1}/{num_calls}")
531
- for message in client.chat_completion(
532
- messages=[{"role": "user", "content": prompt}],
533
- max_tokens=10000,
534
- temperature=temperature,
535
- stream=True,
536
- ):
537
- if message.choices and message.choices[0].delta and message.choices[0].delta.content:
538
- chunk = message.choices[0].delta.content
539
- response += chunk
540
- yield response # Yield partial response
 
 
 
 
541
 
542
  logging.info("Finished generating response")
543
 
 
528
  response = ""
529
  for i in range(num_calls):
530
  logging.info(f"API call {i+1}/{num_calls}")
531
+ try:
532
+ for message in client.chat_completion(
533
+ messages=[{"role": "user", "content": prompt}],
534
+ max_tokens=10000,
535
+ temperature=temperature,
536
+ stream=True,
537
+ ):
538
+ if message.choices and message.choices[0].delta and message.choices[0].delta.content:
539
+ chunk = message.choices[0].delta.content
540
+ response += chunk
541
+ yield response # Yield partial response
542
+ except Exception as e:
543
+ logging.error(f"Error in API call {i+1}: {str(e)}")
544
+ yield f"Error in API call {i+1}: {str(e)}. Attempting next call..."
545
 
546
  logging.info("Finished generating response")
547