From e70f67fcdb6d51223de212b507f092c78f0a2ed7 Mon Sep 17 00:00:00 2001 From: David Cristofaro Date: Fri, 28 Apr 2023 22:21:41 +1000 Subject: [PATCH] Misc tweaks --- .dockerignore | 3 ++- .gitignore | 2 +- src/web/generate.rs | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 04fea2d..66d513b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ * !/src/ -!/Cargo* +!/Cargo.lock +!/Cargo.toml diff --git a/.gitignore b/.gitignore index ea8c4bf..b83d222 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/target +/target/ diff --git a/src/web/generate.rs b/src/web/generate.rs index cb205d7..7b6eaed 100644 --- a/src/web/generate.rs +++ b/src/web/generate.rs @@ -1,4 +1,4 @@ -use std::{env, future}; +use std::future; use axum::{body::StreamBody, http::Uri, response::IntoResponse}; use eventsource_stream::Eventsource; @@ -6,7 +6,10 @@ use futures::{StreamExt, TryStreamExt}; use reqwest::{header, Client}; use serde::{Deserialize, Serialize}; -use crate::error::{Error, Result}; +use crate::{ + env, + error::{Error, Result}, +}; #[derive(Debug, Serialize)] struct ChatCompletionsBody { @@ -70,7 +73,7 @@ Start the reponse with the following exact characters: "authorization", &format!( "Bearer {}", - env::var("OPENAI_API_KEY").map_err(|_| Error::EnvironmentError)? + env::openai_api_key().ok_or(Error::EnvironmentError)? ), ) .body(serde_json::to_string(&body).map_err(|_| Error::SerializationError)?)