llm_worker/llm_client/
client.rs1use std::pin::Pin;
4
5use crate::llm_client::{ClientError, Request, RequestConfig, event::Event};
6use async_trait::async_trait;
7use futures::Stream;
8
9#[derive(Debug, Clone)]
13pub struct ConfigWarning {
14 pub option_name: &'static str,
16 pub message: String,
18}
19
20impl ConfigWarning {
21 pub fn unsupported(option_name: &'static str, provider_name: &str) -> Self {
23 Self {
24 option_name,
25 message: format!(
26 "'{}' is not supported by {} and will be ignored",
27 option_name, provider_name
28 ),
29 }
30 }
31}
32
33impl std::fmt::Display for ConfigWarning {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "{}: {}", self.option_name, self.message)
36 }
37}
38
39#[async_trait]
43pub trait LlmClient: Send + Sync {
44 async fn stream(
53 &self,
54 request: Request,
55 ) -> Result<Pin<Box<dyn Stream<Item = Result<Event, ClientError>> + Send>>, ClientError>;
56
57 fn validate_config(&self, config: &RequestConfig) -> Vec<ConfigWarning> {
65 let _ = config;
67 Vec::new()
68 }
69}
70
71#[async_trait]
75impl LlmClient for Box<dyn LlmClient> {
76 async fn stream(
77 &self,
78 request: Request,
79 ) -> Result<Pin<Box<dyn Stream<Item = Result<Event, ClientError>> + Send>>, ClientError> {
80 (**self).stream(request).await
81 }
82
83 fn validate_config(&self, config: &RequestConfig) -> Vec<ConfigWarning> {
84 (**self).validate_config(config)
85 }
86}