Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,8 @@ from llama_index.core import (
|
|
18 |
from llama_index.core.tools import FunctionTool
|
19 |
from llama_index.agent.openai import OpenAIAgent
|
20 |
from llama_index.llms.openai import OpenAI as LlamaOpenAI
|
|
|
|
|
21 |
|
22 |
from openai import OpenAI as OpenAIClient
|
23 |
|
@@ -63,9 +65,19 @@ class BasicAgent:
|
|
63 |
temperature=0.0,
|
64 |
api_key=openai_api_key
|
65 |
)
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# Prepara l'agente
|
68 |
-
self.agent = OpenAIAgent.from_tools(
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Client OpenAI per chiamate esterne (immagini/audio)
|
71 |
|
@@ -175,17 +187,22 @@ class BasicAgent:
|
|
175 |
|
176 |
|
177 |
def _ask_gpt4o(self, text: str) -> str:
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
def _ask_gpt4o_with_image(self, image: Image.Image, question: str) -> str:
|
191 |
buffered = BytesIO()
|
|
|
18 |
from llama_index.core.tools import FunctionTool
|
19 |
from llama_index.agent.openai import OpenAIAgent
|
20 |
from llama_index.llms.openai import OpenAI as LlamaOpenAI
|
21 |
+
from llama_index.core.callbacks import CallbackManager, LlamaDebugHandler
|
22 |
+
|
23 |
|
24 |
from openai import OpenAI as OpenAIClient
|
25 |
|
|
|
65 |
temperature=0.0,
|
66 |
api_key=openai_api_key
|
67 |
)
|
68 |
+
|
69 |
+
#questo per vedere il ragionamento step by step
|
70 |
+
debug_handler = LlamaDebugHandler(print_trace_on_end=True)
|
71 |
+
callback_manager = CallbackManager([debug_handler])
|
72 |
|
73 |
# Prepara l'agente
|
74 |
+
self.agent = OpenAIAgent.from_tools(
|
75 |
+
tools = [ingredient_tool],
|
76 |
+
llm=llm,
|
77 |
+
callback_manager=callback_manager,
|
78 |
+
verbose=True,
|
79 |
+
system_prompt=custom_yaml_prompt
|
80 |
+
)
|
81 |
|
82 |
# Client OpenAI per chiamate esterne (immagini/audio)
|
83 |
|
|
|
187 |
|
188 |
|
189 |
def _ask_gpt4o(self, text: str) -> str:
|
190 |
+
try:
|
191 |
+
response = self.agent.chat(text, verbose=True)
|
192 |
+
|
193 |
+
print_coso("\n==== RISPOSTA AGENTE ====")
|
194 |
+
print(response.response)
|
195 |
+
|
196 |
+
print_coso("\n==== RAW OUTPUT ====")
|
197 |
+
print(response.raw_output)
|
198 |
+
print_coso("\n==== FINE RAW OUTPUT ====")
|
199 |
+
|
200 |
+
return str(response.response)
|
201 |
+
except Exception as e:
|
202 |
+
print_coso(f"[ERRORE] Agent chat fallita: {e}")
|
203 |
+
return "Agent error"
|
204 |
+
|
205 |
+
|
206 |
|
207 |
def _ask_gpt4o_with_image(self, image: Image.Image, question: str) -> str:
|
208 |
buffered = BytesIO()
|