Spaces:
Running
Running
File size: 972 Bytes
adaea7c 986fa13 adaea7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_lchain_tool.ipynb.
# %% auto 0
__all__ = ['RecipeSerpAPIWrapper']
# %% ../nbs/02_lchain_tool.ipynb 3
import os
from IPython.display import Image
from langchain.agents import AgentType, Tool, initialize_agent, load_tools, tool
from langchain.agents.agent_toolkits import create_python_agent
from langchain.chat_models import ChatOpenAI
from langchain.python import PythonREPL
from langchain.tools.python.tool import PythonREPLTool
from langchain.utilities import GoogleSerperAPIWrapper, SerpAPIWrapper
from serpapi import GoogleSearch
# %% ../nbs/02_lchain_tool.ipynb 12
class RecipeSerpAPIWrapper(SerpAPIWrapper):
@staticmethod
def _process_response(res: dict) -> str:
"""Process response from SerpAPI."""
if "error" in res.keys():
raise ValueError(f"Got error from SerpAPI: {res['error']}")
if "recipes_results" in res.keys():
return res["recipes_results"]
|