Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -203,22 +203,26 @@ def respond_with_enhanced_streaming(message, history):
|
|
| 203 |
tool_call_args_str = ""
|
| 204 |
|
| 205 |
for chunk in stream:
|
| 206 |
-
if
|
|
|
|
|
|
|
|
|
|
| 207 |
# Handle text chunks
|
| 208 |
-
if
|
| 209 |
-
text_chunk =
|
| 210 |
full_response += text_chunk
|
| 211 |
yield full_response
|
| 212 |
|
| 213 |
# Handle tool call chunks
|
| 214 |
-
if
|
| 215 |
-
tool_call_delta =
|
| 216 |
|
| 217 |
# Accumulate name and arguments from stream
|
| 218 |
-
if tool_call_delta
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
| 222 |
|
| 223 |
# Check if we have received the full tool call
|
| 224 |
# This is a simple heuristic and might need refinement
|
|
|
|
| 203 |
tool_call_args_str = ""
|
| 204 |
|
| 205 |
for chunk in stream:
|
| 206 |
+
# Check if chunk has choices and handle accordingly
|
| 207 |
+
if hasattr(chunk, 'choices') and chunk.choices and len(chunk.choices) > 0:
|
| 208 |
+
choice = chunk.choices[0]
|
| 209 |
+
|
| 210 |
# Handle text chunks
|
| 211 |
+
if hasattr(choice, 'delta') and hasattr(choice.delta, 'content') and choice.delta.content:
|
| 212 |
+
text_chunk = choice.delta.content
|
| 213 |
full_response += text_chunk
|
| 214 |
yield full_response
|
| 215 |
|
| 216 |
# Handle tool call chunks
|
| 217 |
+
if hasattr(choice, 'delta') and hasattr(choice.delta, 'tool_calls') and choice.delta.tool_calls:
|
| 218 |
+
tool_call_delta = choice.delta.tool_calls[0]
|
| 219 |
|
| 220 |
# Accumulate name and arguments from stream
|
| 221 |
+
if hasattr(tool_call_delta, 'function'):
|
| 222 |
+
if hasattr(tool_call_delta.function, 'name') and tool_call_delta.function.name:
|
| 223 |
+
tool_call_name = tool_call_delta.function.name
|
| 224 |
+
if hasattr(tool_call_delta.function, 'arguments') and tool_call_delta.function.arguments:
|
| 225 |
+
tool_call_args_str += tool_call_delta.function.arguments
|
| 226 |
|
| 227 |
# Check if we have received the full tool call
|
| 228 |
# This is a simple heuristic and might need refinement
|