alexrudall / ruby-openai

OpenAI API + Ruby! 🤖❤️ NEW: Assistant Vector Stores
MIT License
2.61k stars 302 forks source link

Add the Vector Store, Vector Store Files and Vector Store Batch Files APIs #463

Closed alexrudall closed 2 weeks ago

alexrudall commented 2 months ago
MarcoBgn commented 2 months ago

Thanks for that, a side note:

At the moment is not possible to use the Assistant V2, as they renamed 'retrieval' to 'file_search':

OpenAI HTTP Error (spotted in ruby-openai 6.3.1): {"error"=>{"message"=>"Invalid value: 'file_search'. Supported values are: 'code_interpreter', 'function', and 'retrieval'.", "type"=>"invalid_request_error", "param"=>"tools[1].type", "code"=>"invalid_value"}}
alexrudall commented 2 months ago

Thanks for that, a side note:

At the moment is not possible to use the Assistant V2, as they renamed 'retrieval' to 'file_search':

OpenAI HTTP Error (spotted in ruby-openai 6.3.1): {"error"=>{"message"=>"Invalid value: 'file_search'. Supported values are: 'code_interpreter', 'function', and 'retrieval'.", "type"=>"invalid_request_error", "param"=>"tools[1].type", "code"=>"invalid_value"}}

Thanks @MarcoBgn , ~can you try with version 7? EDIT: I can see this is in the README example. I'll fix this~ I've updated the README so the code_interpreter example works - like you said, file_search won't work until we add Vector Store.

willywg commented 2 months ago

Thanks for that, a side note:

At the moment is not possible to use the Assistant V2, as they renamed 'retrieval' to 'file_search':

OpenAI HTTP Error (spotted in ruby-openai 6.3.1): {"error"=>{"message"=>"Invalid value: 'file_search'. Supported values are: 'code_interpreter', 'function', and 'retrieval'.", "type"=>"invalid_request_error", "param"=>"tools[1].type", "code"=>"invalid_value"}}

@MarcoBgn I faced the same issue, but since I only needed to send attachments via messages, with this monkey patch, I was able to use the messages API with attachments in the parameters.

# OpenAI Patch to use beta API v2
module OpenAIPatch
  def beta(apis)
    dup.tap do |client|
      client.add_headers("OpenAI-Beta": apis.map { |k, v| "#{k}=v2" }.join(";"))
    end  
  end
end
OpenAI::Client.prepend(OpenAIPatch)

client = OpenAI::Client.new(...)
alexrudall commented 2 months ago

Thanks for that, a side note: At the moment is not possible to use the Assistant V2, as they renamed 'retrieval' to 'file_search':

OpenAI HTTP Error (spotted in ruby-openai 6.3.1): {"error"=>{"message"=>"Invalid value: 'file_search'. Supported values are: 'code_interpreter', 'function', and 'retrieval'.", "type"=>"invalid_request_error", "param"=>"tools[1].type", "code"=>"invalid_value"}}

@MarcoBgn I faced the same issue, but since I only needed to send attachments via messages, with this monkey patch, I was able to use the messages API with attachments in the parameters.

# OpenAI Patch to use beta API v2
module OpenAIPatch
  def beta(apis)
    dup.tap do |client|
      client.add_headers("OpenAI-Beta": apis.map { |k, v| "#{k}=v2" }.join(";"))
    end  
  end
end
OpenAI::Client.prepend(OpenAIPatch)

client = OpenAI::Client.new(...)

I released ruby-openai 7 this weekend which uses v2 so you don't need to do this any more if you upgrade :)

willywg commented 2 months ago

@alexrudall thanks for amazing gem, but this don't work for me because you haven't updated the version on Message endpoint. I get this error:

I, [2024-04-29T17:22:33.757198 #9315]  INFO -- request: POST https://api.openai.com/v1/threads/thread_IOAErVqNdHKxUtBhwbczpKqL/messages
I, [2024-04-29T17:22:33.757366 #9315]  INFO -- request: Content-Type: "application/json"
Authorization: "Bearer sk-XXX"
OpenAI-Organization: "org-XXX"
OpenAI-Beta: "assistants=v1"
I, [2024-04-29T17:22:33.757408 #9315]  INFO -- request: {"role":"user","content":"De que trata este file?","attachments":[{"file_id":"file-LubipmNsgV4tVJ6hUeXXXyEo","tools":[{"type":"file_search"}]}]}
I, [2024-04-29T17:22:34.384360 #9315]  INFO -- response: Status 400
I, [2024-04-29T17:22:34.384946 #9315]  INFO -- response: date: "Mon, 29 Apr 2024 22:22:34 GMT"
content-type: "application/json"
content-length: "169"
connection: "keep-alive"
openai-version: "2020-10-01"
openai-organization: "gojom-1"
x-request-id: "req_2f94e391deeccbcb5e44fadac7401986"
openai-processing-ms: "84"
strict-transport-security: "max-age=15724800; includeSubDomains"
cf-cache-status: "DYNAMIC"
set-cookie: "__cf_bm=XXX-1714429354-1.0.1.1-XXX; path=/; expires=Mon, 29-Apr-24 22:52:34 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None, _cfuvid=XXX-1714429354452-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None"
server: "cloudflare"
cf-ray: "87c2b1077ed6a175-GRU"
alt-svc: "h3=\":443\"; ma=86400"
I, [2024-04-29T17:22:34.385060 #9315]  INFO -- response: {
  "error": {
    "message": "Unknown parameter: 'attachments'.",
    "type": "invalid_request_error",
    "param": "attachments",
    "code": "unknown_parameter"
  }
}

Check the OpenAI-Beta: "assistants=v1" header.

alexrudall commented 2 months ago

@willywg man you're right. Thanks a lot for pointing this out - fix released as 7.0.1

willywg commented 1 month ago

Thank you @alexrudall. I’m sending you a PR #472 regarding this issue. I hope it helps :D

alexrudall commented 2 weeks ago

Thank you @willywg! - released in v7.1