PD03 commited on
Commit
edda512
·
verified ·
1 Parent(s): fda49a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -133,12 +133,22 @@ Available tools:
133
  When a user asks for information that can be retrieved using these tools, you should:
134
  1. Identify which tool(s) would be helpful
135
  2. Call the appropriate tool(s) with the right parameters
136
- 3. Interpret and present the results in a user-friendly way
137
 
138
  For SAP-related queries (purchase orders, requisitions), use the SAP tools.
139
  For news-related queries, use the news tools.
140
 
141
- You can call tools by responding with: CALL_TOOL: tool_name(parameter1=value1, parameter2=value2)
 
 
 
 
 
 
 
 
 
 
142
  """
143
 
144
  def extract_tool_calls(self, response: str) -> List[Dict[str, Any]]:
@@ -147,10 +157,13 @@ You can call tools by responding with: CALL_TOOL: tool_name(parameter1=value1, p
147
  lines = response.split('\n')
148
 
149
  for line in lines:
150
- if line.strip().startswith('CALL_TOOL:'):
 
151
  try:
152
- tool_part = line.strip()[10:].strip()
 
153
 
 
154
  if '(' in tool_part and ')' in tool_part:
155
  tool_name = tool_part.split('(')[0].strip()
156
  params_str = tool_part.split('(')[1].split(')')[0]
@@ -175,7 +188,16 @@ You can call tools by responding with: CALL_TOOL: tool_name(parameter1=value1, p
175
  'name': tool_name,
176
  'arguments': params
177
  })
 
 
 
 
 
 
 
 
178
  except Exception as e:
 
179
  continue
180
 
181
  return tool_calls
@@ -210,6 +232,10 @@ You can call tools by responding with: CALL_TOOL: tool_name(parameter1=value1, p
210
  ai_response = response.choices[0].message.content
211
  tool_calls = self.extract_tool_calls(ai_response)
212
 
 
 
 
 
213
  if tool_calls:
214
  tool_results = []
215
 
 
133
  When a user asks for information that can be retrieved using these tools, you should:
134
  1. Identify which tool(s) would be helpful
135
  2. Call the appropriate tool(s) with the right parameters
136
+ 3. Wait for the results before providing your final response
137
 
138
  For SAP-related queries (purchase orders, requisitions), use the SAP tools.
139
  For news-related queries, use the news tools.
140
 
141
+ To call a tool, use this exact format:
142
+ CALL_TOOL: tool_name
143
+ or
144
+ CALL_TOOL: tool_name(parameter1=value1, parameter2=value2)
145
+
146
+ Examples:
147
+ - For "show me purchase orders": CALL_TOOL: get_purchase_orders
148
+ - For "get 20 purchase orders": CALL_TOOL: get_purchase_orders(top=20)
149
+ - For "latest tech news": CALL_TOOL: get_news_headlines(category=technology)
150
+
151
+ After calling a tool, I will provide you with the results to interpret for the user.
152
  """
153
 
154
  def extract_tool_calls(self, response: str) -> List[Dict[str, Any]]:
 
157
  lines = response.split('\n')
158
 
159
  for line in lines:
160
+ line = line.strip()
161
+ if line.startswith('CALL_TOOL:'):
162
  try:
163
+ # Remove 'CALL_TOOL:' prefix and clean up
164
+ tool_part = line[10:].strip()
165
 
166
+ # Handle cases with or without parentheses
167
  if '(' in tool_part and ')' in tool_part:
168
  tool_name = tool_part.split('(')[0].strip()
169
  params_str = tool_part.split('(')[1].split(')')[0]
 
188
  'name': tool_name,
189
  'arguments': params
190
  })
191
+ else:
192
+ # Simple tool call without parameters
193
+ tool_name = tool_part.strip()
194
+ tool_calls.append({
195
+ 'name': tool_name,
196
+ 'arguments': {}
197
+ })
198
+
199
  except Exception as e:
200
+ print(f"Error parsing tool call '{line}': {e}")
201
  continue
202
 
203
  return tool_calls
 
232
  ai_response = response.choices[0].message.content
233
  tool_calls = self.extract_tool_calls(ai_response)
234
 
235
+ # Debug information
236
+ print(f"AI Response: {ai_response}")
237
+ print(f"Extracted tool calls: {tool_calls}")
238
+
239
  if tool_calls:
240
  tool_results = []
241