MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / _call_llm_via_litellm

Function _call_llm_via_litellm

codewiki/src/be/llm_services.py:228–258  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

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
236def 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
247def 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
258def 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)

Callers 1

call_llmFunction · 0.85

Calls 2

_get_litellm_model_nameFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected