Skip to content

Commit b1ea011

Browse files
authored
Merge pull request #3 from Unsupervisedcom/support-azure-openai-assistants
Support azure openai assistants
2 parents 6d8cb30 + 4da745f commit b1ea011

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/openai/http.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,26 @@ def conn(multipart: false)
8686

8787
def uri(path:)
8888
if azure?
89-
base = File.join(@uri_base, path)
90-
"#{base}?api-version=#{@api_version}"
89+
azure_uri(path)
9190
elsif @uri_base.include?(@api_version)
9291
File.join(@uri_base, path)
9392
else
9493
File.join(@uri_base, @api_version, path)
9594
end
9695
end
9796

97+
def azure_uri(path)
98+
base = File.join(@uri_base, path)
99+
100+
# Remove the deployment to support assistants for azure
101+
if path.include?("/assistants") || path.include?("/threads")
102+
base = base.gsub(%r{/deployments/[^/]+/},
103+
"/")
104+
end
105+
106+
"#{base}?api-version=#{@api_version}"
107+
end
108+
98109
def multipart_parameters(parameters)
99110
parameters&.transform_values do |value|
100111
next value unless value.respond_to?(:close) # File or IO object.

spec/openai/client/http_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@
301301
let(:uri_base) { "https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo" }
302302
it { expect(uri).to eq("https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo/chat?api-version=v1") }
303303
end
304+
305+
context "with assistants" do
306+
let(:path) { "/assistants/test_assistant_id" }
307+
let(:uri_base) { "https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo" }
308+
it { expect(uri).to eq("https://custom-domain.openai.azure.com/openai/assistants/test_assistant_id?api-version=v1") }
309+
end
304310
end
305311
end
306312

0 commit comments

Comments
 (0)