hhhhmmmm commited on
Commit
306ad76
·
verified ·
1 Parent(s): f6fb70d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -2
app.py CHANGED
@@ -6,7 +6,9 @@ from langchain.agents import AgentExecutor, create_react_agent
6
  from langchain_google_genai import ChatGoogleGenerativeAI
7
  from langchain.tools import tool
8
  from langchain.prompts import PromptTemplate
9
- from langchain_openai import ChatOpenAI # OpenAI-compatible for Groq API
 
 
10
  from ddgs import DDGS # Updated DuckDuckGo Search
11
  from dotenv import load_dotenv
12
  import re
@@ -48,6 +50,70 @@ def duckduckgo_search(query: str) -> str:
48
  return json.dumps([{"title": r["title"], "snippet": r["body"]} for r in results])
49
  except Exception as e:
50
  return f"Search error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # --- Basic Agent Definition ---
53
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
@@ -55,7 +121,8 @@ class BasicAgent:
55
  def __init__(self):
56
  print("BasicAgent initialized.")
57
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
58
- tools = [duckduckgo_search, python_code_executor, download_file]
 
59
  # Prompt for short, exact answers (GAIA-style) with required ReAct variables
60
  prompt_template = PromptTemplate.from_template("""
61
  You are an AI agent solving GAIA benchmark tasks. Use tools if needed (web search, code execution, file download).
 
6
  from langchain_google_genai import ChatGoogleGenerativeAI
7
  from langchain.tools import tool
8
  from langchain.prompts import PromptTemplate
9
+ from langchain_community.document_loaders import WikipediaLoader
10
+ from langchain_community.document_loaders import ArxivLoader
11
+ #from langchain_openai import ChatOpenAI # OpenAI-compatible for Groq API
12
  from ddgs import DDGS # Updated DuckDuckGo Search
13
  from dotenv import load_dotenv
14
  import re
 
50
  return json.dumps([{"title": r["title"], "snippet": r["body"]} for r in results])
51
  except Exception as e:
52
  return f"Search error: {str(e)}"
53
+
54
+ @tool
55
+ def arvix_search(query: str) -> str:
56
+ """Search Arxiv for a query and return maximum 3 result.
57
+ Args:
58
+ query: The search query."""
59
+ search_docs = ArxivLoader(query=query, load_max_docs=3).load()
60
+ formatted_search_docs = "\n\n---\n\n".join(
61
+ [
62
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
63
+ for doc in search_docs
64
+ ])
65
+ return {"arvix_results": formatted_search_docs}
66
+
67
+ @tool
68
+ def wiki_search(query: str) -> str:
69
+ """Search Wikipedia for a query and return maximum 2 results.
70
+ Args:
71
+ query: The search query."""
72
+ search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
73
+ formatted_search_docs = "\n\n---\n\n".join(
74
+ [
75
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
76
+ for doc in search_docs
77
+ ])
78
+ return {"wiki_results": formatted_search_docs}
79
+
80
+ @tool
81
+ def multiply(a: int, b: int) -> int:
82
+ """Multiply two numbers.
83
+ Args:
84
+ a: first int
85
+ b: second int
86
+ """
87
+ return a * b
88
+
89
+ @tool
90
+ def add(a: int, b: int) -> int:
91
+ """Add two numbers.
92
+ Args:
93
+ a: first int
94
+ b: second int
95
+ """
96
+ return a + b
97
+
98
+ @tool
99
+ def subtract(a: int, b: int) -> int:
100
+ """Subtract two numbers.
101
+ Args:
102
+ a: first int
103
+ b: second int
104
+ """
105
+ return a - b
106
+
107
+ @tool
108
+ def divide(a: int, b: int) -> int:
109
+ """Divide two numbers.
110
+ Args:
111
+ a: first int
112
+ b: second int
113
+ """
114
+ if b == 0:
115
+ raise ValueError("Cannot divide by zero.")
116
+ return a / b
117
 
118
  # --- Basic Agent Definition ---
119
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
121
  def __init__(self):
122
  print("BasicAgent initialized.")
123
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
124
+ #tools = [duckduckgo_search, python_code_executor, download_file]
125
+ tools = [duckduckgo_search, python_code_executor, download_file,arvix_search,wiki_search,multiply,add,subtract,divide]
126
  # Prompt for short, exact answers (GAIA-style) with required ReAct variables
127
  prompt_template = PromptTemplate.from_template("""
128
  You are an AI agent solving GAIA benchmark tasks. Use tools if needed (web search, code execution, file download).