OpenAI Assistants API v2: Should I attach files to the thread or to the assistant?
发布时间
阅读量:
阅读量
题意 :OpenAI Assistants API v2: 我应该将文件附加到线程还是附加到助手
问题背景:
I am accessing the OpenAI Assistant API, and I have the ability to add my PDF files into my knowledge base.
我正在调用 OpenAI Assistants API,并且可以将我的 PDF 文件作为知识库导入。
Should I attach files to the thread or to the assistant?
我应该将文件附加到线程还是附加到助手?
I am super confused here.
我在这里感到非常困惑。
Or should I add them both times?
还是我应该两次都添加它们?
What would work best? 什么方法效果最好?
问题解决:
Upon utilizing the OpenAI Assistants API version 2, one adds attachments to a thread when sending a user message by employing the attachments parameter.
在使用 OpenAIAssistantsAPIv2 时,在调用该 API 的 attachments 参数字段中提交消息至线程中,则可增添文件。
In the code examples below, I passed a file with the file_search tool.
在下面的代码示例中,我使用 file_search 工具传递了一个文件。
Python:
my_thread_message = client.beta.threads.messages.create(
thread_id=my_thread.id,
role="user",
content=user_input,
attachments=[ # 👈 Add files by using the attachments parameter
{"file_id": file_id, "tools": [{"type": "file_search"}]}
],
)
Node.js:
const myThreadMessage = await openai.beta.threads.messages.create(
(thread_id = myThread.id),
{
role: "user",
content: userInput,
attachments: [ // 👈 Add files by using the attachments parameter
{
file_id: fileID,
tools: [{ type: "file_search" }],
},
],
}
);

全部评论 (0)
还没有任何评论哟~
