jdesiree commited on
Commit
4a2e2fb
·
verified ·
1 Parent(s): e697bee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
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 isinstance(chunk, CompletionChunk):
 
 
 
207
  # Handle text chunks
208
- if chunk.choices and chunk.choices[0].delta.content:
209
- text_chunk = chunk.choices[0].delta.content
210
  full_response += text_chunk
211
  yield full_response
212
 
213
  # Handle tool call chunks
214
- if chunk.choices and chunk.choices[0].delta.tool_calls:
215
- tool_call_delta = chunk.choices[0].delta.tool_calls[0]
216
 
217
  # Accumulate name and arguments from stream
218
- if tool_call_delta.function.name:
219
- tool_call_name = tool_call_delta.function.name
220
- if tool_call_delta.function.arguments:
221
- tool_call_args_str += tool_call_delta.function.arguments
 
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