summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-19 21:28:11 +0300
committerPaul Buetow <paul@buetow.org>2025-08-19 21:28:11 +0300
commita58afd061db45678fcf299c3d42f80656ce7e225 (patch)
tree8f0d32d2876952ec1f767443e020dd80a0acb4b8
parentadd957285a5ed6bafbfe2ec5b88060fc01ed7082 (diff)
llm/copilot: add required headers and update default model\n\n- Send X-GitHub-Api-Version and User-Agent headers for Copilot requests\n- Default Copilot model to gpt-4o-mini (avoid non-existent 'codex'/'gpt-4.1')\n- README and config.json.example: update Copilot defaults and guidance\n\nNote: Copilot provider expects Copilot-issued auth; for public access use GitHub Models via OpenAI-compatible endpoint.
-rw-r--r--README.md4
-rw-r--r--config.json.example2
-rw-r--r--internal/llm/copilot.go9
3 files changed, 11 insertions, 4 deletions
diff --git a/README.md b/README.md
index 2758536..e9c53c5 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ Hexai exposes a simple LLM provider interface. It supports OpenAI, GitHub Copilo
"trigger_characters": [".", ":", "/", "_", ";", "?"],
"coding_temperature": 0.2,
"provider": "ollama",
- "copilot_model": "gpt-4.1",
+ "copilot_model": "gpt-4o-mini",
"copilot_base_url": "https://api.githubcopilot.com",
"copilot_temperature": 0.2,
"openai_model": "gpt-4.1",
@@ -64,7 +64,7 @@ Ensure `OPENAI_API_KEY` or `COPILOT_API_KEY` is set in your environment accordin
- Required: `COPILOT_API_KEY` — provided via environment variable only.
- In config file:
- - `copilot_model` — model name (default: `gpt-4.1`).
+ - `copilot_model` — model name (default: `gpt-4o-mini`).
- `copilot_base_url` — API base (default: `https://api.githubcopilot.com`).
- `copilot_temperature` — default temperature (coding-friendly default `0.2`).
diff --git a/config.json.example b/config.json.example
index b8c729b..ce091d5 100644
--- a/config.json.example
+++ b/config.json.example
@@ -18,7 +18,7 @@
"ollama_base_url": "http://localhost:11434",
"ollama_temperature": 0.2,
- "copilot_model": "gpt-4.1",
+ "copilot_model": "gpt-4o-mini",
"copilot_base_url": "https://api.githubcopilot.com",
"copilot_temperature": 0.2
}
diff --git a/internal/llm/copilot.go b/internal/llm/copilot.go
index 1c9f60d..6ab3a0d 100644
--- a/internal/llm/copilot.go
+++ b/internal/llm/copilot.go
@@ -11,6 +11,7 @@ import (
"strings"
"time"
+ appver "hexai/internal"
"hexai/internal/logging"
)
@@ -60,7 +61,9 @@ func newCopilot(baseURL, model, apiKey string, defaultTemp *float64) Client {
baseURL = "https://api.githubcopilot.com"
}
if strings.TrimSpace(model) == "" {
- model = "gpt-4.1"
+ // GitHub Models (Copilot API) commonly supports gpt-4o/gpt-4o-mini.
+ // Default to a broadly available, cost-effective option.
+ model = "gpt-4o-mini"
}
return copilotClient{
httpClient: &http.Client{Timeout: 30 * time.Second},
@@ -155,6 +158,10 @@ func (c copilotClient) doJSON(ctx context.Context, url string, body []byte, head
return nil, err
}
req.Header.Set("Content-Type", "application/json")
+ // GitHub Copilot (GitHub Models) requires an API version header and a UA.
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("X-GitHub-Api-Version", "2023-07-07")
+ req.Header.Set("User-Agent", "hexai/"+appver.Version)
for k, v := range headers {
req.Header.Set(k, v)
}