Skip to content

Commit

Permalink
perf: remove reqwest client initaliziation
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker authored and skeptrunedev committed Apr 6, 2024
1 parent e6b9f8a commit e636c0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
16 changes: 4 additions & 12 deletions server/src/operators/model_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
handlers::chunk_handler::ScoreChunkDTO,
};
use openai_dive::v1::{
api::Client,
helpers::format_response,
resources::embedding::{EmbeddingInput, EmbeddingOutput, EmbeddingResponse},
};
Expand Down Expand Up @@ -40,7 +39,7 @@ pub async fn create_embeddings(
};
sentry::configure_scope(|scope| scope.set_span(Some(transaction.clone())));

let open_ai_api_key = get_env!("OPENAI_API_KEY", "OPENAI_API_KEY should be set").into();
let open_ai_api_key = get_env!("OPENAI_API_KEY", "OPENAI_API_KEY should be set");
let base_url = dataset_config.EMBEDDING_BASE_URL;

let base_url = if base_url.is_empty() || base_url == "https://api.openai.com/v1" {
Expand All @@ -61,13 +60,6 @@ pub async fn create_embeddings(
base_url
};

let client = Client {
http_client: reqwest::Client::new(),
api_key: open_ai_api_key,
base_url,
organization: None,
};

let mut all_vectors = vec![];
let thirty_message_groups = messages.chunks(30).collect::<Vec<_>>();

Expand Down Expand Up @@ -106,10 +98,10 @@ pub async fn create_embeddings(

let embeddings_resp = ureq::post(&format!(
"{}/embeddings?api-version=2023-05-15",
client.base_url
base_url
))
.set("Authorization", &format!("Bearer {}", client.api_key))
.set("api-key", &client.api_key)
.set("Authorization", &format!("Bearer {}", open_ai_api_key))
.set("api-key", &open_ai_api_key)
.set("Content-Type", "application/json")
.send_json(serde_json::to_value(parameters).unwrap())
.map_err(|e| {
Expand Down
2 changes: 1 addition & 1 deletion server/src/operators/user_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub async fn create_user_query(
.first::<User>(&mut conn)
.await
.optional()
.map_err(|_| ServiceError::InternalServerError("Error loading user".to_string()))?;
.map_err(|err| ServiceError::InternalServerError(format!("Error loading user {:?}", err)))?;

if let Some(old_user) = old_user {
let mut conn = pool.get().await.unwrap();
Expand Down

0 comments on commit e636c0d

Please sign in to comment.