use reqwest::Client; use tracing::{debug, instrument, warn, info}; use std::fmt; use serde::{Deserialize, Serialize}; /// #[derive(Debug)] pub struct ApiSessionConfig { // integration config pub target_url : String, pub model_name : String, pub request_timeout : usize, pub client : Client, } impl fmt::Display for ApiSessionConfig { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { let param_name_width = 25; let param_name_val = (self.model_name.as_bytes().iter().count() + 4).max(self.target_url.as_bytes().iter().count() + 4); let param_name_measure = 10; // header writeln!(f, "+{:- anyhow::Result { let config = Self { target_url : std::env::var("ML_TARGET_URL")?, model_name : std::env::var("ML_MODEL_NAME")?, request_timeout : std::env::var("ML_REQUEST_TIMEOUT")?.parse().unwrap_or_else(|_| { warn!("invalid port was given, setting up default one ..."); 15 }), client : Client::new(), }; debug!("{:?}", config); info!("app is configurated. config :\n{}", config); Ok(config) } } #[derive(Debug, Serialize)] pub struct OutputModel { model : String, prompt : String, stream : bool, } impl OutputModel { pub fn build(model_name: &str, prompt: String) -> Self { Self { model : model_name.to_owned(), prompt : prompt, stream : false, } } } #[derive(Debug, Serialize, Deserialize)] pub struct ModelResponse { pub response: String, }