Support OpenAI-compatible endpoints via OPENAI_BASE_URL - #16
Support OpenAI-compatible endpoints via OPENAI_BASE_URL#16abliteration-ai wants to merge 1 commit into
Conversation
get_openai_client() and get_openai_config() now read the optional OPENAI_BASE_URL environment variable and pass it to the OpenAI SDK as base_url, so detectors can be pointed at any OpenAI-compatible API. When unset, behavior is unchanged (default api.openai.com endpoint). Adds unit tests for both helpers and documents the option in the Detection README with a provider example.
|
Thanks for the PR, and especially for the tests — the coverage added in We're going to close this one, for two reasons. 1. The behavior already works without a code change. The OpenAI Python SDK reads >>> os.environ["OPENAI_BASE_URL"] = "https://example.test/v1"
>>> OpenAI(api_key="sk-test").base_url # no base_url argument passed
https://example.test/v1/So setting the env var already points the triage LLM at any OpenAI-compatible endpoint on 2. The README section. We'd prefer to keep third-party endpoint documentation vendor-neutral rather than build the example around one provider's URL, key name, and model. Separately, we'd rather not recommend running triage on an uncensored model: triage is the high-recall gate in front of the reasoning agent, and the paper's Table 2 numbers assume We'll document the SDK's existing Thanks again for taking the time to look at the project. |
What type of PR is this? (check all applicable)
Related issue: N/A
What changed?
Detection/openai_config.py— the single place where OpenAI clients are constructed — now reads the optionalOPENAI_BASE_URLenvironment variable:get_openai_client()passes it to the SDK asbase_urlwhen set, so every consumer (create_chat_completion,create_reasoning_completion, the ADR baseline agent) can be pointed at any OpenAI-compatible API.get_openai_config()includes abase_urlkey when the variable is set.OPENAI_BASE_URLis unset, behavior is byte-for-byte identical to before (defaultapi.openai.comendpoint).Also adds unit tests for both helpers (
Detection/tests/test_openai_config.py) and a short README section documenting the option with a provider example (Abliteration.ai).Why?
The triage model is configurable in
config_detector.yaml, but the client was hardcoded to the hosted OpenAI API. Teams running OpenAI-compatible gateways or alternate providers (self-hosted vLLM, LiteLLM proxies, etc.) had no way to route detector traffic there.OPENAI_BASE_URLfollows the OpenAI SDK's own convention, so it's the least surprising knob.How did you test it?
uv run pytest tests/test_openai_config.py— 8 passed (4 existing + 4 new covering default endpoint, custom base URL, and the config dict with/withoutOPENAI_BASE_URL).black --checkclean on the touched test file;openai_config.pykeeps the file's existing style.Potential risks
None expected: the new code path only activates when
OPENAI_BASE_URLis set; existing deployments without it are unaffected. The Anthropic/Claude path is untouched.