From 660d7d436f246f334e90e2cfe320bd197d06ff02 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Wed, 1 Oct 2025 12:53:57 -0300 Subject: [PATCH] Do nothing --- src/services/llm_generic.rs | 88 +++++++++++++++++++++++++++---------- src/services/state.rs | 10 +++-- 2 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/services/llm_generic.rs b/src/services/llm_generic.rs index 5859eed..cc1ce7d 100644 --- a/src/services/llm_generic.rs +++ b/src/services/llm_generic.rs @@ -36,11 +36,12 @@ struct Choice { finish_reason: String, } -fn _clean_request_body(body: &str) -> String { +fn clean_request_body(body: &str) -> String { // Remove problematic parameters that might not be supported by all providers let re = Regex::new(r#","?\s*"(max_completion_tokens|parallel_tool_calls|top_p|frequency_penalty|presence_penalty)"\s*:\s*[^,}]*"#).unwrap(); re.replace_all(body, "").to_string() } + #[post("/v1/chat/completions")] pub async fn generic_chat_completions(body: web::Bytes, _req: HttpRequest) -> Result { // Log raw POST data @@ -130,13 +131,34 @@ pub async fn generic_chat_completions(body: web::Bytes, _req: HttpRequest) -> Re /// Converts provider response to OpenAI-compatible format fn convert_to_openai_format(provider_response: &str) -> Result> { + #[derive(serde::Deserialize)] + struct ProviderChoice { + message: ProviderMessage, + #[serde(default)] + finish_reason: Option, + } + + #[derive(serde::Deserialize)] + struct ProviderMessage { + role: Option, + content: String, + } + #[derive(serde::Deserialize)] struct ProviderResponse { - text: String, - #[serde(default)] - generated_tokens: Option, - #[serde(default)] - input_tokens: Option, + id: Option, + object: Option, + created: Option, + model: Option, + choices: Vec, + usage: Option, + } + + #[derive(serde::Deserialize, Default)] + struct ProviderUsage { + prompt_tokens: Option, + completion_tokens: Option, + total_tokens: Option, } #[derive(serde::Serialize)] @@ -172,28 +194,46 @@ fn convert_to_openai_format(provider_response: &str) -> Result Result, pub config: Option, - pub db: Option, - pub db_custom: Option, + pub db: Option, + pub db_custom: Option, pub browser_pool: Arc, } - +pub struct _BotState { + pub language: String, + pub work_folder: String, +}