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
228def _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
261def _call_llm_via_azure(

Callers 1

call_llmFunction · 0.85

Calls 2

_get_litellm_model_nameFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected