GattoNero commited on
Commit
bd9e804
·
verified ·
1 Parent(s): d2b3026

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -29
app.py CHANGED
@@ -18,8 +18,6 @@ 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
- #from llama_index.core.callbacks import CallbackManager, LlamaDebugHandler
22
-
23
 
24
  from openai import OpenAI as OpenAIClient
25
 
@@ -65,18 +63,9 @@ class BasicAgent:
65
  temperature=0.0,
66
  api_key=openai_api_key
67
  )
68
- #print_coso(f"openai.__version__: {openai.__version__}")
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
- )
80
 
81
  # Client OpenAI per chiamate esterne (immagini/audio)
82
 
@@ -100,7 +89,7 @@ class BasicAgent:
100
 
101
 
102
  def __call__(self, question: str, file_info: str = "") -> str:
103
- print_coso(f"Received question: {question}")
104
 
105
  # Prova a decodificare JSON
106
  try:
@@ -186,22 +175,17 @@ class BasicAgent:
186
 
187
 
188
  def _ask_gpt4o(self, text: str) -> str:
189
- try:
190
- response = self.agent.chat(text, verbose=True)
191
-
192
- print_coso("\n==== RISPOSTA AGENTE ====")
193
- #print(response.response)
194
-
195
- print_coso("\n==== RAW OUTPUT ====")
196
- #print(response.raw_output)
197
- print_coso("\n==== FINE RAW OUTPUT ====")
198
-
199
- return str(response)
200
- except Exception as e:
201
- print_coso(f"[ERRORE] Agent chat fallita: {e}")
202
- return "Agent error"
203
-
204
-
205
 
206
  def _ask_gpt4o_with_image(self, image: Image.Image, question: str) -> str:
207
  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
 
22
  from openai import OpenAI as OpenAIClient
23
 
 
63
  temperature=0.0,
64
  api_key=openai_api_key
65
  )
 
 
 
 
66
 
67
  # Prepara l'agente
68
+ self.agent = OpenAIAgent.from_tools([ingredient_tool], llm=llm, verbose=True)
 
 
 
 
 
69
 
70
  # Client OpenAI per chiamate esterne (immagini/audio)
71
 
 
89
 
90
 
91
  def __call__(self, question: str, file_info: str = "") -> str:
92
+ print_coso(f"Received question: {question[:100]}")
93
 
94
  # Prova a decodificare JSON
95
  try:
 
175
 
176
 
177
  def _ask_gpt4o(self, text: str) -> str:
178
+ response = self.agent.chat(text)
179
+ return str(response)
180
+ '''
181
+ messages = [{"role": "user", "content": text}]
182
+ response = self.client.chat.completions.create(
183
+ model="gpt-4o-mini",
184
+ temperature=0,
185
+ messages=messages
186
+ )
187
+ return response.choices[0].message.content.strip()
188
+ '''
 
 
 
 
 
189
 
190
  def _ask_gpt4o_with_image(self, image: Image.Image, question: str) -> str:
191
  buffered = BytesIO()