Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,6 +98,9 @@ def respond(
|
|
| 98 |
**parameters # Pass all other parameters
|
| 99 |
)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
| 101 |
# Process the streaming response
|
| 102 |
for chunk in stream:
|
| 103 |
if hasattr(chunk, 'choices') and len(chunk.choices) > 0:
|
|
@@ -105,9 +108,13 @@ def respond(
|
|
| 105 |
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
|
| 106 |
token_text = chunk.choices[0].delta.content
|
| 107 |
if token_text:
|
| 108 |
-
|
|
|
|
| 109 |
response += token_text
|
| 110 |
yield response
|
|
|
|
|
|
|
|
|
|
| 111 |
except Exception as e:
|
| 112 |
print(f"Error during inference: {e}")
|
| 113 |
response += f"\nError: {str(e)}"
|
|
|
|
| 98 |
**parameters # Pass all other parameters
|
| 99 |
)
|
| 100 |
|
| 101 |
+
# Print a starting message for token streaming
|
| 102 |
+
print("Received tokens: ", end="", flush=True)
|
| 103 |
+
|
| 104 |
# Process the streaming response
|
| 105 |
for chunk in stream:
|
| 106 |
if hasattr(chunk, 'choices') and len(chunk.choices) > 0:
|
|
|
|
| 108 |
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
|
| 109 |
token_text = chunk.choices[0].delta.content
|
| 110 |
if token_text:
|
| 111 |
+
# Print tokens inline without newlines
|
| 112 |
+
print(token_text, end="", flush=True)
|
| 113 |
response += token_text
|
| 114 |
yield response
|
| 115 |
+
|
| 116 |
+
# Print a newline at the end of all tokens
|
| 117 |
+
print()
|
| 118 |
except Exception as e:
|
| 119 |
print(f"Error during inference: {e}")
|
| 120 |
response += f"\nError: {str(e)}"
|