Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,8 @@ from io import StringIO
|
|
7 |
import logging
|
8 |
#from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, OpenAIServerModel
|
9 |
from pathlib import Path
|
10 |
-
from prompt_settings import verification_of_final_answer, yaml_template
|
|
|
11 |
|
12 |
from llama_index.core import (
|
13 |
VectorStoreIndex,
|
@@ -56,6 +57,12 @@ class BasicAgent:
|
|
56 |
fn=extract_ingredients,
|
57 |
description="Extracts and returns a comma-separated, alphabetized list of ingredients for a pie filling from a transcription string."
|
58 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
# Registra il tool
|
61 |
#Settings.tools = [ingredient_tool]
|
@@ -67,7 +74,7 @@ class BasicAgent:
|
|
67 |
)
|
68 |
|
69 |
# Prepara l'agente
|
70 |
-
self.agent = OpenAIAgent.from_tools([ingredient_tool], llm=llm, verbose=True)
|
71 |
|
72 |
# Client OpenAI per chiamate esterne (immagini/audio)
|
73 |
|
@@ -535,6 +542,13 @@ def extract_ingredients(transcription: str) -> str:
|
|
535 |
unique_ingredients = sorted(set(match.strip() for match in matches))
|
536 |
return ", ".join(unique_ingredients)
|
537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
def print_coso(scritta: str):
|
540 |
print(f"coso {scritta}")
|
|
|
7 |
import logging
|
8 |
#from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, OpenAIServerModel
|
9 |
from pathlib import Path
|
10 |
+
from prompt_settings import verification_of_final_answer, yaml_templateù
|
11 |
+
from duckduckgo_search import ddg
|
12 |
|
13 |
from llama_index.core import (
|
14 |
VectorStoreIndex,
|
|
|
57 |
fn=extract_ingredients,
|
58 |
description="Extracts and returns a comma-separated, alphabetized list of ingredients for a pie filling from a transcription string."
|
59 |
)
|
60 |
+
|
61 |
+
search_tool = FunctionTool.from_defaults(
|
62 |
+
name="web_search",
|
63 |
+
fn=web_search,
|
64 |
+
description="Performs a DuckDuckGo search and returns the top 3 results."
|
65 |
+
)
|
66 |
|
67 |
# Registra il tool
|
68 |
#Settings.tools = [ingredient_tool]
|
|
|
74 |
)
|
75 |
|
76 |
# Prepara l'agente
|
77 |
+
self.agent = OpenAIAgent.from_tools([ingredient_tool, search_tool], llm=llm, verbose=True)
|
78 |
|
79 |
# Client OpenAI per chiamate esterne (immagini/audio)
|
80 |
|
|
|
542 |
unique_ingredients = sorted(set(match.strip() for match in matches))
|
543 |
return ", ".join(unique_ingredients)
|
544 |
|
545 |
+
def web_search(query: str) -> str:
|
546 |
+
results = ddg(query, max_results=3)
|
547 |
+
if not results:
|
548 |
+
return "No results found."
|
549 |
+
return "\n".join([f"{res['title']} - {res['href']}" for res in results])
|
550 |
+
|
551 |
+
|
552 |
|
553 |
def print_coso(scritta: str):
|
554 |
print(f"coso {scritta}")
|