1mod error;
2pub mod types;
3mod config;
4mod provider;
5mod router;
6
7pub use error::*;
8pub use types::*;
9pub use config::{Config, ProviderConfig, CallOptions};
10
11use futures_util::stream::BoxStream;
12
13pub struct Client {
14 router: router::Router,
15}
16
17impl Client {
18 pub fn new() -> Self {
19 Self::with_config(Config::default())
20 }
21
22 pub fn with_config(cfg: Config) -> Self {
23 let router = router::Router::new(cfg);
24 Self { router }
25 }
26
27 pub fn from_env() -> Self {
28 Self::with_config(Config::from_env())
29 }
30
31 pub fn from_yaml_file_auto() -> Option<Self> {
33 Config::from_yaml_file_auto().map(Self::with_config)
34 }
35
36 pub fn list_models(&self) -> Vec<String> {
38 self.router.list_models()
39 }
40
41 pub async fn list_models_auto(&self) -> Result<Vec<String>, error::LlmProxyError> {
43 self.router.list_models_auto(&CallOptions::default()).await
44 }
45
46 pub async fn list_models_auto_with(&self, opts: CallOptions) -> Result<Vec<String>, error::LlmProxyError> {
48 self.router.list_models_auto(&opts).await
49 }
50
51 pub async fn chat(&self, req: types::ChatRequest) -> Result<types::ChatResponse, error::LlmProxyError> {
53 self.router.chat(req, &CallOptions::default()).await
54 }
55
56 pub async fn chat_with(
58 &self,
59 req: types::ChatRequest,
60 opts: CallOptions,
61 ) -> Result<types::ChatResponse, error::LlmProxyError> {
62 self.router.chat(req, &opts).await
63 }
64
65 pub async fn chat_stream(
67 &self,
68 req: types::ChatRequest,
69 ) -> Result<BoxStream<'static, Result<String, error::LlmProxyError>>, error::LlmProxyError> {
70 self.router.chat_stream(req, &CallOptions::default()).await
71 }
72
73 pub async fn chat_stream_with(
75 &self,
76 req: types::ChatRequest,
77 opts: CallOptions,
78 ) -> Result<BoxStream<'static, Result<String, error::LlmProxyError>>, error::LlmProxyError> {
79 self.router.chat_stream(req, &opts).await
80 }
81}