Spaces:
Sleeping
Sleeping
Alexandre Gazola
commited on
Commit
·
713bdac
1
Parent(s):
aeedad9
fix search com Tavily
Browse files- constants.py +2 -0
- excel_parser_tool.py +0 -1
- internet_search_tool.py +13 -6
- requirements.txt +2 -2
constants.py
CHANGED
@@ -9,6 +9,8 @@ API_KEY = os.getenv("GEMINI_API_KEY")
|
|
9 |
|
10 |
OPENAI_KEY = os.getenv("OPENAI_KEY")
|
11 |
|
|
|
|
|
12 |
PROMPT_LIMITADOR_LLM = """
|
13 |
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
14 |
|
|
|
9 |
|
10 |
OPENAI_KEY = os.getenv("OPENAI_KEY")
|
11 |
|
12 |
+
TAVILY_KEY = os.getenv("TAVILY_KEY")
|
13 |
+
|
14 |
PROMPT_LIMITADOR_LLM = """
|
15 |
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
16 |
|
excel_parser_tool.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
from duckduckgo_search import DDGS
|
2 |
from utils import clean_text
|
3 |
from langchain_core.tools import tool
|
4 |
import io
|
|
|
|
|
1 |
from utils import clean_text
|
2 |
from langchain_core.tools import tool
|
3 |
import io
|
internet_search_tool.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
-
from
|
2 |
from utils import clean_text
|
3 |
from langchain_core.tools import tool
|
|
|
|
|
4 |
|
5 |
@tool
|
6 |
def internet_search(query: str, max_results: int = 10) -> list[dict]:
|
@@ -23,12 +25,17 @@ def internet_search(query: str, max_results: int = 10) -> list[dict]:
|
|
23 |
if not query.strip():
|
24 |
raise ValueError("Query must not be empty.")
|
25 |
|
|
|
|
|
|
|
26 |
results = []
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
return results
|
33 |
|
34 |
if __name__ == "__main__":
|
|
|
1 |
+
from tavily import TavilyClient
|
2 |
from utils import clean_text
|
3 |
from langchain_core.tools import tool
|
4 |
+
import os
|
5 |
+
from constants import TAVILY_KEY
|
6 |
|
7 |
@tool
|
8 |
def internet_search(query: str, max_results: int = 10) -> list[dict]:
|
|
|
25 |
if not query.strip():
|
26 |
raise ValueError("Query must not be empty.")
|
27 |
|
28 |
+
client = TavilyClient(api_key=TAVILY_KEY)
|
29 |
+
search_results = client.search(query=query, max_results=max_results)
|
30 |
+
|
31 |
results = []
|
32 |
+
for r in search_results["results"]:
|
33 |
+
results.append({
|
34 |
+
"title": r.get("title", ""),
|
35 |
+
"href": r.get("url", ""),
|
36 |
+
"body": r.get("content", "")
|
37 |
+
})
|
38 |
+
|
39 |
return results
|
40 |
|
41 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
gradio
|
2 |
requests
|
3 |
certifi
|
4 |
-
duckduckgo_search
|
5 |
httpx
|
6 |
langchain
|
7 |
langchain-core
|
@@ -18,4 +17,5 @@ yt-dlp
|
|
18 |
wikipedia-api
|
19 |
google-generativeai
|
20 |
openpyxl
|
21 |
-
tabulate
|
|
|
|
1 |
gradio
|
2 |
requests
|
3 |
certifi
|
|
|
4 |
httpx
|
5 |
langchain
|
6 |
langchain-core
|
|
|
17 |
wikipedia-api
|
18 |
google-generativeai
|
19 |
openpyxl
|
20 |
+
tabulate
|
21 |
+
tavily-python
|