Spaces:
Sleeping
Sleeping
feat: :sparkles: add googleapi
Browse files- __pycache__/agents.cpython-312.pyc +0 -0
- __pycache__/tools.cpython-312.pyc +0 -0
- qa_graph.py +21 -13
- requirements.txt +2 -0
- tools.py +18 -1
__pycache__/agents.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/agents.cpython-312.pyc and b/__pycache__/agents.cpython-312.pyc differ
|
|
|
__pycache__/tools.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/tools.cpython-312.pyc and b/__pycache__/tools.cpython-312.pyc differ
|
|
|
qa_graph.py
CHANGED
|
@@ -34,13 +34,14 @@ def get_file_type(file_path: str) -> str:
|
|
| 34 |
|
| 35 |
def ask_question(question: str, thread_id: str = "default") -> str:
|
| 36 |
"""Ask the agent a question."""
|
| 37 |
-
config = {"configurable": {"thread_id": thread_id}}
|
| 38 |
|
| 39 |
try:
|
| 40 |
response = general_agent.invoke(
|
| 41 |
{"messages": [{"role": "user", "content": question}]},
|
| 42 |
config=config
|
| 43 |
)
|
|
|
|
| 44 |
return response["messages"][-1].content
|
| 45 |
except Exception as e:
|
| 46 |
return f"Error: {str(e)}"
|
|
@@ -87,6 +88,12 @@ def ask_question_youtube(question: Question) -> str:
|
|
| 87 |
return result["messages"][-1].content
|
| 88 |
|
| 89 |
test = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
# {
|
| 91 |
# "task_id": "cca530fc-4052-43b2-b130-b30968d8aa44",
|
| 92 |
# "question": "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
|
@@ -117,18 +124,18 @@ test = [
|
|
| 117 |
# "Level": "1",
|
| 118 |
# "file_name": ""
|
| 119 |
# },
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
]
|
| 133 |
|
| 134 |
questions = [Question(**item) for item in test]
|
|
@@ -232,6 +239,7 @@ if __name__ == "__main__":
|
|
| 232 |
"decision": "",
|
| 233 |
"answer": ""
|
| 234 |
})
|
|
|
|
| 235 |
|
| 236 |
print(f"Answer: {result['answer']}")
|
| 237 |
print("-" * 50)
|
|
|
|
| 34 |
|
| 35 |
def ask_question(question: str, thread_id: str = "default") -> str:
|
| 36 |
"""Ask the agent a question."""
|
| 37 |
+
config = {"configurable": {"thread_id": thread_id}, "recursion_limit": 100}
|
| 38 |
|
| 39 |
try:
|
| 40 |
response = general_agent.invoke(
|
| 41 |
{"messages": [{"role": "user", "content": question}]},
|
| 42 |
config=config
|
| 43 |
)
|
| 44 |
+
print(response["messages"])
|
| 45 |
return response["messages"][-1].content
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error: {str(e)}"
|
|
|
|
| 88 |
return result["messages"][-1].content
|
| 89 |
|
| 90 |
test = [
|
| 91 |
+
{
|
| 92 |
+
"task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
|
| 93 |
+
"question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
|
| 94 |
+
"Level": "1",
|
| 95 |
+
"file_name": ""
|
| 96 |
+
},
|
| 97 |
# {
|
| 98 |
# "task_id": "cca530fc-4052-43b2-b130-b30968d8aa44",
|
| 99 |
# "question": "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
|
|
|
| 124 |
# "Level": "1",
|
| 125 |
# "file_name": ""
|
| 126 |
# },
|
| 127 |
+
# {
|
| 128 |
+
# "task_id": "9d191bce-651d-4746-be2d-7ef8ecadb9c2",
|
| 129 |
+
# "question": "Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\n\nWhat does Teal'c say in response to the question \"Isn't that hot?\"",
|
| 130 |
+
# "Level": "1",
|
| 131 |
+
# "file_name": ""
|
| 132 |
+
# },
|
| 133 |
+
# {
|
| 134 |
+
# "task_id": "a1e91b78-d3d8-4675-bb8d-62741b4b68a6",
|
| 135 |
+
# "question": "In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?",
|
| 136 |
+
# "Level": "1",
|
| 137 |
+
# "file_name": ""
|
| 138 |
+
# },
|
| 139 |
]
|
| 140 |
|
| 141 |
questions = [Question(**item) for item in test]
|
|
|
|
| 239 |
"decision": "",
|
| 240 |
"answer": ""
|
| 241 |
})
|
| 242 |
+
print(result)
|
| 243 |
|
| 244 |
print(f"Answer: {result['answer']}")
|
| 245 |
print("-" * 50)
|
requirements.txt
CHANGED
|
@@ -11,3 +11,5 @@ arxiv
|
|
| 11 |
openpyxl
|
| 12 |
ultralytics
|
| 13 |
youtube-transcript-api
|
|
|
|
|
|
|
|
|
| 11 |
openpyxl
|
| 12 |
ultralytics
|
| 13 |
youtube-transcript-api
|
| 14 |
+
google-api-python-client
|
| 15 |
+
langchain-google-community
|
tools.py
CHANGED
|
@@ -5,6 +5,10 @@ from langchain_community.tools import (
|
|
| 5 |
WikipediaQueryRun,
|
| 6 |
ArxivQueryRun
|
| 7 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from langchain_community.utilities import WikipediaAPIWrapper, ArxivAPIWrapper
|
| 9 |
from langchain_openai import ChatOpenAI
|
| 10 |
|
|
@@ -25,6 +29,8 @@ import re
|
|
| 25 |
from dotenv import load_dotenv
|
| 26 |
load_dotenv()
|
| 27 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 28 |
client = InferenceClient(
|
| 29 |
provider="hf-inference",
|
| 30 |
api_key=HF_TOKEN,
|
|
@@ -323,11 +329,22 @@ def analyze_video_content(video_url: str, question: str = "", max_vision_frames:
|
|
| 323 |
|
| 324 |
except Exception as e:
|
| 325 |
return f"Error analyzing video content: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
def general_tools():
|
| 327 |
tools = [
|
| 328 |
-
DuckDuckGoSearchRun(),
|
| 329 |
WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper()),
|
| 330 |
ArxivQueryRun(api_wrapper=ArxivAPIWrapper()),
|
|
|
|
| 331 |
analyze_image,
|
| 332 |
read_python_file,
|
| 333 |
transcribe_audio,
|
|
|
|
| 5 |
WikipediaQueryRun,
|
| 6 |
ArxivQueryRun
|
| 7 |
)
|
| 8 |
+
from langchain_google_community.search import (
|
| 9 |
+
GoogleSearchAPIWrapper,
|
| 10 |
+
GoogleSearchRun
|
| 11 |
+
)
|
| 12 |
from langchain_community.utilities import WikipediaAPIWrapper, ArxivAPIWrapper
|
| 13 |
from langchain_openai import ChatOpenAI
|
| 14 |
|
|
|
|
| 29 |
from dotenv import load_dotenv
|
| 30 |
load_dotenv()
|
| 31 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 32 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 33 |
+
GOOGLE_CSE_ID = os.getenv("GOOGLE_CSE_ID")
|
| 34 |
client = InferenceClient(
|
| 35 |
provider="hf-inference",
|
| 36 |
api_key=HF_TOKEN,
|
|
|
|
| 329 |
|
| 330 |
except Exception as e:
|
| 331 |
return f"Error analyzing video content: {str(e)}"
|
| 332 |
+
@tool
|
| 333 |
+
def google_search():
|
| 334 |
+
"""Google search tool"""
|
| 335 |
+
api_wrapper = GoogleSearchAPIWrapper(
|
| 336 |
+
google_api_key=GOOGLE_API_KEY,
|
| 337 |
+
google_cse_id=GOOGLE_CSE_ID,
|
| 338 |
+
k=10, # Number of results
|
| 339 |
+
siterestrict=False # Site restrictions
|
| 340 |
+
)
|
| 341 |
+
google_search = GoogleSearchRun(api_wrapper=api_wrapper)
|
| 342 |
+
return google_search
|
| 343 |
def general_tools():
|
| 344 |
tools = [
|
|
|
|
| 345 |
WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper()),
|
| 346 |
ArxivQueryRun(api_wrapper=ArxivAPIWrapper()),
|
| 347 |
+
google_search,
|
| 348 |
analyze_image,
|
| 349 |
read_python_file,
|
| 350 |
transcribe_audio,
|