Spaces:
Running
Running
# 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 | |
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): | |
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"] | |