Skip to content

Commit

Permalink
Merge pull request #3 from Unsupervisedcom/support-azure-openai-assis…
Browse files Browse the repository at this point in the history
…tants

Support azure openai assistants
  • Loading branch information
CarterBland authored Oct 1, 2024
2 parents 6d8cb30 + 4da745f commit b1ea011
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/openai/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,26 @@ def conn(multipart: false)

def uri(path:)
if azure?
base = File.join(@uri_base, path)
"#{base}?api-version=#{@api_version}"
azure_uri(path)
elsif @uri_base.include?(@api_version)
File.join(@uri_base, 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.
Expand Down
6 changes: 6 additions & 0 deletions spec/openai/client/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,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/test_assistant_id" }
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/test_assistant_id?api-version=v1") }
end
end
end

Expand Down

0 comments on commit b1ea011

Please sign in to comment.