Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
|
|
|
|
|
|
|
|
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 |
|