Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,15 @@ import requests
|
|
8 |
from typing import List, Dict, Union
|
9 |
import pandas as pd
|
10 |
import wikipediaapi
|
11 |
-
from typing import Optional
|
12 |
-
from termax.agent import Agent # Assuming you're using a specific agent framework
|
13 |
-
from termax.tool import google_search # Assuming this is your search tool import
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
load_dotenv()
|
16 |
|
@@ -41,6 +47,34 @@ class BasicAgent:
|
|
41 |
return fixed_answer
|
42 |
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
def search_tool(self, prompt: str) -> str:
|
45 |
"""
|
46 |
Searches for information using a Gemini-powered agent with Google Search capability.
|
|
|
8 |
from typing import List, Dict, Union
|
9 |
import pandas as pd
|
10 |
import wikipediaapi
|
11 |
+
#from typing import Optional
|
12 |
+
#from termax.agent import Agent # Assuming you're using a specific agent framework
|
13 |
+
#from termax.tool import google_search # Assuming this is your search tool import
|
14 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
15 |
+
from langchain.agents import AgentExecutor, create_tool_calling_agent
|
16 |
+
from langchain.tools import Tool
|
17 |
+
from langchain import hub
|
18 |
+
import google.generativeai as genai # Fallback if needed
|
19 |
+
|
20 |
|
21 |
load_dotenv()
|
22 |
|
|
|
47 |
return fixed_answer
|
48 |
|
49 |
|
50 |
+
|
51 |
+
|
52 |
+
def search_tool(self, prompt: str) -> str:
|
53 |
+
# Initialize Gemini model
|
54 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro") # or "gemini-1.5-flash"
|
55 |
+
|
56 |
+
# Define Google Search tool (replace with actual search API)
|
57 |
+
def google_search(query: str) -> str:
|
58 |
+
# Use SerpAPI, Google Custom Search, etc.
|
59 |
+
return f"Search results for: {query}"
|
60 |
+
|
61 |
+
tools = [
|
62 |
+
Tool(
|
63 |
+
name="google_search",
|
64 |
+
func=google_search,
|
65 |
+
description="Useful for searching the web."
|
66 |
+
)
|
67 |
+
]
|
68 |
+
|
69 |
+
# Create agent
|
70 |
+
agent = create_tool_calling_agent(llm, tools, prompt_template=hub.pull("hwchase17/openai-tools-agent"))
|
71 |
+
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
72 |
+
|
73 |
+
# Run the agent
|
74 |
+
response = agent_executor.invoke({"input": prompt})
|
75 |
+
return response["output"]
|
76 |
+
|
77 |
+
|
78 |
def search_tool(self, prompt: str) -> str:
|
79 |
"""
|
80 |
Searches for information using a Gemini-powered agent with Google Search capability.
|