alith_interface/llms/api/anthropic/
builder.rs

1use super::{AnthropicBackend, AnthropicConfig};
2use crate::llms::{
3    LLMBackend,
4    api::config::{ApiConfig, LLMApiConfigTrait},
5};
6use alith_devices::logging::{LoggingConfig, LoggingConfigTrait};
7use alith_models::api_model::{ApiLLMModel, anthropic::AnthropicModelTrait};
8use std::sync::Arc;
9
10// Everything here can be implemented for any struct.
11pub struct AnthropicBackendBuilder {
12    pub config: AnthropicConfig,
13    pub model: ApiLLMModel,
14}
15
16impl Default for AnthropicBackendBuilder {
17    fn default() -> Self {
18        Self {
19            config: Default::default(),
20            model: ApiLLMModel::claude_3_7_sonnet(),
21        }
22    }
23}
24
25impl AnthropicBackendBuilder {
26    pub fn init(self) -> crate::Result<Arc<LLMBackend>> {
27        Ok(Arc::new(LLMBackend::Anthropic(AnthropicBackend::new(
28            self.config,
29            self.model,
30        )?)))
31    }
32}
33
34impl LLMApiConfigTrait for AnthropicBackendBuilder {
35    fn api_base_config_mut(&mut self) -> &mut ApiConfig {
36        &mut self.config.api_config
37    }
38
39    fn api_config(&self) -> &ApiConfig {
40        &self.config.api_config
41    }
42}
43
44impl AnthropicModelTrait for AnthropicBackendBuilder {
45    fn model(&mut self) -> &mut ApiLLMModel {
46        &mut self.model
47    }
48}
49
50impl LoggingConfigTrait for AnthropicBackendBuilder {
51    fn logging_config_mut(&mut self) -> &mut LoggingConfig {
52        &mut self.config.logging_config
53    }
54}