Skip to content

Commit 516b2c3

Browse files
committed
Add tests for uri and headers
1 parent a012696 commit 516b2c3

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

spec/openai/client/http_spec.rb

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

0 commit comments

Comments
 (0)