Files
owlen/examples/custom_provider.rs
vikingowl 4d7ad2c330 Refactor codebase for consistency and readability
- Standardize array and vector formatting for clarity.
- Adjust spacing and indentation in examples and TUI code.
- Ensure proper newline usage across files (e.g., LICENSE, TOML files, etc.).
- Simplify `.to_string()` and `.ok()` calls for brevity.
2025-10-05 02:31:53 +02:00

46 lines
1.3 KiB
Rust

// This example demonstrates how to implement a custom provider.
use async_trait::async_trait;
use owlen_core::model::Model;
use owlen_core::provider::Provider;
use owlen_core::session::Session;
// Define a struct for your custom provider.
pub struct MyCustomProvider;
// Implement the `Provider` trait for your struct.
#[async_trait]
impl Provider for MyCustomProvider {
fn name(&self) -> &str {
"custom-provider"
}
async fn chat(&self, session: &Session, model: &Model) -> Result<String, anyhow::Error> {
println!(
"Custom provider received chat request for model: {}",
model.name
);
// In a real implementation, you would send the session data to an API.
let message_count = session.get_messages().len();
Ok(format!(
"This is a custom response. You have {} messages in your session.",
message_count
))
}
}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let provider = MyCustomProvider;
let model = Model::new("custom-model");
let mut session = Session::new("custom-session");
session.add_message("user", "Hello, custom provider!");
let response = provider.chat(&session, &model).await?;
println!("Provider response: {}", response);
Ok(())
}