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