mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
community: fix bug to support for file_search
tool from OpenAI (#25927)
- **Description:** The function `_is_assistants_builtin_tool` didn't had support for `file_search` from OpenAI. This was creating conflict and blocking the usage of such. OpenAI Assistant changed from`retrieval` to `file_search`. The following code ``` agent = OpenAIAssistantV2Runnable.create_assistant( name="Data Analysis Assistant", instructions=prompt[0].content, tools={'type': 'file_search'}, model=self.chat_config.connection.deployment_name, client=llm, as_agent=True, tool_resources={ "file_search": { "vector_store_ids": vector_store_id } } ) ``` Was throwing the following error ``` Traceback (most recent call last): File "/Users/l.guedesdossantos/Documents/codes/shellai-nlp-backend/app/chat/chat_decorators.py", line 500, in get_response return await super().get_response(post, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/Documents/codes/shellai-nlp-backend/app/chat/chat_decorators.py", line 96, in get_response response = await self.inner_chat.get_response(post, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/Documents/codes/shellai-nlp-backend/app/chat/chat_decorators.py", line 96, in get_response response = await self.inner_chat.get_response(post, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/Documents/codes/shellai-nlp-backend/app/chat/chat_decorators.py", line 96, in get_response response = await self.inner_chat.get_response(post, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Previous line repeated 4 more times] File "/Users/l.guedesdossantos/Documents/codes/shellai-nlp-backend/app/chat/azure_open_ai_chat.py", line 147, in get_response chain = chain_factory.get_chain(prompts, post.conversation.id, overrides, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/Documents/codes/shellai-nlp-backend/app/llm_connections/chains.py", line 1324, in get_chain agent = OpenAIAssistantV2Runnable.create_assistant( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/anaconda3/envs/shell-e/lib/python3.11/site-packages/langchain_community/agents/openai_assistant/base.py", line 256, in create_assistant tools=[_get_assistants_tool(tool) for tool in tools], # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/anaconda3/envs/shell-e/lib/python3.11/site-packages/langchain_community/agents/openai_assistant/base.py", line 256, in <listcomp> tools=[_get_assistants_tool(tool) for tool in tools], # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/anaconda3/envs/shell-e/lib/python3.11/site-packages/langchain_community/agents/openai_assistant/base.py", line 119, in _get_assistants_tool return convert_to_openai_tool(tool) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/anaconda3/envs/shell-e/lib/python3.11/site-packages/langchain_core/utils/function_calling.py", line 255, in convert_to_openai_tool function = convert_to_openai_function(tool) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/l.guedesdossantos/anaconda3/envs/shell-e/lib/python3.11/site-packages/langchain_core/utils/function_calling.py", line 230, in convert_to_openai_function raise ValueError( ValueError: Unsupported function {'type': 'file_search'} Functions must be passed in as Dict, pydantic.BaseModel, or Callable. If they're a dict they must either be in OpenAI function format or valid JSON schema with top-level 'title' and 'description' keys. ``` With the proposed changes, this is fixed and the function will have support for `file_search`. This was the only place missing the support for `file_search`. Reference doc https://platform.openai.com/docs/assistants/tools/file-search - **Twitter handle:** luizf0992 --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
f49cce739b
commit
36bbdc776e
@ -91,7 +91,7 @@ def _is_assistants_builtin_tool(
|
||||
A boolean response of true or false indicating if the tool corresponds to
|
||||
OpenAI Assistants built-in.
|
||||
"""
|
||||
assistants_builtin_tools = ("code_interpreter", "retrieval")
|
||||
assistants_builtin_tools = ("code_interpreter", "retrieval", "file_search")
|
||||
return (
|
||||
isinstance(tool, dict)
|
||||
and ("type" in tool)
|
||||
|
Loading…
Reference in New Issue
Block a user