Documentation
¶
Overview ¶
Package providers implements OAuth providers for various LLM services.
Index ¶
- Constants
- type BaseProvider
- func (p *BaseProvider) AuthURL(state, challenge string) string
- func (p *BaseProvider) ExchangeCode(ctx context.Context, code, verifier string) (credential any, err error)
- func (p *BaseProvider) Label() string
- func (p *BaseProvider) Name() string
- func (p *BaseProvider) RefreshToken(ctx context.Context, refreshToken string) (credential any, err error)
- func (p *BaseProvider) Scopes() []string
- func (p *BaseProvider) SupportsDeviceCode() bool
- func (p *BaseProvider) SupportsPKCE() bool
- func (p *BaseProvider) TokenURL() string
- type ChatGPTOption
- type ChatGPTProvider
- func (p *ChatGPTProvider) APIBase() string
- func (p *ChatGPTProvider) AuthURL(state, challenge string) string
- func (p *ChatGPTProvider) BuildAPIRequest(ctx context.Context, accessToken string, req *ChatRequest) (*http.Request, error)
- func (p *ChatGPTProvider) DoAPIRequest(ctx context.Context, accessToken string, req *ChatRequest) (*ChatResponse, error)
- func (p *ChatGPTProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
- func (p *ChatGPTProvider) IsExperimental() bool
- func (p *ChatGPTProvider) RedirectPort() int
- func (p *ChatGPTProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type GeminiCLICredentials
- type GeminiOption
- type GeminiProvider
- func (p *GeminiProvider) AuthURL(state, challenge string) string
- func (p *GeminiProvider) ClientID() string
- func (p *GeminiProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
- func (p *GeminiProvider) RedirectPort() int
- func (p *GeminiProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
- type MiniMaxOption
- type MiniMaxProvider
- func (p *MiniMaxProvider) APIBase() string
- func (p *MiniMaxProvider) DeviceCodeURL() string
- func (p *MiniMaxProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
- func (p *MiniMaxProvider) PollForToken(ctx context.Context, deviceCode string, interval time.Duration) (*oauth.OAuthCredential, error)
- func (p *MiniMaxProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
- func (p *MiniMaxProvider) Region() string
- func (p *MiniMaxProvider) StartDeviceFlow(ctx context.Context) (*oauth.DeviceCodeResponse, error)
- func (p *MiniMaxProvider) TokenURL() string
- type QwenOption
- type QwenProvider
- func (p *QwenProvider) APIBase() string
- func (p *QwenProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
- func (p *QwenProvider) PollForToken(ctx context.Context, deviceCode string, interval time.Duration) (*oauth.OAuthCredential, error)
- func (p *QwenProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
- func (p *QwenProvider) StartDeviceFlow(ctx context.Context) (*oauth.DeviceCodeResponse, error)
Constants ¶
const ExperimentalWarning = `` /* 248-byte string literal not displayed */
ExperimentalWarning is shown when using ChatGPT OAuth.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseProvider ¶
type BaseProvider struct {
// contains filtered or unexported fields
}
BaseProvider contains common functionality for OAuth providers.
func (*BaseProvider) AuthURL ¶
func (p *BaseProvider) AuthURL(state, challenge string) string
AuthURL returns the authorization URL.
func (*BaseProvider) ExchangeCode ¶
func (p *BaseProvider) ExchangeCode(ctx context.Context, code, verifier string) (credential any, err error)
ExchangeCode must be implemented by each provider.
func (*BaseProvider) Label ¶
func (p *BaseProvider) Label() string
Label returns the human-readable provider name.
func (*BaseProvider) Name ¶
func (p *BaseProvider) Name() string
Name returns the provider identifier.
func (*BaseProvider) RefreshToken ¶
func (p *BaseProvider) RefreshToken(ctx context.Context, refreshToken string) (credential any, err error)
RefreshToken must be implemented by each provider.
func (*BaseProvider) Scopes ¶
func (p *BaseProvider) Scopes() []string
Scopes returns the OAuth scopes.
func (*BaseProvider) SupportsDeviceCode ¶
func (p *BaseProvider) SupportsDeviceCode() bool
SupportsDeviceCode returns true if device code flow is supported.
func (*BaseProvider) SupportsPKCE ¶
func (p *BaseProvider) SupportsPKCE() bool
SupportsPKCE returns true if PKCE is supported.
func (*BaseProvider) TokenURL ¶
func (p *BaseProvider) TokenURL() string
TokenURL returns the token exchange URL.
type ChatGPTOption ¶
type ChatGPTOption func(*ChatGPTProvider)
ChatGPTOption configures the ChatGPT provider.
func WithChatGPTClientID ¶
func WithChatGPTClientID(clientID string) ChatGPTOption
WithChatGPTClientID sets a custom client ID.
func WithChatGPTLogger ¶
func WithChatGPTLogger(logger *slog.Logger) ChatGPTOption
WithChatGPTLogger sets the logger.
func WithChatGPTRedirectPort ¶
func WithChatGPTRedirectPort(port int) ChatGPTOption
WithChatGPTRedirectPort sets the redirect port.
type ChatGPTProvider ¶
type ChatGPTProvider struct {
BaseProvider
// contains filtered or unexported fields
}
ChatGPTProvider implements OAuth for ChatGPT/Codex (EXPERIMENTAL).
func NewChatGPTProvider ¶
func NewChatGPTProvider(opts ...ChatGPTOption) *ChatGPTProvider
NewChatGPTProvider creates a new ChatGPT OAuth provider.
func (*ChatGPTProvider) APIBase ¶
func (p *ChatGPTProvider) APIBase() string
APIBase returns the ChatGPT Codex API base URL.
func (*ChatGPTProvider) AuthURL ¶
func (p *ChatGPTProvider) AuthURL(state, challenge string) string
AuthURL returns the authorization URL for the OAuth flow.
func (*ChatGPTProvider) BuildAPIRequest ¶
func (p *ChatGPTProvider) BuildAPIRequest(ctx context.Context, accessToken string, req *ChatRequest) (*http.Request, error)
BuildAPIRequest builds an HTTP request for the ChatGPT Codex API.
func (*ChatGPTProvider) DoAPIRequest ¶
func (p *ChatGPTProvider) DoAPIRequest(ctx context.Context, accessToken string, req *ChatRequest) (*ChatResponse, error)
DoAPIRequest executes a request to the ChatGPT Codex API.
func (*ChatGPTProvider) ExchangeCode ¶
func (p *ChatGPTProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
ExchangeCode exchanges an authorization code for tokens.
func (*ChatGPTProvider) IsExperimental ¶
func (p *ChatGPTProvider) IsExperimental() bool
IsExperimental returns true (ChatGPT OAuth is experimental).
func (*ChatGPTProvider) RedirectPort ¶
func (p *ChatGPTProvider) RedirectPort() int
RedirectPort returns the configured redirect port.
func (*ChatGPTProvider) RefreshToken ¶
func (p *ChatGPTProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
RefreshToken refreshes an access token.
type ChatMessage ¶
ChatMessage represents a message in a chat request.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
Stream bool `json:"stream,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
}
ChatRequest represents a request to the ChatGPT Codex API.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Message struct {
Role string `json:"role"`
Content string `json:"content"`
} `json:"message"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
ChatResponse represents a response from the ChatGPT Codex API.
type GeminiCLICredentials ¶
GeminiCLICredentials contains extracted credentials from Gemini CLI.
func ExtractGeminiCLICredentials ¶
func ExtractGeminiCLICredentials() (*GeminiCLICredentials, error)
ExtractGeminiCLICredentials extracts OAuth credentials from an installed Gemini CLI.
type GeminiOption ¶
type GeminiOption func(*GeminiProvider)
GeminiOption configures the Gemini provider.
func WithGeminiClientID ¶
func WithGeminiClientID(clientID string) GeminiOption
WithGeminiClientID sets a custom client ID.
func WithGeminiClientSecret ¶
func WithGeminiClientSecret(secret string) GeminiOption
WithGeminiClientSecret sets a custom client secret.
func WithGeminiLogger ¶
func WithGeminiLogger(logger *slog.Logger) GeminiOption
WithGeminiLogger sets the logger.
func WithGeminiRedirectPort ¶
func WithGeminiRedirectPort(port int) GeminiOption
WithGeminiRedirectPort sets the redirect port.
type GeminiProvider ¶
type GeminiProvider struct {
BaseProvider
// contains filtered or unexported fields
}
GeminiProvider implements OAuth for Google Gemini/Code Assist.
func NewGeminiProvider ¶
func NewGeminiProvider(opts ...GeminiOption) *GeminiProvider
NewGeminiProvider creates a new Gemini OAuth provider.
func (*GeminiProvider) AuthURL ¶
func (p *GeminiProvider) AuthURL(state, challenge string) string
AuthURL returns the authorization URL for the OAuth flow.
func (*GeminiProvider) ClientID ¶
func (p *GeminiProvider) ClientID() string
ClientID returns the configured client ID.
func (*GeminiProvider) ExchangeCode ¶
func (p *GeminiProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
ExchangeCode exchanges an authorization code for tokens.
func (*GeminiProvider) RedirectPort ¶
func (p *GeminiProvider) RedirectPort() int
RedirectPort returns the configured redirect port.
func (*GeminiProvider) RefreshToken ¶
func (p *GeminiProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
RefreshToken refreshes an access token.
type MiniMaxOption ¶
type MiniMaxOption func(*MiniMaxProvider)
MiniMaxOption configures the MiniMax provider.
func WithMiniMaxLogger ¶
func WithMiniMaxLogger(logger *slog.Logger) MiniMaxOption
WithMiniMaxLogger sets the logger.
func WithMiniMaxRegion ¶
func WithMiniMaxRegion(region string) MiniMaxOption
WithMiniMaxRegion sets the region ("global" or "cn").
type MiniMaxProvider ¶
type MiniMaxProvider struct {
BaseProvider
// contains filtered or unexported fields
}
MiniMaxProvider implements OAuth for MiniMax Portal using device code flow.
func NewMiniMaxProvider ¶
func NewMiniMaxProvider(opts ...MiniMaxOption) *MiniMaxProvider
NewMiniMaxProvider creates a new MiniMax OAuth provider.
func (*MiniMaxProvider) APIBase ¶
func (p *MiniMaxProvider) APIBase() string
APIBase returns the API base URL for the region.
func (*MiniMaxProvider) DeviceCodeURL ¶
func (p *MiniMaxProvider) DeviceCodeURL() string
DeviceCodeURL returns the device code URL for the region.
func (*MiniMaxProvider) ExchangeCode ¶
func (p *MiniMaxProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
ExchangeCode is not supported for MiniMax (uses device code flow).
func (*MiniMaxProvider) PollForToken ¶
func (p *MiniMaxProvider) PollForToken(ctx context.Context, deviceCode string, interval time.Duration) (*oauth.OAuthCredential, error)
PollForToken polls for token completion.
func (*MiniMaxProvider) RefreshToken ¶
func (p *MiniMaxProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
RefreshToken refreshes an access token.
func (*MiniMaxProvider) Region ¶
func (p *MiniMaxProvider) Region() string
Region returns the configured region.
func (*MiniMaxProvider) StartDeviceFlow ¶
func (p *MiniMaxProvider) StartDeviceFlow(ctx context.Context) (*oauth.DeviceCodeResponse, error)
StartDeviceFlow initiates the device code flow.
func (*MiniMaxProvider) TokenURL ¶
func (p *MiniMaxProvider) TokenURL() string
TokenURL returns the token URL for the region.
type QwenOption ¶
type QwenOption func(*QwenProvider)
QwenOption configures the Qwen provider.
func WithQwenClientID ¶
func WithQwenClientID(clientID string) QwenOption
WithQwenClientID sets a custom client ID.
func WithQwenLogger ¶
func WithQwenLogger(logger *slog.Logger) QwenOption
WithQwenLogger sets the logger.
type QwenProvider ¶
type QwenProvider struct {
BaseProvider
// contains filtered or unexported fields
}
QwenProvider implements OAuth for Qwen Portal using device code flow.
func NewQwenProvider ¶
func NewQwenProvider(opts ...QwenOption) *QwenProvider
NewQwenProvider creates a new Qwen OAuth provider.
func (*QwenProvider) APIBase ¶
func (p *QwenProvider) APIBase() string
APIBase returns the Qwen API base URL.
func (*QwenProvider) ExchangeCode ¶
func (p *QwenProvider) ExchangeCode(ctx context.Context, code, verifier string) (*oauth.OAuthCredential, error)
ExchangeCode is not supported for Qwen (uses device code flow).
func (*QwenProvider) PollForToken ¶
func (p *QwenProvider) PollForToken(ctx context.Context, deviceCode string, interval time.Duration) (*oauth.OAuthCredential, error)
PollForToken polls for token completion.
func (*QwenProvider) RefreshToken ¶
func (p *QwenProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.OAuthCredential, error)
RefreshToken refreshes an access token.
func (*QwenProvider) StartDeviceFlow ¶
func (p *QwenProvider) StartDeviceFlow(ctx context.Context) (*oauth.DeviceCodeResponse, error)
StartDeviceFlow initiates the device code flow.