Skip to content

Commit

Permalink
cleanup: remove expects for LLM completion calls
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev committed Dec 9, 2024
1 parent be27319 commit 5281e45
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
31 changes: 20 additions & 11 deletions server/src/handlers/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,17 +1003,26 @@ pub async fn get_suggested_queries(
.collect();

while queries.len() < 3 {
query = client
.chat()
.create(parameters.clone())
.await
.expect("No LLM Completion for topic");
queries = match &query
.choices
.first()
.expect("No response for LLM completion")
.message
{
query = match client.chat().create(parameters.clone()).await {
Ok(query) => query,
Err(err) => {
log::error!(
"Error generating suggested queries when queries are less than 3: {}",
err
);
return Err(ServiceError::BadRequest(err.to_string()));
}
};
let first_query = match query.choices.first() {
Some(first_query) => first_query,
None => {
log::error!("Error generating suggested queries when queries are less than 3: No first query in choices");
return Err(ServiceError::BadRequest(
"No first query in choices on call to LLM".to_string(),
));
}
};
queries = match &first_query.message {
ChatMessage::User {
content: ChatMessageContent::Text(content),
..
Expand Down
18 changes: 13 additions & 5 deletions server/src/operators/message_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,19 @@ pub async fn get_rag_chunks_query(
..Default::default()
};

let search_query_from_message_to_query_prompt = client
.chat()
.create(gen_inference_parameters)
.await
.expect("No LLM Completion for chunk search");
let search_query_from_message_to_query_prompt =
match client.chat().create(gen_inference_parameters).await {
Ok(query) => query,
Err(err) => {
log::error!(
"Error getting LLM completion for message to query prompt {:?}",
err
);
return Err(actix_web::error::ErrorInternalServerError(
"Error getting LLM completion for message to query prompt",
));
}
};

query = match &search_query_from_message_to_query_prompt
.choices
Expand Down

0 comments on commit 5281e45

Please sign in to comment.