pub mod agent;
pub mod handler;
pub use agent::{AIAgent, AgentConfig, AgentCapability};
pub use handler::{MessageHandler, HandlerContext};
use crate::{Error, Result};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AIProvider {
Claude,
OpenAI,
Local,
Custom,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModelConfig {
pub provider: AIProvider,
pub model: String,
pub endpoint: Option<String>,
#[serde(skip_serializing)]
pub api_key: Option<String>,
pub temperature: f32,
pub max_tokens: usize,
pub system_prompt: Option<String>,
}
impl Default for ModelConfig {
fn default() -> Self {
Self {
provider: AIProvider::Claude,
model: "claude-3-sonnet-20240229".to_string(),
endpoint: None,
api_key: None,
temperature: 0.7,
max_tokens: 1024,
system_prompt: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AIMessage {
pub role: String,
pub content: String,
}
impl AIMessage {
pub fn system(content: impl Into<String>) -> Self {
Self {
role: "system".to_string(),
content: content.into(),
}
}
pub fn user(content: impl Into<String>) -> Self {
Self {
role: "user".to_string(),
content: content.into(),
}
}
pub fn assistant(content: impl Into<String>) -> Self {
Self {
role: "assistant".to_string(),
content: content.into(),
}
}
}
#[derive(Debug, Clone)]
pub struct CompletionRequest {
pub messages: Vec<AIMessage>,
pub config: ModelConfig,
}
#[derive(Debug, Clone)]
pub struct CompletionResponse {
pub content: String,
pub tokens_used: usize,
pub finish_reason: String,
}
#[async_trait::async_trait]
pub trait AIProviderTrait: Send + Sync {
async fn complete(&self, request: CompletionRequest) -> Result<CompletionResponse>;
async fn stream_complete(
&self,
request: CompletionRequest,
callback: Box<dyn Fn(&str) + Send>,
) -> Result<CompletionResponse>;
}