Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -70,9 +70,9 @@ class BasicAgent:
|
|
70 |
description="Logs the agent's thought process for debugging purposes."
|
71 |
)
|
72 |
|
73 |
-
|
74 |
name="add floats",
|
75 |
-
fn=
|
76 |
description="Takes two float numbers and returns their sum"
|
77 |
)
|
78 |
|
@@ -87,7 +87,7 @@ class BasicAgent:
|
|
87 |
)
|
88 |
|
89 |
# Prepara l'agente
|
90 |
-
self.agent = OpenAIAgent.from_tools([ingredient_tool, search_tool, log_thought_tool,
|
91 |
|
92 |
# Client OpenAI per chiamate esterne (immagini/audio)
|
93 |
|
@@ -231,26 +231,6 @@ class BasicAgent:
|
|
231 |
)
|
232 |
return response.choices[0].message.content.strip()
|
233 |
|
234 |
-
|
235 |
-
'''
|
236 |
-
def _ask_gpt4o_with_mp3(self, audio: Image.Image, question: str) -> str:
|
237 |
-
buffered = BytesIO()
|
238 |
-
image.save(buffered, format="PNG")
|
239 |
-
buffered.seek(0)
|
240 |
-
image_bytes = buffered.read()
|
241 |
-
|
242 |
-
response = self.client.chat.completions.create(
|
243 |
-
model="gpt-4o", #ATTENZIONE QUI MODELLO NON MINI
|
244 |
-
messages=[{
|
245 |
-
"role": "user",
|
246 |
-
"content": [
|
247 |
-
{"type": "text", "text": question},
|
248 |
-
{"type": "image_url", "image_url": {"url": "data:image/png;base64," + base64.b64encode(image_bytes).decode()}}
|
249 |
-
]
|
250 |
-
}]
|
251 |
-
)
|
252 |
-
return response.choices[0].message.content.strip()
|
253 |
-
'''
|
254 |
def _transcribe_audio(self, audio_bytes: BytesIO) -> str:
|
255 |
#audio_file = BytesIO(audio_bytes)
|
256 |
#transcription = self.client.audio.transcriptions.create(model="whisper-1", file=audio_bytes)
|
@@ -572,14 +552,8 @@ def log_thought(thought: str) -> str:
|
|
572 |
return "Thought logged."
|
573 |
|
574 |
|
575 |
-
def
|
576 |
print_coso(f"Tool add: {a} + {b}")
|
577 |
-
"""Add two numbers.
|
578 |
-
|
579 |
-
Args:
|
580 |
-
a: first float
|
581 |
-
b: second float
|
582 |
-
"""
|
583 |
return a + b
|
584 |
|
585 |
|
|
|
70 |
description="Logs the agent's thought process for debugging purposes."
|
71 |
)
|
72 |
|
73 |
+
add_floats_tool = FunctionTool.from_defaults(
|
74 |
name="add floats",
|
75 |
+
fn=add_tool,
|
76 |
description="Takes two float numbers and returns their sum"
|
77 |
)
|
78 |
|
|
|
87 |
)
|
88 |
|
89 |
# Prepara l'agente
|
90 |
+
self.agent = OpenAIAgent.from_tools([ingredient_tool, search_tool, log_thought_tool, add_floats_tool], llm=llm, verbose=True)
|
91 |
|
92 |
# Client OpenAI per chiamate esterne (immagini/audio)
|
93 |
|
|
|
231 |
)
|
232 |
return response.choices[0].message.content.strip()
|
233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
def _transcribe_audio(self, audio_bytes: BytesIO) -> str:
|
235 |
#audio_file = BytesIO(audio_bytes)
|
236 |
#transcription = self.client.audio.transcriptions.create(model="whisper-1", file=audio_bytes)
|
|
|
552 |
return "Thought logged."
|
553 |
|
554 |
|
555 |
+
def add_tool(a: float, b: float) -> float:
|
556 |
print_coso(f"Tool add: {a} + {b}")
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
return a + b
|
558 |
|
559 |
|