capradeepgujaran commited on
Commit
8ce6be4
·
verified ·
1 Parent(s): 3dab4cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -128,15 +128,21 @@ class ComputerUseDemo:
128
  betas=["computer-use-2024-10-22"]
129
  )
130
 
131
- # Handle tool calls
132
- if response.stop_reason == "tool_use" and response.tool_calls:
133
- tool_call = response.tool_calls[0]
134
- tool_result = self.execute_tool(tool_call.name, tool_call.arguments)
 
 
 
 
 
 
135
 
136
  # Add tool interactions to message history
137
  messages.append({
138
  "role": "assistant",
139
- "content": [{"type": "tool_use", "name": tool_call.name, "input": tool_call.arguments}]
140
  })
141
  messages.append({
142
  "role": "user",
 
128
  betas=["computer-use-2024-10-22"]
129
  )
130
 
131
+ # Check for tool calls in the response
132
+ tool_calls = []
133
+ for content in response.content:
134
+ if hasattr(content, 'tool_calls') and content.tool_calls:
135
+ tool_calls.extend(content.tool_calls)
136
+
137
+ # Handle tool calls if present
138
+ if tool_calls:
139
+ tool_call = tool_calls[0] # Handle first tool call
140
+ tool_result = self.execute_tool(tool_call.name, tool_call.parameters)
141
 
142
  # Add tool interactions to message history
143
  messages.append({
144
  "role": "assistant",
145
+ "content": [{"type": "tool_use", "name": tool_call.name, "input": tool_call.parameters}]
146
  })
147
  messages.append({
148
  "role": "user",