Skip to content

Commit

Permalink
updating example (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSalesforce authored May 21, 2024
2 parents f228a0e + 057728b commit 9e912ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
19 changes: 11 additions & 8 deletions example/SearchActions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from langchain_community.tools import DuckDuckGoSearchResults, WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
import wikipedia
import duckduckgo_search

from agentlite.actions.BaseAction import BaseAction

Expand All @@ -11,25 +11,28 @@ def __init__(self) -> None:
action_name = "DuckDuckGo_Search"
action_desc = "Using this action to search online content."
params_doc = {"query": "the search string. be simple."}
self.search = DuckDuckGoSearchResults()
self.ddgs = duckduckgo_search.DDGS()
super().__init__(
action_name=action_name, action_desc=action_desc, params_doc=params_doc,
)

def __call__(self, query):
return self.search.run(query)


results = self.ddgs.chat(query)
return results
class WikipediaSearch(BaseAction):
def __init__(self) -> None:
action_name = "Wikipedia_Search"
action_desc = "Using this API to search Wiki content."
params_doc = {"query": "the search string. be simple."}

self.search = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
super().__init__(
action_name=action_name, action_desc=action_desc, params_doc=params_doc,
)

def __call__(self, query):
return self.search.run(query)
search_results = wikipedia.search(query)
if not search_results:
return "No results found."
article = wikipedia.page(search_results[0])
return article.summary
3 changes: 2 additions & 1 deletion example/SearchAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def test_search_agent():
# role = "searching online content"
# labor_agent = SearchAgent(name=name, role=role, llm=llm, actions=actions)
## test the one-shot wikipedia search agent
labor_agent = WikiSearchAgent(llm=llm)
# labor_agent = WikiSearchAgent(llm=llm)
labor_agent = DuckSearchAgent(llm=llm)

test_task = "what is the found date of microsoft"
test_task_pack = TaskPackage(instruction=test_task)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pydantic
## example dependencies
numpy
wikipedia
duckduckgo-search
duckduckgo-search==6.1.0
openmeteo_requests==1.2.0
requests_cache==1.2.0
retry_requests==2.0.0
Expand Down

0 comments on commit 9e912ae

Please sign in to comment.