mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-29 01:03:17 +00:00
* refactor(rust): rename litellm-core to litellm-inference Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(rust): expose inference base API for format crates Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(rust): move shared inference test helpers behind test-support Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use litellm_core_utils::get_llm_provider_logic::{
|
|
CustomLlmProvider, LlmProviders, get_custom_llm_provider,
|
|
};
|
|
|
|
use crate::error::RouteError as Error;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ResolvedProvider<'a> {
|
|
pub model: &'a str,
|
|
pub provider: LlmProviders,
|
|
}
|
|
|
|
pub fn resolve_llm_provider<'a>(
|
|
model: &'a str,
|
|
custom_llm_provider: Option<&'a str>,
|
|
route: &'static str,
|
|
) -> Result<ResolvedProvider<'a>, Error> {
|
|
let CustomLlmProvider {
|
|
model,
|
|
custom_llm_provider,
|
|
} = get_custom_llm_provider(model, custom_llm_provider)
|
|
.or_else(|| {
|
|
custom_llm_provider.map(|provider| CustomLlmProvider {
|
|
model,
|
|
custom_llm_provider: provider,
|
|
})
|
|
})
|
|
.ok_or_else(|| {
|
|
Error::InvalidProvider(format!(
|
|
"unable to resolve custom_llm_provider for {route} request"
|
|
))
|
|
})?;
|
|
let provider = custom_llm_provider
|
|
.parse()
|
|
.map_err(|_| Error::InvalidProvider(custom_llm_provider.to_string()))?;
|
|
Ok(ResolvedProvider { model, provider })
|
|
}
|