From 84c6a9a664959c73a981d5903cb09992091ee72f Mon Sep 17 00:00:00 2001 From: Carter Johnson Date: Thu, 15 Feb 2024 16:43:11 -0600 Subject: [PATCH 1/6] fix: update uri to omit deployment ids for assistant and thread paths --- lib/openai/http.rb | 12 ++++++++++-- spec/openai/client/http_spec.rb | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 69ac162d..1e1bd155 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -86,13 +86,21 @@ 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 + base = base.gsub(/\/deployments\/.+\//, '/') if (path.include?('/assistants') || path.include?('/threads')) + + "#{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. diff --git a/spec/openai/client/http_spec.rb b/spec/openai/client/http_spec.rb index e52ccd50..940e54cd 100644 --- a/spec/openai/client/http_spec.rb +++ b/spec/openai/client/http_spec.rb @@ -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 From 7124e4633b809b97cba51d014a462219bfa7d41c Mon Sep 17 00:00:00 2001 From: Carter Johnson Date: Thu, 15 Feb 2024 16:47:19 -0600 Subject: [PATCH 2/6] fix: fix method --- lib/openai/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 1e1bd155..496c8395 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -92,7 +92,7 @@ def uri(path:) end end - def azure_uri(path:) + def azure_uri(path) base = File.join(@uri_base, path) # Remove the deployment to support assistants for azure From 015cf1883d8f1085205ed940a46cfe9cbe98c1fe Mon Sep 17 00:00:00 2001 From: Carter Johnson Date: Thu, 15 Feb 2024 17:07:16 -0600 Subject: [PATCH 3/6] fix: lint fix --- lib/openai/http.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 496c8395..a957043c 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -94,10 +94,13 @@ def uri(path:) def azure_uri(path) base = File.join(@uri_base, path) - + # Remove the deployment to support assistants for azure - base = base.gsub(/\/deployments\/.+\//, '/') if (path.include?('/assistants') || path.include?('/threads')) - + if path.include?("/assistants") || path.include?("/threads") + base = base.gsub(%r{/deployments/.+/}, + "/") + end + "#{base}?api-version=#{@api_version}" end From ae088f824aaf19e406d2d6f6b00f079329b03804 Mon Sep 17 00:00:00 2001 From: Carter Johnson Date: Mon, 18 Mar 2024 08:20:59 -0500 Subject: [PATCH 4/6] Update lib/openai/http.rb Co-authored-by: Bryan Morrow --- lib/openai/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index a957043c..4a649a99 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -97,7 +97,7 @@ def azure_uri(path) # Remove the deployment to support assistants for azure if path.include?("/assistants") || path.include?("/threads") - base = base.gsub(%r{/deployments/.+/}, + base = base.gsub(%r{/deployments/[^\/]+/}, "/") end From e6d2dc1310510dfb0463080baf78251ed255b903 Mon Sep 17 00:00:00 2001 From: Carter Johnson Date: Mon, 18 Mar 2024 08:27:30 -0500 Subject: [PATCH 5/6] fix: lint fix & test addition --- lib/openai/http.rb | 2 +- spec/openai/client/http_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 4a649a99..10f7062f 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -97,7 +97,7 @@ def azure_uri(path) # Remove the deployment to support assistants for azure if path.include?("/assistants") || path.include?("/threads") - base = base.gsub(%r{/deployments/[^\/]+/}, + base = base.gsub(%r{/deployments/[^/]+/}, "/") end diff --git a/spec/openai/client/http_spec.rb b/spec/openai/client/http_spec.rb index 940e54cd..f4d23945 100644 --- a/spec/openai/client/http_spec.rb +++ b/spec/openai/client/http_spec.rb @@ -241,9 +241,9 @@ end context "with assistants" do - let(:path) { "/assistants" } + 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?api-version=v1") } + it { expect(uri).to eq("https://custom-domain.openai.azure.com/openai/assistants/test_assistant_id?api-version=v1") } end end end From 4da745ffcef15e4bb35b85649a07f4f7aeeb9a67 Mon Sep 17 00:00:00 2001 From: Carter Johnson Date: Wed, 1 May 2024 09:39:42 -0500 Subject: [PATCH 6/6] fix: Update http.rb --- lib/openai/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 411f6241..4b9ad60b 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -102,7 +102,7 @@ def azure_uri(path) base = base.gsub(%r{/deployments/[^/]+/}, "/") end - + "#{base}?api-version=#{@api_version}" end