github / github/copilot-cli

Feature request: opt-in model discovery for BYOK / custom providers

未關閉
#3,795 1 則留言 6 個 reaction 已指派 0 人 在 GitHub 檢視
area:models
主要語言
Shell
星號
11.2k
分支
1.9k
平均合併
14 小時 16 分鐘
30 天內合併 PR
6

描述

**Is your feature request related to a problem? Please describe.**

When using GitHub Copilot CLI in BYOK ("custom provider") mode, the user is required to set `COPILOT_MODEL` (or pass `--model`) to a provider-specific model identifier before launching a session. The CLI does not appear to query the provider for available models, so users must know the exact model string ahead of time and manage it in a separate step (shell aliases, wrapper scripts, provider documentation, etc.). This is particularly inconvenient for OpenAI-compatible endpoints whose `/models` endpoint already exposes the supported model IDs.

For comparison, when running on the default GitHub Copilot path, the CLI lists models from GitHub and lets the user select one interactively. BYOK users currently do not get equivalent convenience.

**Describe the solution you'd like**

When `COPILOT_PROVIDER_BASE_URL` is set and points to an OpenAI-compatible provider (`COPILOT_PROVIDER_TYPE=openai` or unset), the CLI should optionally call `GET /models` and use the returned `data[].id` values to populate the `/model` picker and `--model` completions. For other provider types (`azure`, `anthropic`) this could be supported later where a standard listing API exists.

To keep the behavior safe and backward-compatible, model discovery should be opt-in via an environment variable or command-line flag, e.g.:

```bash
COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1 \
COPILOT_PROVIDER_DISCOVER_MODELS=1 \
copilot
```

or

```bash
COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1 \
copilot --discover-models
```

When discovery is enabled:

1. On startup the CLI calls `GET /models` at the configured provider.
2. If the call succeeds, the returned model IDs populate the `/model` interactive picker and `--model` completions.
3. If the call fails (network error, 403, unsupported provider type, etc.), the CLI falls back to the current behavior: require `COPILOT_MODEL` and display the existing warning about unknown models.
4. Token limits are still resolved as documented: manual env vars take precedence, then the built-in catalog, then safe defaults.

**Describe alternatives you've considered**

- **Wrapper scripts / shell aliases:** This is what many BYOK users do today. It works but duplicates provider-specific knowledge outside the CLI and does not integrate with the `/model` picker.
- **Manual `COPILOT_MODEL` only:** Current behavior; works but is unfriendly for endpoints whose model list changes frequently (e.g., local Ollama, Azure AI Foundry, vLLM).
- **Always discover automatically:** Could break users whose providers reject unauthenticated `/models` calls or return huge lists. Making it opt-in keeps BYOK mode predictable.

**Additional context**

- Version tested: `GitHub Copilot CLI 1.0.62`
- Provider path tested: OpenAI-compatible (`COPILOT_PROVIDER_TYPE=openai`, `COPILOT_PROVIDER_WIRE_API=completions`)
- `copilot help providers` documents `COPILOT_PROVIDER_MODEL_ID` / `COPILOT_PROVIDER_WIRE_MODEL` for matching a well-known model identity to a provider-specific wire name. Model discovery would be a natural complement: the discovered ID can serve as the wire model, while the existing catalog/override mechanism continues to handle token limits and agent behavior.
- The OpenAI `/models` response shape is already widely supported by OpenAI-compatible servers (Ollama, vLLM, Azure AI Foundry `/openai/v1/` deployments, LiteLLM, etc.), so the implementation cost for the `openai` provider type should be low.

**Example workflow this would enable**

```bash
# Ollama local server already exposes /v1/models
export COPILOT_PROVIDER_BASE_URL=http://localhost:11434/v1
export COPILOT_PROVIDER_TYPE=openai
export COPILOT_PROVIDER_DISCOVER_MODELS=1

# User launches copilot and types /model to pick from locally pulled models
copilot
```

```bash
# Non-interactive: choose the provider's first available model automatically
COPILOT_PROVIDER_BASE_URL=https://api.example.com/v1 \
COPILOT_PROVIDER_API_KEY=sk-... \
COPILOT_PROVIDER_DISCOVER_MODELS=1 \
copilot -p "Refactor this file" --model auto --allow-all-tools
```

```bash
# Azure AI Foundry OpenAI-compatible endpoint also exposes /models
export COPILOT_PROVIDER_BASE_URL=https://my-resource.openai.azure.com/openai/v1/
export COPILOT_PROVIDER_API_KEY=...
export COPILOT_PROVIDER_DISCOVER_MODELS=1
export COPILOT_PROVIDER_WIRE_API=responses

copilot
```

Thank you for considering this!

貢獻指南

開啟貢獻指南

研究方向

先追蹤現有的 BYOK provider 設定、/model 選擇器、--model 補全以及未知模型警告路徑。檢查相容於 OpenAI 的 /models 回應和 opt-in 設定將如何連接到這些入口點,然後驗證成功發現後會填入模型選項,而失敗時會保留目前的 fallback 行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
shell
領域
api, cli
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。