Skip to content

Commit 15e2ceb

Browse files
committed
Add tests for uri and headers
1 parent a012696 commit 15e2ceb

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

spec/openai/client/http_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,58 @@
184184
it { expect(parsed).to eq([{ "prompt" => ":)" }, { "prompt" => ":(" }]) }
185185
end
186186
end
187+
188+
describe ".uri" do
189+
let(:path) { "/chat" }
190+
let(:uri) { OpenAI::Client.send(:uri, path: path) }
191+
192+
it { expect(uri).to eq("https://api.openai.com/v1/chat") }
193+
194+
describe "with Azure" do
195+
before do
196+
OpenAI.configuration.uri_base = "https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo"
197+
OpenAI.configuration.api_type = :azure
198+
end
199+
200+
after do
201+
OpenAI.configuration.uri_base = "https://api.openai.com/"
202+
OpenAI.configuration.api_type = nil
203+
end
204+
205+
let(:path) { "/chat" }
206+
let(:uri) { OpenAI::Client.send(:uri, path: path) }
207+
208+
it { expect(uri).to eq("https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo/chat?api-version=v1") }
209+
end
210+
end
211+
212+
describe ".headers" do
213+
before do
214+
OpenAI.configuration.api_type = :nil
215+
end
216+
217+
let(:headers) { OpenAI::Client.send(:headers) }
218+
219+
it {
220+
expect(headers).to eq({ "Authorization" => "Bearer #{OpenAI.configuration.access_token}",
221+
"Content-Type" => "application/json", "OpenAI-Organization" => nil })
222+
}
223+
224+
describe "with Azure" do
225+
before do
226+
OpenAI.configuration.api_type = :azure
227+
end
228+
229+
after do
230+
OpenAI.configuration.api_type = nil
231+
end
232+
233+
let(:headers) { OpenAI::Client.send(:headers) }
234+
235+
it {
236+
expect(headers).to eq({ "Content-Type" => "application/json",
237+
"api-key" => OpenAI.configuration.access_token })
238+
}
239+
end
240+
end
187241
end

0 commit comments

Comments
 (0)