Open rdvhoorn opened 5 months ago
I just figured out that the following does not error in the same way. It is ugly, but it seems to work:
from langchain_google_community import GoogleSearchAPIWrapper
from langchain_core.runnables import RunnablePassthrough, RunnableParallel, RunnableLambda
from langchain_core.tools import Tool
# Initialize tools to use
search = GoogleSearchAPIWrapper()
google_search_tool = Tool(
name="google-search",
description="Search Google for web results.",
func=search.run,
)
search2 = GoogleSearchAPIWrapper()
google_search_tool2 = Tool(
name="google-search",
description="Search Google for web results.",
func=search2.run,
)
chain = (
RunnableParallel({
"search_results": google_search_tool,
"input": RunnablePassthrough()
})
|
RunnableParallel({
"search_results": RunnableLambda(lambda x: x['input']) | google_search_tool2
})
)
chain.batch([{'__arg1': 'What is LangChain?'}, {'__arg1': 'What is an LLM?'}])
Or more shorthand:
# Initialize tools to use
number_of_google_calls_in_chain = 2
wrappers = [GoogleSearchAPIWrapper() for _ in range(number_of_google_calls_in_chain)]
search_tools = [Tool(name="google-search", description="Search Google for web results.", func=wrapper.run) for wrapper in wrappers]
chain = (
RunnableParallel({
"search_results": search_tools[0],
"input": RunnablePassthrough()
})
| RunnableParallel({
"search_results": RunnableLambda(lambda x: x['input']) | search_tools[1]
})
)
chain.batch([{'__arg1': 'What is LangChain?'}, {'__arg1': 'What is an LLM?'}])
but we probably should fix the wrapper too :)
If you give me an indication of where to look, or what it might be, i would be willing to look into it. But since there are like 5 different, not very descriptive, errors, im not burning my hands without some guidance xD
Hi! I was working with the GoogleSearchAPIWrapper for batched calls to the google search API. I was prototyping in a jupyter Notebook when I noticed an error when two batched calls are made without rerunning the search tool initialization.
Here is a minimal example that simply returns exactly what you would expect:
However, once you remove the initialization from the function calling, i.e. like this:
And call
google_search_tool.batch([{'__arg1': 'What is LangChain?'}, {'__arg1': 'What is an LLM?'}])
in a separate cell:It will successfully run the first time you run the second cell. But once you rerun the second cell for a second time, without rerunning the initialization of the tool, you can get the following possible errors:
Option 1:
Option 2:
Option 3:
Option 4:
This becomes highly problematic when you have 2 search calls in a single chain, such as:
Which results in the same errors as I mentioned above.
I have absolutely no idea how to fix/work around this issue. So, any help on what the cause of this error is, or how to solve it or work around it would be very helpful.
Versions: python 3.12.2 langchain_google_community: 1.0.3 langchain_core: 0.1.45