Skip to content

Commit

Permalink
fix: OpenAI authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Nov 11, 2023
1 parent 48c78b5 commit a71c3aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/infrastructure/backends/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl Backend for OpenAI {
async fn list_models(&self) -> Result<Vec<String>> {
let res = reqwest::Client::new()
.get(format!("{url}/v1/models", url = self.url))
.header("Authorization", format!("Bearer {}", self.token))
.send()
.await?
.json::<ModelListResponse>()
Expand Down Expand Up @@ -154,6 +155,7 @@ impl Backend for OpenAI {

let res = reqwest::Client::new()
.post(format!("{url}/v1/chat/completions", url = self.url))
.header("Authorization", format!("Bearer {}", self.token))
.json(&req)
.send()
.await?;
Expand Down
4 changes: 3 additions & 1 deletion src/infrastructure/backends/openai_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ async fn it_lists_models() -> Result<()> {
let mut server = mockito::Server::new();
let mock = server
.mock("GET", "/v1/models")
.match_header("Authorization", "Bearer abc")
.with_status(200)
.with_body(body)
.create();

let backend = OpenAI::with_url(server.url());
let res = backend.list_models().await?;
mock.assert();

assert_eq!(res, vec!["first".to_string(), "second".to_string()]);
mock.assert();

return Ok(());
}
Expand Down Expand Up @@ -129,6 +130,7 @@ async fn it_gets_completions() -> Result<()> {
let mut server = mockito::Server::new();
let mock = server
.mock("POST", "/v1/chat/completions")
.match_header("Authorization", "Bearer abc")
.with_status(200)
.with_body(body)
.create();
Expand Down

0 comments on commit a71c3aa

Please sign in to comment.