Add default authorization header for gitea api (remove query string)

Add review cost
This commit is contained in:
2026-06-05 18:39:38 +00:00
parent cd5c5b9478
commit 01e13f0081
4 changed files with 53 additions and 38 deletions
+14 -9
View File
@@ -2,6 +2,11 @@ use std::time::Duration;
use openrouter_rs::{Message, api::chat::ChatCompletionRequest};
pub struct ChatResult {
pub message: String,
pub cost: Option<f64>,
}
pub struct OpenRouterClient {
client: openrouter_rs::OpenRouterClient,
model: String,
@@ -22,21 +27,21 @@ impl OpenRouterClient {
})
}
pub async fn chat(&self, msg: &str) -> anyhow::Result<String> {
pub async fn chat(&self, msg: &str) -> anyhow::Result<ChatResult> {
let request = ChatCompletionRequest::builder()
.model(&self.model)
.enable_reasoning()
.messages(vec![Message::new(
openrouter_rs::types::Role::Developer,
msg,
)])
.messages(vec![Message::new(openrouter_rs::types::Role::User, msg)])
.build()?;
let response = self.client.chat().create(&request).await?;
response.choices[0]
.content()
.map(|msg| String::from(msg))
.ok_or(anyhow::anyhow!("No content"))
Ok(ChatResult {
message: response.choices[0]
.content()
.map(|msg| String::from(msg))
.ok_or(anyhow::anyhow!("No content"))?,
cost: response.usage.and_then(|u| u.cost),
})
}
}