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 | |
| 228 | def _call_llm_via_litellm( |
| 229 | prompt: str, |
| 230 | config: Config, |
| 231 | model: str, |
| 232 | temperature: float = 0.0 |
| 233 | ) -> str: |
| 234 | """ |
| 235 | Call LLM via litellm for Bedrock/Anthropic providers. |
| 236 | |
| 237 | litellm handles the provider-specific API translation automatically. |
| 238 | """ |
| 239 | import litellm |
| 240 | import os |
| 241 | |
| 242 | litellm_model = _get_litellm_model_name(model, config.provider) |
| 243 | |
| 244 | if config.provider == "bedrock": |
| 245 | os.environ.setdefault("AWS_DEFAULT_REGION", config.aws_region) |
| 246 | os.environ.setdefault("AWS_REGION_NAME", config.aws_region) |
| 247 | logger.debug("Calling Bedrock model %s in region %s", litellm_model, config.aws_region) |
| 248 | elif config.provider == "anthropic": |
| 249 | logger.debug("Calling Anthropic model %s via litellm", litellm_model) |
| 250 | |
| 251 | response = litellm.completion( |
| 252 | model=litellm_model, |
| 253 | messages=[{"role": "user", "content": prompt}], |
| 254 | temperature=temperature, |
| 255 | max_tokens=config.max_tokens, |
| 256 | api_key=config.llm_api_key if config.provider != "bedrock" else None, |
| 257 | ) |
| 258 | return response.choices[0].message.content |
| 259 | |
| 260 | |
| 261 | def _call_llm_via_azure( |
no test coverage detected