“Assistants“ has no attribute “files“ in openAI assistants

题意:在 OpenAI 的助手(assistants)中,“Assistants” 没有 “files” 这个属性。

问题背景:

assistant_file = client.beta.assistants.files.create(
    assistant_id = st.session_state.assistant_id,
    file_id = st.session_state.file_id
)

I have this code which I have to integrate but it's showing up that "Assistants" have no attribute "file", this code is around 8 months old, and I understand that the API probably changed since then, but I cannot find any alternatives to this in the documentation. Does anyone have any experience in migrating this code ?

我有这段代码需要集成,但是它显示“Assistants”没有“file”这个属性。这段代码大约有8个月的历史了,我理解从那时起API可能已经发生了变化,但我在文档中找不到关于这个问题的替代方案。有人有迁移这段代码的经验吗?

问题解决:

The method you're trying to use (i.e., .files.create) doesn't exist.

你试图使用的方法(即 .files.create)不存在。

Moreover, this code wouldn't work even with the OpenAI Assistants API v1.

此外,即使使用 OpenAI Assistants API v1,这段代码也无法工作。

If you want to create an assistant, use the following code (works with the OpenAI Assistants API v2):

如果你想要创建一个助手,请使用以下代码(适用于 OpenAI Assistants API v2):

from openai import OpenAI
client = OpenAI()

my_assistant = client.beta.assistants.create(
    instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
    name="Math Tutor",
    tools=[{"type": "code_interpreter"}],
    model="gpt-4o",
)

print(my_assistant)

If you want to create a file for an assistant, use the following code (works with the OpenAI Assistants API v2):

如果你想要为助手创建一个文件,请使用以下代码(适用于 OpenAI Assistants API v2):

from openai import OpenAI
client = OpenAI()

my_file = client.files.create(
  file=open("mydata.jsonl", "rb"),
  purpose="assistants"
)

print(my_file)

  • 19
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值