“助手”在 openAI 助手中没有属性“文件”

问题描述 投票:0回答:1
assistant_file = client.beta.assistants.files.create(
    assistant_id = st.session_state.assistant_id,
    file_id = st.session_state.file_id
)

我有这段代码,我必须集成,但它显示“助手”没有属性“文件”,这段代码大约有 8 个月的历史,我知道 API 从那时起可能发生了变化,但我找不到任何替代方案文档中对此进行了说明。有人有迁移此代码的经验吗?

python-3.x openai-api openai-assistants-api
1个回答
0
投票

您尝试使用的方法(即

.files.create
)不存在。

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

v1

如果您想创建助手,请使用以下代码(与 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)

如果您想为助手创建文件,请使用以下代码(与 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)
© www.soinside.com 2019 - 2024. All rights reserved.