langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.43k stars 15.04k forks source link

Assistants.create() got an unexpected keyword argument 'file_ids' #20842

Closed pletinsky closed 5 months ago

pletinsky commented 5 months ago

Checked other resources

Example Code


from langchain.agents.openai_assistant import OpenAIAssistantRunnable

assistant = OpenAIAssistantRunnable.create_assistant(
    name="langchain assistant",
    instructions="You are a personal math tutor. Write and run code to answer math questions.",
    tools=[{"type": "code_interpreter"}],
    model="gpt-4-1106-preview",
    )
result = assistant.invoke({"content": "What's 10 - 4 raised to the 2.7"})

### Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Repo/ai/main.py", line 16, in read_root
    return await interact(message.text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Repo/ai/bot/bot.py", line 16, in interact
    assistant = OpenAIAssistantRunnable.create_assistant(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/home/Library/Caches/pypoetry/virtualenvs/A5OhnBxC-py3.12/lib/python3.12/site-packages/langchain/agents/openai_assistant/base.py", line 247, in create_assistant
    assistant = client.beta.assistants.create(

### Description

I am trying to create the Open AI Assistant and I se the error: "TypeError: Assistants.create() got an unexpected keyword argument 'file_ids'"

### System Info

macos

> Python Version:  3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
> langchain_core: 0.1.45
> langchain: 0.1.16
> langchain_community: 0.0.34
> langsmith: 0.1.50
> langchain_openai: 0.1.3
> langchain_text_splitters: 0.0.1
> langchainhub: 0.1.15

fastapi: 0.110.2
uvicorn: 0.29.0
wodka commented 3 months ago

@pletinsky how did you solve the problem?

pletinsky commented 3 months ago

@wodka, I don't remember, unfortunately. We avoided using the open ai assistant. It seems that there was a need to upgrade to the beta version. But I could be wrong.

janhenrikbern commented 2 months ago

Hi! I encountered the same error. Looking at the openai github, file_ids should be provided as part of tool_resources, see this comment.

I am using:

langchain==0.2.9
langchain-openai==0.1.17
openai==1.35.13

Under which conditions is this confirmed to be working?

Edit: I got the OpenAI Assistants running by removing all injections of file_ids from the beta.assistants.create call and thread messages in langchain/agents/openai_assistant/base.py. I definitely miss a lot of context here, so please forgive me if my proposed solution makes no sense. In my naive perspective, I would propose removing file_ids from the top level and only include it in an optional tool_resources argument.