langchain OpenAI助手新版本似乎不兼容,

vbkedwbf  于 3个月前  发布在  其他
关注(0)|答案(3)|浏览(60)

检查其他资源

  • 为这个问题添加了一个非常描述性的标题。
  • 使用集成搜索在LangChain文档中进行了搜索。
  • 使用GitHub搜索找到了一个类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此错误。

示例代码

interpreter_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",
)

错误信息和堆栈跟踪(如果适用)

TypeError Traceback (most recent call last)
Cell In[24], line 1
----> 1 interpreter_assistant = OpenAIAssistantRunnable.create_assistant(
2 name="langchain assistant",
3 instructions="You are a personal math tutor. Write and run code to answer math questions.",
4 tools=[{"type": "code_interpreter"}],
5 model="gpt-4-1106-preview",
6 )
File ~/python3.11/lib/python3.11/site-packages/langchain/agents/openai_assistant/base.py:247, in OpenAIAssistantRunnable.create_assistant(cls, name, instructions, tools, model, client, **kwargs)
233 """Create an OpenAI Assistant and instantiate the Runnable.
234
235 Args:
(...)
244 OpenAIAssistantRunnable configured to run using the created assistant.
245 """
246 client = client or _get_openai_client()
--> 247 assistant = client.beta.assistants.create(
248 name=name,
249 instructions=instructions,
250 tools=[_get_assistants_tool(tool) for tool in tools], # type: ignore
251 model=model,
252 file_ids=kwargs.get("file_ids"),
253 )
254 return cls(assistant_id=assistant.id, client=client, **kwargs)
TypeError: Assistants.create() got an unexpected keyword argument 'file_ids'

描述

可能是新的OpenAi助手V2不接受file_ids参数。

pobjuy32

pobjuy321#

从openAI文档:

from openai import OpenAI
client = OpenAI()
  
assistant = client.beta.assistants.create(
  name="Math Tutor",
  instructions="You are a personal math tutor. Write and run code to answer math questions.",
  tools=[{"type": "code_interpreter"}],
  model="gpt-4-turbo",
)

所以这看起来像是langchain代码应该更新。
如果有帮助的话,我可以完成这项工作并提交pull request。

sg3maiej

sg3maiej2#

我确认。代码在v2助手上无法使用:
这里是更改:
https://platform.openai.com/docs/assistants/migration/what-has-changed
始终可以通过安装openai<=1.20的旧版本来使用助手v1,但v1将被openai淘汰,因此我认为没有必要与langchain维护v1。

cnwbcb6i

cnwbcb6i3#

@jjehl 我已经创建了一个拉取请求(PR),提议解决这个问题。请确认是否可以。
#21484
谢谢
Surya

相关问题