Replace You with DDG in xml agent (#12504)

You requires an email to get an API key which IMO is too much friction.
Duckduck go is free and easy to install.
This commit is contained in:
William FH
2023-10-31 04:51:00 +09:00
committed by GitHub
parent 6e702b9c36
commit 199630ff93
3 changed files with 415 additions and 37 deletions

View File

@@ -1,14 +1,11 @@
from typing import List, Tuple
from langchain.agents import AgentExecutor
from langchain.agents.agent_toolkits.conversational_retrieval.tool import (
create_retriever_tool,
)
from langchain.agents.format_scratchpad import format_xml
from langchain.chat_models import ChatAnthropic
from langchain.pydantic_v1 import BaseModel
from langchain.retrievers.you import YouRetriever
from langchain.schema import AIMessage, HumanMessage
from langchain.tools import DuckDuckGoSearchRun
from langchain.tools.render import render_text_description
from xml_agent.prompts import conversational_prompt, parse_output
@@ -24,13 +21,8 @@ def _format_chat_history(chat_history: List[Tuple[str, str]]):
model = ChatAnthropic(model="claude-2")
# Fake Tool
retriever = YouRetriever(k=5)
retriever_tool = create_retriever_tool(
retriever, "search", "Use this to search for current events."
)
tools = [retriever_tool]
tools = [DuckDuckGoSearchRun()]
prompt = conversational_prompt.partial(
tools=render_text_description(tools),