MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / build_llm_provider

Function build_llm_provider

paperflow/providers/llm.py:375–401  ·  view source on GitHub ↗

Construct the configured LLM provider, falling back to mock on missing credentials.

(config: Optional[ProviderConfig] = None)

Source from the content-addressed store, hash-verified

373
374
375def build_llm_provider(config: Optional[ProviderConfig] = None) -> LLMProvider:
376 """Construct the configured LLM provider, falling back to mock on missing credentials."""
377
378 cfg = config or load_provider_config()
379
380 if cfg.llm_provider == "openai":
381 api_key = os.environ.get("OPENAI_API_KEY", "")
382 if _is_placeholder(api_key):
383 return MockLLM()
384 base_url = os.environ.get("OPENAI_BASE_URL") or None
385 timeout = float(os.environ.get("OPENAI_API_TIMEOUT", "60") or 60)
386 return OpenAILLM(model=cfg.llm_model, api_key=api_key, base_url=base_url, timeout=timeout)
387
388 if cfg.llm_provider == "anthropic":
389 api_key = os.environ.get("ANTHROPIC_API_KEY", "")
390 if _is_placeholder(api_key):
391 return MockLLM()
392 base_url = os.environ.get("ANTHROPIC_BASE_URL") or None
393 timeout = float(os.environ.get("ANTHROPIC_API_TIMEOUT", "60") or 60)
394 return AnthropicLLM(model=cfg.llm_model, api_key=api_key, base_url=base_url, timeout=timeout)
395
396 if cfg.llm_provider == "ollama":
397 base_url = os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434")
398 timeout = float(os.environ.get("OLLAMA_API_TIMEOUT", "120") or 120)
399 return OllamaLLM(model=cfg.llm_model, base_url=base_url, timeout=timeout)
400
401 return MockLLM(model=cfg.llm_model)
402
403
404__all__ = [

Callers 9

test_providerFunction · 0.90
_notes_llm_sync_reviewFunction · 0.90
_direct_answerFunction · 0.90
_direct_answer_streamFunction · 0.90
answer_questionFunction · 0.90
answer_question_streamFunction · 0.90
demoFunction · 0.85

Calls 7

load_provider_configFunction · 0.85
MockLLMClass · 0.85
OpenAILLMClass · 0.85
AnthropicLLMClass · 0.85
OllamaLLMClass · 0.85
getMethod · 0.80
_is_placeholderFunction · 0.70