Documentation
¶
Overview ¶
Package copilot calls models through a GitHub Copilot subscription: the same sign-in Copilot CLI uses, exchanged for a short-lived session token and the API host that subscription is supposed to call.
A personal subscription is served at api.githubcopilot.com. Copilot Business and Copilot Enterprise are served at their own hosts, and the host is part of the token exchange, not something the caller guesses. A request that skips the exchange and calls the personal host with the GitHub token is the failure mode in which the model list loads and every completion then answers that the model is not supported.
Index ¶
Constants ¶
const Provider = "github-copilot"
Provider is the config value (llm.provider, or a models: entry's provider) that selects this package.
Variables ¶
This section is empty.
Functions ¶
func DefaultBackend ¶
DefaultBackend is the protocol used when the account's model list does not say, chosen from the model id the way Copilot routes it.
func IsEmbeddingModel ¶ added in v0.3.1
func IsEmbeddingModel(m ListedModel) bool
IsEmbeddingModel reports whether a catalog model is an embedding model. Those have no chat endpoint, so they are useless as agent models. GitHub serves them as text-embedding-*, with context 0 and no chat protocol.
func NormalizeHost ¶
NormalizeHost accepts a hostname or an https URL and returns the hostname Copilot's enterprise routing wants (company.ghe.com). Empty stays empty.
Types ¶
type Catalog ¶
type Catalog struct {
APIBase string
SKU string
Exchanged bool
Models []ListedModel
}
Catalog is the model list for the signed-in account, plus which API origin and which kind of token produced it.
type CommandRunner ¶
type CommandRunner interface {
LookPath(name string) (string, error)
Output(ctx context.Context, name string, args ...string) ([]byte, error)
}
CommandRunner is the slice of os/exec Finder needs. Tests substitute one that never touches the real keychain or a real `gh`.
type Finder ¶
type Finder struct {
Getenv func(string) string
HomeDir string
Run CommandRunner
}
Finder reads a GitHub token from the environment, Copilot CLI's config file, the OS keychain, and the GitHub CLI. A zero Finder uses the real environment; tests replace the function fields.
type ListedModel ¶
type ListedModel struct {
ID string
Name string
Endpoints []string
Protocol string
Context int
Efforts []string
Disabled bool
}
ListedModel is one model the signed-in Copilot account is allowed to call.
type Options ¶
type Options struct {
Model string
GitHubToken string
Host string
BaseURL string
BackendPinned bool
ForceInitiator string
InteractionType string
}
Options selects one Copilot model and, optionally, forces the API origin or the wire protocol. An empty GitHubToken means "read whatever Copilot CLI would use on this machine".
type Result ¶
type Result struct {
BaseURL string
APIKey string
Backend string
Auth llm.RequestAuthorizer
APIBase string
SKU string
Exchanged bool
// MaxOutput is the model's output cap from the account's model list, or
// 0 when the list did not say. The messages API requires some cap;
// chat and responses leave it to the caller.
MaxOutput int
}
Result is what a chat client needs after the token exchange: the origin to call, the bearer token, the wire protocol, and an authorizer that refreshes the session token and sets Copilot's request headers.
func Prepare ¶
Prepare exchanges the GitHub token and decides which protocol the named model speaks. A failure to fetch the model list does not fail the call when the token itself was accepted: the protocol then comes from the model id. An authorization failure does fail it, because the chat call would fail the same way.