use reqwest::Client; use serde::Serialize; use serde_json::{json, Value}; use crate::{ http_error::HttpError, DEEPINFRA_TOKEN }; #[derive(Serialize)] pub struct PromptMessage { pub role: PromptRole, pub content: String } #[derive(Serialize)] #[serde(rename_all = "lowercase")] pub enum PromptRole { User, System, Assistant } pub struct PromptResponse { pub message: String, pub input_tokens: i32, pub output_tokens: i32 } pub async fn send_message(prompt: Vec) -> Result { let client = Client::new(); let key = DEEPINFRA_TOKEN.get().unwrap(); let body = json!({ "model": "Qwen/Qwen3-32B", "messages": prompt, "reasoning_effort": "none" }); let response = client .post("https://api.deepinfra.com/v1/chat/completions") .header("Authorization", format!("Bearer {}", key)) .header("Content-Type", "application/json") .json(&body) .send() .await .map_err(|e| HttpError::InternalError(e.to_string()))?; let data: Value = response .json() .await .map_err(|e| HttpError::InternalError(e.to_string()))?; Ok(PromptResponse { message: (&data["choices"][0]["message"]["content"]).to_string(), input_tokens: data["usage"]["prompt_tokens"].as_i64().unwrap_or(0) as i32, output_tokens: data["usage"]["completion_tokens"].as_i64().unwrap_or(0) as i32 }) }