-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hemslo/generic-search
Generic search
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from langchain.agents import AgentExecutor | ||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder | ||
from langchain.globals import set_debug | ||
from .util import create_ollama_functions_agent | ||
from ..dependencies.ollama_functions_model import ollama_functions_model | ||
from ..tools.duckduckgo_search import duckduckgo_search | ||
from typing import Any | ||
from pydantic import BaseModel | ||
|
||
prompt = ChatPromptTemplate.from_messages( | ||
[ | ||
( | ||
"user", | ||
"{input}", | ||
), | ||
MessagesPlaceholder(variable_name="agent_scratchpad"), | ||
] | ||
) | ||
|
||
class Input(BaseModel): | ||
input: str | ||
|
||
|
||
class Output(BaseModel): | ||
output: Any | ||
|
||
tools = [duckduckgo_search] | ||
llm = ollama_functions_model | ||
agent = create_ollama_functions_agent(llm, tools, prompt) | ||
|
||
search_engine_agent_executor = AgentExecutor( | ||
agent=agent, | ||
tools=tools, | ||
).with_types( | ||
input_type=Input, | ||
output_type=Output, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from langchain_community.tools import DuckDuckGoSearchResults | ||
from langchain_community.utilities import DuckDuckGoSearchAPIWrapper | ||
|
||
|
||
from langchain_core.tools import tool | ||
|
||
|
||
@tool() | ||
def duckduckgo_search(): | ||
""" | ||
Get search result from Duckduckgo | ||
""" | ||
wrapper = DuckDuckGoSearchAPIWrapper(max_results=10) | ||
search = DuckDuckGoSearchResults(api_wrapper=wrapper) | ||
return search |