improve number of messages output
Browse files
agent.py
CHANGED
@@ -274,8 +274,7 @@ class SantaAgent:
|
|
274 |
ChatMessage(role="user", content=user_prompt),
|
275 |
]
|
276 |
|
277 |
-
|
278 |
-
|
279 |
while True:
|
280 |
response = self.client.chat.completions.create(
|
281 |
messages=messages,
|
@@ -283,15 +282,24 @@ class SantaAgent:
|
|
283 |
tools=self.tools,
|
284 |
tool_choice="auto",
|
285 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
messages.append(response.choices[0].message.to_dict())
|
287 |
content = response.choices[0].message.content
|
288 |
if content is not None:
|
289 |
gradio_messages.append(ChatMessage(role="assistant", content=content))
|
290 |
-
tool_calls = response.choices[0].message.tool_calls
|
291 |
|
292 |
should_stop = False
|
293 |
if tool_calls:
|
294 |
-
non_tool_count = 0
|
295 |
for tool_call in tool_calls:
|
296 |
arguments = json.loads(tool_call.function.arguments)
|
297 |
if tool_call.function.name == "buy_item":
|
@@ -346,12 +354,6 @@ class SantaAgent:
|
|
346 |
if not should_stop:
|
347 |
gradio_messages.append(ChatMessage(role="assistant", content=output, metadata={"title": f"🔧 Tool Output: {tool_call.function.name}"}))
|
348 |
|
349 |
-
else:
|
350 |
-
non_tool_count += 1
|
351 |
-
|
352 |
-
if non_tool_count >= 2:
|
353 |
-
break
|
354 |
-
|
355 |
if should_stop or len(messages) > 10:
|
356 |
break
|
357 |
return messages, gradio_messages
|
|
|
274 |
ChatMessage(role="user", content=user_prompt),
|
275 |
]
|
276 |
|
277 |
+
consequtive_non_tool_call_count = 0
|
|
|
278 |
while True:
|
279 |
response = self.client.chat.completions.create(
|
280 |
messages=messages,
|
|
|
282 |
tools=self.tools,
|
283 |
tool_choice="auto",
|
284 |
)
|
285 |
+
|
286 |
+
tool_calls = response.choices[0].message.tool_calls
|
287 |
+
|
288 |
+
# Reduce the number of non-toolcall messages
|
289 |
+
if not tool_calls:
|
290 |
+
consequtive_non_tool_call_count += 1
|
291 |
+
if consequtive_non_tool_call_count >= 2:
|
292 |
+
break
|
293 |
+
else:
|
294 |
+
consequtive_non_tool_call_count = 0
|
295 |
+
|
296 |
messages.append(response.choices[0].message.to_dict())
|
297 |
content = response.choices[0].message.content
|
298 |
if content is not None:
|
299 |
gradio_messages.append(ChatMessage(role="assistant", content=content))
|
|
|
300 |
|
301 |
should_stop = False
|
302 |
if tool_calls:
|
|
|
303 |
for tool_call in tool_calls:
|
304 |
arguments = json.loads(tool_call.function.arguments)
|
305 |
if tool_call.function.name == "buy_item":
|
|
|
354 |
if not should_stop:
|
355 |
gradio_messages.append(ChatMessage(role="assistant", content=output, metadata={"title": f"🔧 Tool Output: {tool_call.function.name}"}))
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
if should_stop or len(messages) > 10:
|
358 |
break
|
359 |
return messages, gradio_messages
|
app.py
CHANGED
@@ -48,7 +48,7 @@ def run_testing(user_prompt, invariant_api_key):
|
|
48 |
|
49 |
agent_params = {"system_prompt": user_prompt}
|
50 |
|
51 |
-
yield f'Running Test
|
52 |
|
53 |
env={
|
54 |
"INVARIANT_API_KEY": invariant_api_key,
|
@@ -137,7 +137,7 @@ with gr.Blocks(
|
|
137 |
gr.Markdown("""
|
138 |
## Get an API Key
|
139 |
* [Create an account here](https://explorer.invariantlabs.ai/settings) by clicking 'Sign In', and then the GitHub icon.
|
140 |
-
* Click on `Get API Key` to get your Invariant API key.
|
141 |
* Paste the API key in the text box below.
|
142 |
"""
|
143 |
)
|
|
|
48 |
|
49 |
agent_params = {"system_prompt": user_prompt}
|
50 |
|
51 |
+
yield f'Running Test 1 of {TOTAL_TESTS}. Please wait.', '', 'button-loading'
|
52 |
|
53 |
env={
|
54 |
"INVARIANT_API_KEY": invariant_api_key,
|
|
|
137 |
gr.Markdown("""
|
138 |
## Get an API Key
|
139 |
* [Create an account here](https://explorer.invariantlabs.ai/settings) by clicking 'Sign In', and then the GitHub icon.
|
140 |
+
* Click on `Get API Key` below to get your Invariant API key.
|
141 |
* Paste the API key in the text box below.
|
142 |
"""
|
143 |
)
|