You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用OpenAI Python API向ChatGPT助手传文件时遇file_ids参数错误

解决方法
  • 移除file_ids参数,改用content数组同时包含文本和文件引用
    最新版OpenAI Threads Messages API已废弃file_ids参数,需将文件作为content数组的一个对象传入,指定类型为file并关联文件ID。

  • 修正后的代码:

# Create a message with the uploaded file
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content=[
        {"type": "text", "text": "Here is the HTML content for the seminar page."},
        {"type": "file", "file_id": file.id}
    ]
)
  • 注意事项:
    • 确保OpenAI Python包为最新版本,执行pip install --upgrade openai更新
    • 上传的文件需先通过client.files.create()完成上传,且文件状态为processed
    • 确认使用的模型支持文件处理(如GPT-4o、GPT-4 Turbo)

内容的提问来源于stack exchange,提问作者John Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 23:02:38