Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic check for qdrant existence #10

Closed
wants to merge 12 commits into from
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ pub enum ServerError {
ArgumentError(String),
#[error("{0}")]
Operation(String),
#[error("{0}")]
DatabaseError(String),
}
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use llama_core::MetadataBuilder;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, net::SocketAddr, path::PathBuf};
use utils::{is_valid_url, LogLevel};
use utils::{is_valid_url, qdrant_up, LogLevel};

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

Expand Down Expand Up @@ -212,11 +212,19 @@ async fn main() -> Result<(), ServerError> {

// log
{
error!(target: "server_config", "rag_prompt: {}", err_msg);
error!(target: "server_config", "qdrant_url: {}", err_msg);
}

return Err(ServerError::ArgumentError(err_msg));
}
if !qdrant_up(&cli.qdrant_url).await {
let err_msg = format!("[INFO] Qdrant not found at: {}", &cli.qdrant_url);
error!(target: "server_config", "qdrant_url: {}", err_msg);

return Err(ServerError::DatabaseError(err_msg));
}

// log qdrant url
info!(target: "server_config", "qdrant_url: {}", &cli.qdrant_url);

// log qdrant collection name
Expand Down
11 changes: 11 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
use hyper::Client;
use serde::{Deserialize, Serialize};
use url::Url;

pub(crate) fn is_valid_url(url: &str) -> bool {
Url::parse(url).is_ok()
}

//TODO: check json title field to check whether running service is really qdrant
pub(crate) async fn qdrant_up(url: &str) -> bool {
let client = Client::new();

match client.get(url.parse().unwrap()).await {
Ok(res) => res.status().is_success(),
Err(_) => false,
}
}

pub(crate) fn gen_chat_id() -> String {
format!("chatcmpl-{}", uuid::Uuid::new_v4())
}
Expand Down
Loading