Call LLM via litellm for Bedrock/Anthropic providers. litellm handles the provider-specific API translation automatically.
(
prompt: str,
config: Config,
model: str,
temperature: float = 0.0
)
| 226 | |
| 227 | # litellm exposes an OpenAI-compatible Router we can use, |
| 228 | # but the simplest path is to use litellm.completion() directly. |
| 229 | # For pydantic-ai integration, we create a proxy client. |
| 230 | return OpenAI( |
| 231 | api_key=config.llm_api_key or "not-needed-for-bedrock", |
| 232 | base_url=config.llm_base_url or "https://api.openai.com/v1", |
| 233 | ) |
| 234 | |
| 235 | |
| 236 | def create_main_model(config: Config) -> CachingOpenAIModel: |
| 237 | """Create the main LLM model from configuration.""" |
| 238 | return CachingOpenAIModel( |
| 239 | model_name=config.main_model, |
| 240 | prompt_caching=config.prompt_caching, |
| 241 | cache_registry_key=config.llm_base_url or "", |
| 242 | provider=OpenAIProvider(base_url=config.llm_base_url, api_key=config.llm_api_key), |
| 243 | settings=_build_model_settings(config, config.main_model), |
| 244 | ) |
| 245 | |
| 246 | |
| 247 | def create_fallback_model(config: Config) -> CachingOpenAIModel: |
| 248 | """Create the fallback LLM model from configuration.""" |
| 249 | return CachingOpenAIModel( |
| 250 | model_name=config.fallback_model, |
| 251 | prompt_caching=config.prompt_caching, |
| 252 | cache_registry_key=config.llm_base_url or "", |
| 253 | provider=OpenAIProvider(base_url=config.llm_base_url, api_key=config.llm_api_key), |
| 254 | settings=_build_model_settings(config, config.fallback_model), |
| 255 | ) |
| 256 | |
| 257 | |
| 258 | def create_fallback_models(config: Config) -> FallbackModel: |
| 259 | """Create fallback models chain from configuration.""" |
| 260 | main = create_main_model(config) |
| 261 | fallback = create_fallback_model(config) |
no test coverage detected