diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-17 08:43:53 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-17 08:43:53 +0300 |
| commit | 07d02d93dbb7a8167758f678c68b5a1a520167c8 (patch) | |
| tree | ffa0698323175c2c5fa591420f2c33d1bcb9e069 /internal/llm/provider.go | |
| parent | d44ae13e97eff75704b0fbd90814811dcc98eff5 (diff) | |
llm: add GitHub Copilot provider
- Implement copilot client reading COPILOT_API_KEY
- Wire copilot_base_url and copilot_model config
- Update README and config example; defaults to gpt-4.1
- Keep OpenAI default at gpt-4.1 for consistency
Diffstat (limited to 'internal/llm/provider.go')
| -rw-r--r-- | internal/llm/provider.go | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/internal/llm/provider.go b/internal/llm/provider.go index 6c6cf04..dda3d16 100644 --- a/internal/llm/provider.go +++ b/internal/llm/provider.go @@ -43,32 +43,40 @@ func WithStop(stop ...string) RequestOption { // Config defines provider configuration read from the Hexai config file. type Config struct { - Provider string - // OpenAI options - OpenAIBaseURL string - OpenAIModel string - // Ollama options - OllamaBaseURL string - OllamaModel string + Provider string + // OpenAI options + OpenAIBaseURL string + OpenAIModel string + // Ollama options + OllamaBaseURL string + OllamaModel string + // Copilot options + CopilotBaseURL string + CopilotModel string } // NewFromConfig creates an LLM client using only the supplied configuration. // The OpenAI API key is supplied separately and may be read from the environment // by the caller; other environment-based configuration is not used. -func NewFromConfig(cfg Config, openAIAPIKey string) (Client, error) { - p := strings.ToLower(strings.TrimSpace(cfg.Provider)) - if p == "" { - p = "openai" - } - switch p { - case "openai": - if strings.TrimSpace(openAIAPIKey) == "" { - return nil, errors.New("missing OPENAI_API_KEY for provider openai") - } - return newOpenAI(cfg.OpenAIBaseURL, cfg.OpenAIModel, openAIAPIKey), nil - case "ollama": - return newOllama(cfg.OllamaBaseURL, cfg.OllamaModel), nil - default: - return nil, errors.New("unknown LLM provider: " + p) - } +func NewFromConfig(cfg Config, openAIAPIKey, copilotAPIKey string) (Client, error) { + p := strings.ToLower(strings.TrimSpace(cfg.Provider)) + if p == "" { + p = "openai" + } + switch p { + case "openai": + if strings.TrimSpace(openAIAPIKey) == "" { + return nil, errors.New("missing OPENAI_API_KEY for provider openai") + } + return newOpenAI(cfg.OpenAIBaseURL, cfg.OpenAIModel, openAIAPIKey), nil + case "ollama": + return newOllama(cfg.OllamaBaseURL, cfg.OllamaModel), nil + case "copilot": + if strings.TrimSpace(copilotAPIKey) == "" { + return nil, errors.New("missing COPILOT_API_KEY for provider copilot") + } + return newCopilot(cfg.CopilotBaseURL, cfg.CopilotModel, copilotAPIKey), nil + default: + return nil, errors.New("unknown LLM provider: " + p) + } } |
