1use crate::error::Result;
10use async_trait::async_trait;
11use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
14#[serde(rename_all = "lowercase")]
15pub enum Role {
16 System,
17 User,
18 Assistant,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct Message {
23 pub role: Role,
24 pub content: String,
25}
26
27impl Message {
28 pub fn system(content: impl Into<String>) -> Self {
29 Self {
30 role: Role::System,
31 content: content.into(),
32 }
33 }
34
35 pub fn user(content: impl Into<String>) -> Self {
36 Self {
37 role: Role::User,
38 content: content.into(),
39 }
40 }
41
42 pub fn assistant(content: impl Into<String>) -> Self {
43 Self {
44 role: Role::Assistant,
45 content: content.into(),
46 }
47 }
48}
49
50#[async_trait]
51pub trait LlmClient: Send + Sync {
52 fn name(&self) -> &str;
56
57 async fn complete(&self, messages: &[Message]) -> Result<Message>;
60}