Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -40,8 +40,48 @@ class BasicAgent:
|
|
40 |
if not openai_api_key:
|
41 |
raise ValueError("OPENAI_API_KEY not set!")
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
tools = [
|
46 |
{
|
47 |
"type": "function",
|
@@ -97,7 +137,7 @@ class BasicAgent:
|
|
97 |
# Prepara il query engine
|
98 |
self.query_engine = self.index.as_query_engine()
|
99 |
print("coso Agent ready.")
|
100 |
-
|
101 |
def __call__(self, question: str) -> str:
|
102 |
print(f"Received question: {question[:50]}...")
|
103 |
response = self.query_engine.query(question)
|
|
|
40 |
if not openai_api_key:
|
41 |
raise ValueError("OPENAI_API_KEY not set!")
|
42 |
|
43 |
+
# Imposta il logger
|
44 |
+
logging.basicConfig(level=logging.DEBUG)
|
45 |
+
|
46 |
+
# LLM per LlamaIndex
|
47 |
+
llm = OpenAI(
|
48 |
+
model="gpt-4o-mini",
|
49 |
+
temperature=0,
|
50 |
+
api_key=openai_api_key,
|
51 |
+
verbose=True
|
52 |
+
)
|
53 |
+
Settings.llm = llm
|
54 |
|
55 |
+
# Tool per estrarre ingredienti
|
56 |
+
ingredient_tool = FunctionTool.from_defaults(
|
57 |
+
name="extract_ingredients",
|
58 |
+
fn=extract_ingredients,
|
59 |
+
description="Extracts and returns a comma-separated, alphabetized list of ingredients for a pie filling from a transcription string."
|
60 |
+
)
|
61 |
+
|
62 |
+
# Registra il tool
|
63 |
+
Settings.tools = [ingredient_tool]
|
64 |
|
65 |
+
# Prepara l'agente
|
66 |
+
self.agent = OpenAIAgent.from_tools([ingredient_tool], llm=llm, verbose=True)
|
67 |
+
|
68 |
+
# Client OpenAI per chiamate esterne (immagini/audio)
|
69 |
+
self.client = OpenAI(api_key=openai_api_key)
|
70 |
+
|
71 |
+
# Carica i documenti
|
72 |
+
self.documents = SimpleDirectoryReader("data").load_data()
|
73 |
+
self.index = VectorStoreIndex.from_documents(self.documents, settings=Settings)
|
74 |
+
self.query_engine = self.index.as_query_engine()
|
75 |
+
|
76 |
+
print("coso Agent ready.")
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
'''
|
85 |
tools = [
|
86 |
{
|
87 |
"type": "function",
|
|
|
137 |
# Prepara il query engine
|
138 |
self.query_engine = self.index.as_query_engine()
|
139 |
print("coso Agent ready.")
|
140 |
+
|
141 |
def __call__(self, question: str) -> str:
|
142 |
print(f"Received question: {question[:50]}...")
|
143 |
response = self.query_engine.query(question)
|