alith_client/
lib.rs

1pub mod backend_builders;
2pub mod basic_completion;
3pub mod components;
4pub mod embeddings;
5pub mod prelude;
6pub mod primitives;
7pub mod workflows;
8
9#[allow(unused_imports)]
10pub(crate) use alith_devices::logging::{i_ln, i_lns, i_nln, i_nlns};
11#[allow(unused_imports)]
12pub(crate) use anyhow::{Error, Result, anyhow, bail};
13pub use prelude::*;
14#[allow(unused_imports)]
15pub(crate) use tracing::{Level, debug, error, info, span, trace, warn};
16
17pub use alith_interface as interface;
18pub use alith_interface::llms::LLMBackend;
19
20use backend_builders::anthropic::AnthropicBackendBuilder;
21use backend_builders::openai::OpenAIBackendBuilder;
22use backend_builders::perplexity::PerplexityBackendBuilder;
23use basic_completion::BasicCompletion;
24use embeddings::Embeddings;
25use std::sync::Arc;
26use workflows::basic_primitive::BasicPrimitiveWorkflowBuilder;
27use workflows::nlp::Nlp;
28use workflows::reason::ReasonWorkflowBuilder;
29
30#[derive(Clone)]
31pub struct LLMClient {
32    pub backend: Arc<LLMBackend>,
33}
34
35impl LLMClient {
36    #[inline]
37    pub fn new(backend: Arc<LLMBackend>) -> Self {
38        Self { backend }
39    }
40
41    /// Creates a new instance of the [`OpenAIBackendBuilder`]. This builder that allows you to specify the model and other parameters. It is converted to an `LLMClient` instance using the `init` method.
42    #[inline]
43    pub fn openai() -> OpenAIBackendBuilder {
44        OpenAIBackendBuilder::default()
45    }
46
47    /// Creates a new instance of the [`AnthropicBackendBuilder`]. This builder that allows you to specify the model and other parameters. It is converted to an `LLMClient` instance using the `init` method.
48    #[inline]
49    pub fn anthropic() -> AnthropicBackendBuilder {
50        AnthropicBackendBuilder::default()
51    }
52
53    /// Creates a new instance of the [`PerplexityBackendBuilder`]. This builder that allows you to specify the model and other parameters. It is converted to an `LLMClient` instance using the `init` method.
54    #[inline]
55    pub fn perplexity() -> PerplexityBackendBuilder {
56        PerplexityBackendBuilder::default()
57    }
58
59    #[inline]
60    pub fn embeddings(&self) -> Embeddings {
61        Embeddings::new(self.backend.clone())
62    }
63
64    #[inline]
65    pub fn basic_completion(&self) -> BasicCompletion {
66        BasicCompletion::new(self.backend.clone())
67    }
68
69    #[inline]
70    pub fn basic_primitive(&self) -> BasicPrimitiveWorkflowBuilder {
71        BasicPrimitiveWorkflowBuilder::new(self.backend.clone())
72    }
73
74    #[inline]
75    pub fn reason(&self) -> ReasonWorkflowBuilder {
76        ReasonWorkflowBuilder::new(self.backend.clone())
77    }
78
79    #[inline]
80    pub fn nlp(&self) -> Nlp {
81        Nlp::new(self.backend.clone())
82    }
83
84    #[inline]
85    pub fn shutdown(&self) {
86        self.backend.shutdown();
87    }
88
89    #[inline]
90    pub fn completion_request(&self) -> CompletionRequest {
91        CompletionRequest::new(self.backend.clone())
92    }
93
94    #[inline]
95    pub fn embeddings_request(&self) -> EmbeddingsRequest {
96        EmbeddingsRequest::new(self.backend.clone())
97    }
98}