Skip to main content

wae_ai/capabilities/
chat.rs

1use crate::{AiConfig, AiResult};
2
3use serde::{Deserialize, Serialize};
4
5/// 聊天消息
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ChatMessage {
8    /// 角色
9    pub role: String,
10    /// 内容
11    pub content: String,
12}
13
14/// 聊天参数
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct ChatParams {
17    /// 消息列表
18    pub messages: Vec<ChatMessage>,
19    /// 温度参数
20    pub temperature: Option<f32>,
21    /// 最大 token 数
22    pub max_tokens: Option<u32>,
23}
24
25/// 聊天能力 trait
26pub trait ChatCapability: Send + Sync {
27    /// 执行聊天
28    #[allow(async_fn_in_trait)]
29    async fn chat(&self, params: &ChatParams, config: &AiConfig) -> AiResult<String>;
30}