fed8b2eed7
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Backend release / release (push) Has been cancelled
Bandit Security Scan / bandit_scan (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / manifest (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / manifest (push) Has been cancelled
Python linting / ruff (push) Has been cancelled
Run python tests with pytest / Run tests and count coverage (3.12) (push) Has been cancelled
React Widget Build / build (push) Has been cancelled
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
from application.llm.openai import OpenAILLM
|
|
from application.llm.providers.base import Provider
|
|
|
|
|
|
class OpenAIProvider(Provider):
|
|
name = "openai"
|
|
llm_class = OpenAILLM
|
|
|
|
def get_api_key(self, settings) -> Optional[str]:
|
|
if settings.OPENAI_API_KEY:
|
|
return settings.OPENAI_API_KEY
|
|
if settings.LLM_PROVIDER == self.name and settings.API_KEY:
|
|
return settings.API_KEY
|
|
return None
|
|
|
|
def is_enabled(self, settings) -> bool:
|
|
# When the deployment is pointed at a custom OpenAI-compatible
|
|
# endpoint (Ollama, LM Studio, ...), the cloud-OpenAI catalog is
|
|
# suppressed but ``is_enabled`` stays True — necessary so the
|
|
# filter below still gets to drop the catalog (rather than the
|
|
# registry skipping the provider entirely and missing the rule).
|
|
if settings.OPENAI_BASE_URL:
|
|
return True
|
|
return bool(self.get_api_key(settings))
|
|
|
|
def filter_yaml_models(self, settings, models):
|
|
# Legacy local-endpoint mode hides the cloud catalog. The
|
|
# corresponding dynamic models live in OpenAICompatibleProvider.
|
|
if settings.OPENAI_BASE_URL:
|
|
return []
|
|
if not settings.OPENAI_API_KEY:
|
|
return []
|
|
return models
|