update notebook and make backwards compatible (#772)

This commit is contained in:
Harrison Chase 2023-01-28 07:23:04 -08:00 committed by GitHub
parent 924b7ecf89
commit a5d003f0c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 23 deletions

View File

@ -53,7 +53,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 2,
"id": "becda2a1", "id": "becda2a1",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -70,7 +70,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 3,
"id": "339b1bb8", "id": "339b1bb8",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -99,7 +99,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 4,
"id": "e21d2098", "id": "e21d2098",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -134,7 +134,6 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"id": "5e028e6d", "id": "5e028e6d",
"metadata": {}, "metadata": {},
@ -146,7 +145,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 5,
"id": "9b1cc2a2", "id": "9b1cc2a2",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -156,17 +155,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 7,
"id": "e4f5092f", "id": "e4f5092f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools)" "tool_names = [tool.name for tool in tools]\n",
"agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 8,
"id": "490604e9", "id": "490604e9",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -176,7 +176,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 9,
"id": "653b1617", "id": "653b1617",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -191,22 +191,23 @@
"Action: Search\n", "Action: Search\n",
"Action Input: Population of Canada\u001b[0m\n", "Action Input: Population of Canada\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mCanada is a country in North America. Its ten provinces and three territories extend from the Atlantic Ocean to the Pacific Ocean and northward into the Arctic Ocean, covering over 9.98 million square kilometres, making it the world's second-largest country by total area.\u001b[0m\n", "Observation: \u001b[36;1m\u001b[1;3mCanada is a country in North America. Its ten provinces and three territories extend from the Atlantic Ocean to the Pacific Ocean and northward into the Arctic Ocean, covering over 9.98 million square kilometres, making it the world's second-largest country by total area.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I need to find out the exact population of Canada\n", "Thought:\u001b[32;1m\u001b[1;3m I need to find out the population of Canada\n",
"Action: Search\n", "Action: Search\n",
"Action Input: Population of Canada 2020\u001b[0m\n", "Action Input: Population of Canada\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mCanada is a country in North America. Its ten provinces and three territories extend from the Atlantic Ocean to the Pacific Ocean and northward into the Arctic Ocean, covering over 9.98 million square kilometres, making it the world's second-largest country by total area.\u001b[0m\n", "Observation: \u001b[36;1m\u001b[1;3mCanada is a country in North America. Its ten provinces and three territories extend from the Atlantic Ocean to the Pacific Ocean and northward into the Arctic Ocean, covering over 9.98 million square kilometres, making it the world's second-largest country by total area.\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I now know the population of Canada\n", "Thought:\u001b[32;1m\u001b[1;3m I now know the population of Canada\n",
"Final Answer: Arrr, Canada be home to 37.59 million people!\u001b[0m\n", "Final Answer: Arrr, Canada be home to over 37 million people!\u001b[0m\n",
"\u001b[1m> Finished AgentExecutor chain.\u001b[0m\n" "\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
] ]
}, },
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"'Arrr, Canada be home to 37.59 million people!'" "'Arrr, Canada be home to over 37 million people!'"
] ]
}, },
"execution_count": 19, "execution_count": 9,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -361,7 +362,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -375,7 +376,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.12 (default, Feb 15 2022, 17:41:09) \n[Clang 12.0.5 (clang-1205.0.22.11)]" "version": "3.10.9"
}, },
"vscode": { "vscode": {
"interpreter": { "interpreter": {

View File

@ -33,7 +33,7 @@ class Agent(BaseModel):
""" """
llm_chain: LLMChain llm_chain: LLMChain
allowed_tools: List[str] allowed_tools: Optional[List[str]] = None
return_values: List[str] = ["output"] return_values: List[str] = ["output"]
@abstractmethod @abstractmethod
@ -269,11 +269,12 @@ class AgentExecutor(Chain, BaseModel):
"""Validate that tools are compatible with agent.""" """Validate that tools are compatible with agent."""
agent = values["agent"] agent = values["agent"]
tools = values["tools"] tools = values["tools"]
if set(agent.allowed_tools) != set([tool.name for tool in tools]): if agent.allowed_tools is not None:
raise ValueError( if set(agent.allowed_tools) != set([tool.name for tool in tools]):
f"Allowed tools ({agent.allowed_tools}) different than " raise ValueError(
f"provided tools ({[tool.name for tool in tools]})" f"Allowed tools ({agent.allowed_tools}) different than "
) f"provided tools ({[tool.name for tool in tools]})"
)
return values return values
def save(self, file_path: Union[Path, str]) -> None: def save(self, file_path: Union[Path, str]) -> None: