From dbc90bd75515c01142e4bcb935792216fff8c4ee Mon Sep 17 00:00:00 2001 From: Huangzisu <1003101889@qq.com> Date: Sat, 30 May 2026 06:58:05 +0000 Subject: [PATCH] fix(auth): let env vars override yaml for openai_compatible mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The yaml default `azure_openai_auth_mode: azure_cli` was silently overwriting `AZURE_OPENAI_AUTH_MODE` exported by the user, because `configure_clients()` treats any non-empty config value as an explicit override. Switching the three auth_mode defaults (shared / optimizer / target) to "" lets `_clean()` drop them and restores the intended fallback chain: yaml → env var → module default ("azure_cli"). Also update README and .env.example to document the openai_compatible mode introduced in d5c5b61, and remove the misleading `OPENAI_API_KEY` snippet — SkillOpt reuses the `AZURE_OPENAI_*` env vars in this mode. --- .env.example | 8 ++++++-- README.md | 15 ++++++++++++--- configs/_base_/default.yaml | 6 +++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index faf9c85..f424cda 100644 --- a/.env.example +++ b/.env.example @@ -14,8 +14,12 @@ export AZURE_OPENAI_API_KEY= # export AZURE_OPENAI_AUTH_MODE=managed_identity # export AZURE_OPENAI_MANAGED_IDENTITY_CLIENT_ID=your-client-id -# ── OpenAI (alternative to Azure) ──────────────────────────────────── -# export OPENAI_API_KEY=sk-... +# ── OpenAI-compatible endpoints ────────────────────────────────────── +# Set AUTH_MODE to openai_compatible and reuse AZURE_OPENAI_ENDPOINT / _API_KEY. +# The plain OpenAI client is used; no Azure auth, no api-version header. +# export AZURE_OPENAI_ENDPOINT=https://api.openai.com/v1 +# export AZURE_OPENAI_API_KEY=sk-... +# export AZURE_OPENAI_AUTH_MODE=openai_compatible # ── Anthropic / Claude (for claude_chat backend) ───────────────────── # export ANTHROPIC_API_KEY=sk-ant-... diff --git a/README.md b/README.md index 6342cff..f81c37b 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,22 @@ export AZURE_OPENAI_API_KEY="your-key" export AZURE_OPENAI_AUTH_MODE="azure_cli" ``` -> **Note:** `AZURE_OPENAI_ENDPOINT` is always required. Without it, all LLM calls will fail. +> **Note:** `AZURE_OPENAI_ENDPOINT` is required for all three modes (`api_key`, `azure_cli`, +> `openai_compatible`). Without it, all LLM calls will fail. -**OpenAI** directly: +**OpenAI-compatible endpoints**: ```bash -export OPENAI_API_KEY="sk-..." +export AZURE_OPENAI_ENDPOINT="https://api.openai.com/v1" +export AZURE_OPENAI_API_KEY="sk-..." +export AZURE_OPENAI_AUTH_MODE="openai_compatible" ``` +This routes all calls through the plain OpenAI Python client (no Azure auth, no `api-version` +header). + +> **Note:** SkillOpt reuses the `AZURE_OPENAI_*` env var names even in this mode — there is no +> separate `OPENAI_API_KEY` knob. + **Anthropic Claude**: ```bash export ANTHROPIC_API_KEY="sk-ant-..." diff --git a/configs/_base_/default.yaml b/configs/_base_/default.yaml index 9ec2270..ed8f61d 100644 --- a/configs/_base_/default.yaml +++ b/configs/_base_/default.yaml @@ -28,19 +28,19 @@ model: azure_openai_endpoint: "" # e.g. "https://your-resource.openai.azure.com/" azure_openai_api_version: "2024-12-01-preview" azure_openai_api_key: "" # Fill locally if you do not export AZURE_OPENAI_API_KEY - azure_openai_auth_mode: azure_cli + azure_openai_auth_mode: "" # empty → fall back to AZURE_OPENAI_AUTH_MODE env (default "azure_cli") azure_openai_ad_scope: "https://cognitiveservices.azure.com/.default" azure_openai_managed_identity_client_id: "" optimizer_azure_openai_endpoint: "" # e.g. "https://your-resource.openai.azure.com/" optimizer_azure_openai_api_version: "2024-12-01-preview" optimizer_azure_openai_api_key: "" - optimizer_azure_openai_auth_mode: azure_cli + optimizer_azure_openai_auth_mode: "" # empty → fall back to OPTIMIZER_AZURE_OPENAI_AUTH_MODE env, then shared optimizer_azure_openai_ad_scope: "https://cognitiveservices.azure.com/.default" optimizer_azure_openai_managed_identity_client_id: "" target_azure_openai_endpoint: "" # e.g. "https://your-resource.openai.azure.com/" target_azure_openai_api_version: "2024-12-01-preview" target_azure_openai_api_key: "" - target_azure_openai_auth_mode: azure_cli + target_azure_openai_auth_mode: "" # empty → fall back to TARGET_AZURE_OPENAI_AUTH_MODE env, then shared target_azure_openai_ad_scope: "https://cognitiveservices.azure.com/.default" target_azure_openai_managed_identity_client_id: ""