MatteoFalcioni commited on
Commit
200f0bf
·
1 Parent(s): f1a20fe

tools updated

Browse files
Files changed (2) hide show
  1. __pycache__/tools.cpython-310.pyc +0 -0
  2. tools.py +14 -27
__pycache__/tools.cpython-310.pyc ADDED
Binary file (1.77 kB). View file
 
tools.py CHANGED
@@ -1,9 +1,11 @@
1
- from typing import Optional
2
  from langchain_core.tools import tool
3
  import math
4
  import pandas as pd
5
  import requests
6
  import io
 
 
 
7
 
8
 
9
  @tool
@@ -44,35 +46,20 @@ def describe_table_from_url(file_url: str) -> str:
44
  return f"Error loading table: {e}"
45
 
46
 
47
- @tool
48
- def search_web(query: str) -> str:
49
- """
50
- Perform a simple web search using DuckDuckGo Instant Answer API.
51
- Returns a short summary or answer.
52
- """
53
- try:
54
- response = requests.get("https://api.duckduckgo.com/", params={
55
- "q": query,
56
- "format": "json",
57
- "no_redirect": 1,
58
- "no_html": 1
59
- }, timeout=10)
60
- data = response.json()
61
- if data.get("AbstractText"):
62
- return data["AbstractText"]
63
- elif data.get("Answer"):
64
- return data["Answer"]
65
- elif data.get("RelatedTopics"):
66
- return data["RelatedTopics"][0].get("Text", "No summary found.")
67
- else:
68
- return "No results found."
69
- except Exception as e:
70
- return f"Web search error: {e}"
71
-
72
 
73
  # Export the tools in a list
74
  TOOLS = [
75
  compute_expression,
76
  describe_table_from_url,
77
- search_web,
78
  ]
 
 
 
 
1
  from langchain_core.tools import tool
2
  import math
3
  import pandas as pd
4
  import requests
5
  import io
6
+ from langchain_tavily import TavilySearch
7
+ import os
8
+ from dotenv import load_dotenv
9
 
10
 
11
  @tool
 
46
  return f"Error loading table: {e}"
47
 
48
 
49
+ load_dotenv() # Load variables from .env into environment
50
+ api_key = os.getenv("TAVILY_API_KEY")
51
+ # Initialize Tavily Search Tool
52
+ tavily_search_tool = TavilySearch(
53
+ max_results=5,
54
+ topic="general",
55
+ tavily_api_key=api_key
56
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  # Export the tools in a list
59
  TOOLS = [
60
  compute_expression,
61
  describe_table_from_url,
62
+ tavily_search_tool
63
  ]
64
+
65
+