Documentation
¶
Overview ¶
Package openrouter provides an input plugin for generating images using OpenRouter.ai models.
Index ¶
- Constants
- type APIError
- type Architecture
- type ChatCompletionRequest
- type ChatCompletionResponse
- type Choice
- type ImageConfig
- type ImageData
- type ImageMetadata
- type ImageURL
- type Message
- type Model
- type ModelsResponse
- type Plugin
- func (p *Plugin) Description() string
- func (p *Plugin) Generate(ctx context.Context, opts input.GenerateOptions) (*colour.Palette, error)
- func (p *Plugin) GetFlagHelp() []input.FlagHelp
- func (p *Plugin) Name() string
- func (p *Plugin) RegisterFlags(cmd *cobra.Command)
- func (p *Plugin) Validate() error
- func (p *Plugin) Version() string
- func (p *Plugin) WallpaperPath() string
- type Pricing
- type PricingInfo
- type PricingType
- type ResponseMessage
- type TopProvider
Constants ¶
const ( // RegionWeightFactor determines how much weight region colors receive // relative to main palette colors. Region colors get 10% of the total weight. RegionWeightFactor = 0.1 // MainColorWeightRatio is the proportion of total weight allocated to // main palette colors when region extraction is enabled (90%). MainColorWeightRatio = 0.9 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Message string `json:"message"`
Type string `json:"type"`
Code interface{} `json:"code"` // Can be string or number depending on provider
}
APIError represents an API error response.
func (*APIError) CodeString ¶
CodeString returns the error code as a string.
type Architecture ¶
type Architecture struct {
Modality string `json:"modality"`
InputModalities []string `json:"input_modalities"`
OutputModalities []string `json:"output_modalities"`
Tokenizer string `json:"tokenizer"`
}
Architecture contains model capability information.
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Modalities []string `json:"modalities,omitempty"`
ImageConfig *ImageConfig `json:"image_config,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
}
ChatCompletionRequest represents the request body for OpenRouter chat completions.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Error *APIError `json:"error,omitempty"`
}
ChatCompletionResponse represents the response from OpenRouter.
type Choice ¶
type Choice struct {
Index int `json:"index"`
Message ResponseMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
Choice represents a completion choice.
type ImageConfig ¶
type ImageConfig struct {
AspectRatio string `json:"aspect_ratio,omitempty"`
}
ImageConfig contains image generation configuration.
type ImageMetadata ¶
type ImageMetadata struct {
// Generation parameters
Prompt string `json:"prompt"`
EnhancedPrompt string `json:"enhanced_prompt,omitempty"`
NegativePrompt string `json:"negative_prompt,omitempty"`
Model string `json:"model"`
AspectRatio string `json:"aspect_ratio"`
// Generation details
CreatedAt time.Time `json:"created_at"`
ImagePath string `json:"image_path"`
ImageSize_ int `json:"image_bytes"`
// API response data
FinishReason string `json:"finish_reason,omitempty"`
}
ImageMetadata contains metadata about a generated image.
type ImageURL ¶
type ImageURL struct {
URL string `json:"url"`
}
ImageURL contains the image URL data.
type Model ¶
type Model struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Created int64 `json:"created"`
Architecture Architecture `json:"architecture"`
Pricing Pricing `json:"pricing"`
TopProvider *TopProvider `json:"top_provider,omitempty"`
}
Model represents a model in the API response.
type ModelsResponse ¶
type ModelsResponse struct {
Data []Model `json:"data"`
}
ModelsResponse represents the response from the models API.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the input.Plugin interface for OpenRouter image generation.
func (*Plugin) Description ¶
Description returns a human-readable description.
func (*Plugin) GetFlagHelp ¶
GetFlagHelp returns help information for all plugin flags.
func (*Plugin) RegisterFlags ¶
RegisterFlags registers plugin-specific flags.
func (*Plugin) WallpaperPath ¶
WallpaperPath returns the path to the generated image for wallpaper use.
type Pricing ¶
type Pricing struct {
Prompt string `json:"prompt"`
Completion string `json:"completion"`
Request string `json:"request"`
Image string `json:"image"`
}
Pricing contains model pricing information.
type PricingInfo ¶
type PricingInfo struct {
Type PricingType
ImageCost float64 // Cost per image
RequestCost float64 // Cost per request
PromptCost float64 // Cost per input token
CompletionCost float64 // Cost per output token
}
PricingInfo contains parsed pricing information for a model.
type PricingType ¶
type PricingType int
PricingType indicates the pricing model used by a model.
const ( PricingFree PricingType = iota PricingPerImage PricingPerRequest PricingPerToken )
type ResponseMessage ¶
type ResponseMessage struct {
Role string `json:"role"`
Content string `json:"content"`
Images []ImageData `json:"images,omitempty"`
}
ResponseMessage represents the assistant's response message.
type TopProvider ¶
type TopProvider struct {
ContextLength int `json:"context_length"`
MaxCompletionTokens int `json:"max_completion_tokens"`
IsModerated bool `json:"is_moderated"`
}
TopProvider contains provider-specific information.