Skip to content

Commit 2ed92ff

Browse files
committed
Strip out duplicate api_versions in uri
1 parent 3c8eaaa commit 2ed92ff

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/openai/http.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def uri(path:)
8888
if azure?
8989
base = File.join(@uri_base, path)
9090
"#{base}?api-version=#{@api_version}"
91+
elsif @uri_base.include?(@api_version)
92+
File.join(@uri_base, path)
9193
else
9294
File.join(@uri_base, @api_version, path)
9395
end

spec/openai/client/http_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@
204204

205205
it { expect(uri).to eq("https://api.openai.com/v1/chat") }
206206

207+
context "uri_base with version included" do
208+
before do
209+
OpenAI.configuration.uri_base = "https://api.openai.com/v1/"
210+
end
211+
212+
after do
213+
OpenAI.configuration.uri_base = "https://api.openai.com/"
214+
end
215+
216+
it { expect(uri).to eq("https://api.openai.com/v1/chat") }
217+
end
218+
207219
context "uri_base without trailing slash" do
208220
before do
209221
OpenAI.configuration.uri_base = "https://api.openai.com"

0 commit comments

Comments
 (0)