ai21 instance not runnable with langchain

#45
by LordSahu - opened

I am facing an issue with AI21 LLM, instance of LLM should be runnable.
I have used my AI21Client to get access my api_key and use my client
Then I have used Langchain agents to add serpapi in my system.
To fetch results from the google-search-results

from langchain.agents import AgentType
from langchain.agents import load_tools, initialize_agent
from langchain.llms import ai21
from ai21 import AI21Client
client = AI21Client(api_key=jurasic_key)
tool = load_tools(["serpapi"],serpapi_api_key=serpapi_key,llm=client)
agent = initialize_agent(tool,client,agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,verbose=True)

Output for:
client -> <ai21.clients.studio.ai21_client.AI21Client at 0x1e3e2e34250>
tool -> [Tool(name='Search', description='A search engine. Useful for when you need to answer questions about current events. Input should be a search query.', func=<bound method SerpAPIWrapper.run of SerpAPIWrapper(search_engine=<class 'serpapi.google_search.GoogleSearch'>, params={'engine': 'google', 'google_domain': 'google.com', 'gl': 'us', 'hl': 'en'}, serpapi_api_key='serpapi_key', aiosession=None)>, coroutine=<bound method SerpAPIWrapper.arun of SerpAPIWrapper(search_engine=<class 'serpapi.google_search.GoogleSearch'>, params={'engine': 'google', 'google_domain': 'google.com', 'gl': 'us', 'hl': 'en'}, serpapi_api_key='serpapi_key', aiosession=None)>)

For agents it should have considered my tool and client but it is throwing this error
Error:
ValidationError Traceback (most recent call last)
Cell In[103], line 1
----> 1 agent = initialize_agent(tool,client,agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,verbose=True)
2 agent

File u:\GenAI.venv\lib\site-packages\langchain_core_api\deprecation.py:168, in deprecated..deprecate..warning_emitting_wrapper(*args, **kwargs)
166 warned = True
167 emit_warning()
--> 168 return wrapped(*args, **kwargs)

File u:\GenAI.venv\lib\site-packages\langchain\agents\initialize.py:67, in initialize_agent(tools, llm, agent, callback_manager, agent_path, agent_kwargs, tags, **kwargs)
65 agent_cls = AGENT_TO_CLASS[agent]
66 agent_kwargs = agent_kwargs or {}
---> 67 agent_obj = agent_cls.from_llm_and_tools(
68 llm, tools, callback_manager=callback_manager, **agent_kwargs
69 )
70 elif agent_path is not None:
71 agent_obj = load_agent(
72 agent_path, llm=llm, tools=tools, callback_manager=callback_manager
73 )

File u:\GenAI.venv\lib\site-packages\langchain\agents\mrkl\base.py:113, in ZeroShotAgent.from_llm_and_tools(cls, llm, tools, callback_manager, output_parser, prefix, suffix, format_instructions, input_variables, **kwargs)
105 cls._validate_tools(tools)
106 prompt = cls.create_prompt(
...
ValidationError: 2 validation errors for LLMChain
llm
instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)
llm
instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)

How to make my LLM instance runnable ?

I'm Facing the same issue. did you get any solution ?

Sign up or log in to comment