Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -484,16 +484,20 @@ Write a detailed and complete response that answers the following user question:
|
|
484 |
response = ""
|
485 |
for i in range(num_calls):
|
486 |
logging.info(f"API call {i+1}/{num_calls}")
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
|
|
|
|
|
|
|
|
497 |
|
498 |
logging.info("Finished generating response")
|
499 |
|
|
|
484 |
response = ""
|
485 |
for i in range(num_calls):
|
486 |
logging.info(f"API call {i+1}/{num_calls}")
|
487 |
+
try:
|
488 |
+
for message in client.chat_completion(
|
489 |
+
messages=[{"role": "user", "content": prompt}],
|
490 |
+
max_tokens=10000,
|
491 |
+
temperature=temperature,
|
492 |
+
stream=True,
|
493 |
+
):
|
494 |
+
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
495 |
+
chunk = message.choices[0].delta.content
|
496 |
+
response += chunk
|
497 |
+
yield response # Yield partial response
|
498 |
+
logging.info(f"API call {i+1} completed successfully")
|
499 |
+
except Exception as e:
|
500 |
+
logging.error(f"Error in API call {i+1}: {str(e)}")
|
501 |
|
502 |
logging.info("Finished generating response")
|
503 |
|