ooodc 73dab09bfe Refactor code for improved readability and consistency
- Adjusted formatting and indentation in various files for better clarity.
- Consolidated multi-line statements into single lines where appropriate.
- Enhanced error handling messages for better debugging.
- Added a new InboundProcessor struct to handle inbound messages more effectively.
- Updated test cases to ensure they align with the new code structure.
2026-04-28 10:33:31 +08:00

56 lines
1.6 KiB
Rust

pub mod anthropic;
pub mod openai;
pub mod traits;
pub use self::anthropic::AnthropicProvider;
pub use self::openai::OpenAIProvider;
use crate::config::LLMProviderConfig;
pub use traits::{
ChatCompletionRequest, ChatCompletionResponse, LLMProvider, Message, Tool, ToolCall,
ToolFunction, Usage,
};
pub fn create_provider(config: LLMProviderConfig) -> Result<Box<dyn LLMProvider>, ProviderError> {
match config.provider_type.as_str() {
"openai" => Ok(Box::new(OpenAIProvider::new(
config.name,
config.api_key,
config.base_url,
config.extra_headers,
config.llm_timeout_secs,
config.model_id,
config.temperature,
config.max_tokens,
config.model_extra,
))),
"anthropic" => Ok(Box::new(AnthropicProvider::new(
config.name,
config.api_key,
config.base_url,
config.extra_headers,
config.llm_timeout_secs,
config.model_id,
config.temperature,
config.max_tokens,
config.model_extra,
))),
_ => Err(ProviderError::UnknownProviderType(config.provider_type)),
}
}
#[derive(Debug)]
pub enum ProviderError {
UnknownProviderType(String),
}
impl std::fmt::Display for ProviderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProviderError::UnknownProviderType(t) => write!(f, "Unknown provider type: {}", t),
}
}
}
impl std::error::Error for ProviderError {}