Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/openai/http.rb
Original file line number Diff line number Diff line change
@@ -86,13 +86,24 @@ def conn(multipart: false)

def uri(path:)
if azure?
base = File.join(@uri_base, path)
"#{base}?api-version=#{@api_version}"
azure_uri(path)
else
File.join(@uri_base, @api_version, path)
end
end

def azure_uri(path)
base = File.join(@uri_base, path)

# Remove the deployment to support assistants for azure
if path.include?("/assistants") || path.include?("/threads")
base = base.gsub(%r{/deployments/.+/},
"/")
end

"#{base}?api-version=#{@api_version}"
end

def multipart_parameters(parameters)
parameters&.transform_values do |value|
next value unless value.respond_to?(:close) # File or IO object.
6 changes: 6 additions & 0 deletions spec/openai/client/http_spec.rb
Original file line number Diff line number Diff line change
@@ -239,6 +239,12 @@
let(:uri_base) { "https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo" }
it { expect(uri).to eq("https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo/chat?api-version=v1") }
end

context "with assistants" do
let(:path) { "/assistants" }
let(:uri_base) { "https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo" }
it { expect(uri).to eq("https://custom-domain.openai.azure.com/openai/assistants?api-version=v1") }
end
end
end