Add default authorization header for gitea api (remove query string)
Add review cost
This commit is contained in:
+14
-9
@@ -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),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user