Paperbag commited on
Commit
334e8ea
·
1 Parent(s): 423ddfc

add wiki tool

Browse files
Files changed (2) hide show
  1. __pycache__/agent.cpython-39.pyc +0 -0
  2. agent.py +23 -0
__pycache__/agent.cpython-39.pyc CHANGED
Binary files a/__pycache__/agent.cpython-39.pyc and b/__pycache__/agent.cpython-39.pyc differ
 
agent.py CHANGED
@@ -5,6 +5,7 @@ from langgraph.graph import StateGraph, START, END
5
  from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFacePipeline
6
  from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
7
  from langchain_core.tools import tool
 
8
  from ddgs import DDGS
9
  from dotenv import load_dotenv
10
  from groq import Groq
@@ -58,6 +59,28 @@ def web_search(keywords: str, max_results:int = 5) -> str:
58
  output += f"Results: {result['title']}\n{result['body']}\n{result['href']}\n\n"
59
  return(output)
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  # @tool
62
  # def get_image_file(task_id):
63
  # """
 
5
  from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFacePipeline
6
  from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
7
  from langchain_core.tools import tool
8
+ from langchain_community.document_loaders import WikipediaLoader
9
  from ddgs import DDGS
10
  from dotenv import load_dotenv
11
  from groq import Groq
 
59
  output += f"Results: {result['title']}\n{result['body']}\n{result['href']}\n\n"
60
  return(output)
61
 
62
+ @tool
63
+ def wiki_search(query: str) -> str:
64
+ """
65
+ Search Wikipedia for a query and return a maximum of 2 results
66
+
67
+ Use cases:
68
+ When the question requires the use of information from wikipedia
69
+
70
+ Args:
71
+ query: The search query
72
+ """
73
+
74
+ search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
75
+ formatted_search_docs = "\n\n---\n\n".join(
76
+ [
77
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
78
+ for doc in search_docs
79
+ ])
80
+ return {"wiki_results": formatted_search_docs}
81
+
82
+
83
+
84
  # @tool
85
  # def get_image_file(task_id):
86
  # """