我在使用OpenAI Assistants API,并且可以选择将我的PDF文件作为知识库添加。
我应该将文件附加到线程上还是助手上呢?
我对此非常困惑。
还是应该在两处都添加?
哪种方式效果最好?
回答:
在使用OpenAI Assistants API v2
时,您可以通过在向线程添加用户消息时使用attachments
参数来附加文件。
在下面的代码示例中,我使用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" }], }, ], });