provider

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProviderModels = map[llm.ProviderName][]string{
	llm.ProviderNameOpenAI: {
		"gpt-5",
		"gpt-5-mini",
		"gpt-5-nano",
		"gpt-5.1",
		"gpt-4.1",
		"gpt-4.1-mini",
		"gpt-4.1-nano",
		"gpt-4o",
		"gpt-4o-mini",
		"o3",
		"o3-mini",
		"o4-mini",
	},
	llm.ProviderNameAnthropic: {
		"claude-haiku-4-5",
		"claude-opus-4-20250514",
		"claude-sonnet-4-20250514",
		"claude-opus-4-1-20250805",
		"claude-sonnet-4-0",
		"claude-3-7-sonnet",
		"claude-3-5-sonnet",
		"claude-3-5-haiku",
	},
	llm.ProviderNameGemini: {
		"gemini-3-pro-preview",
		"gemini-3-pro",
		"gemini-2.5-pro",
		"gemini-2.5-flash",
		"gemini-2.5-flash-lite",
		"gemini-2.0-flash",
		"gemini-1.5-pro",
	},
	llm.ProviderNameXAI: {
		"grok-4",
		"grok-4-heavy",
		"grok-4.1-fast-reasoning",
		"grok-4.1-fast-non-reasoning",
		"grok-4-fast-reasoning",
		"grok-4-fast-non-reasoning",
		"grok-3",
		"grok-3-mini",
		"grok-2.5",
	},
	llm.ProviderNameOllama: {
		"llama3.1:latest",
		"mistral:latest",
	},
}

ProviderModels contains the available models for each provider

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID           uuid.UUID        `json:"id" db:"id"`
	ProviderType llm.ProviderName `json:"provider_type" db:"provider_type"`
	Name         string           `json:"name" db:"name"`
	APIKey       string           `json:"api_key" db:"api_key"`
	Enabled      bool             `json:"enabled" db:"enabled"`
	IsDefault    bool             `json:"is_default" db:"is_default"`
	CreatedAt    time.Time        `json:"created_at" db:"created_at"`
	UpdatedAt    time.Time        `json:"updated_at" db:"updated_at"`
}

APIKey represents an API key configuration

type CreateAPIKeyRequest

type CreateAPIKeyRequest struct {
	ProviderType llm.ProviderName `json:"provider_type" validate:"required,oneof=OpenAI Anthropic Gemini xAI"`
	Name         string           `json:"name" validate:"required,min=1,max=255"`
	APIKey       string           `json:"api_key" validate:"required,min=1"`
	Enabled      bool             `json:"enabled,omitempty"`
	IsDefault    bool             `json:"is_default,omitempty"`
}

CreateAPIKeyRequest represents the request to create a new API key

type CreateProviderConfigRequest

type CreateProviderConfigRequest struct {
	ProviderType  llm.ProviderName `json:"provider_type" validate:"required,oneof=OpenAI Anthropic Gemini xAI"`
	BaseURL       *string          `json:"base_url,omitempty" validate:"omitempty,url"`
	CustomHeaders CustomHeadersMap `json:"custom_headers,omitempty"`
}

CreateProviderConfigRequest represents the request to create/update provider config

type CustomHeadersMap

type CustomHeadersMap map[string]string

CustomHeadersMap represents a map of custom headers that can be stored in JSONB

func (CustomHeadersMap) MarshalJSON

func (h CustomHeadersMap) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*CustomHeadersMap) Scan

func (h *CustomHeadersMap) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database/sql

func (*CustomHeadersMap) UnmarshalJSON

func (h *CustomHeadersMap) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (CustomHeadersMap) Value

func (h CustomHeadersMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database/sql

type ProviderConfig

type ProviderConfig struct {
	ProviderType  llm.ProviderName `json:"provider_type" db:"provider_type"`
	BaseURL       *string          `json:"base_url,omitempty" db:"base_url"`
	CustomHeaders CustomHeadersMap `json:"custom_headers,omitempty" db:"custom_headers"`
	CreatedAt     time.Time        `json:"created_at" db:"created_at"`
	UpdatedAt     time.Time        `json:"updated_at" db:"updated_at"`
}

ProviderConfig represents provider-level configuration (base URL, custom headers)

type ProviderModelsData

type ProviderModelsData struct {
	Models []string `json:"models"`
}

ProviderModelsData represents the models data for a provider

type ProviderModelsResponse

type ProviderModelsResponse struct {
	Providers map[string]ProviderModelsData `json:"providers"`
}

ProviderModelsResponse represents the response structure for provider models API

func GetProviderModelsResponse

func GetProviderModelsResponse() ProviderModelsResponse

GetProviderModelsResponse returns the provider models in the API response format

type ProviderRepo

type ProviderRepo struct {
	// contains filtered or unexported fields
}

ProviderRepo handles database operations for API keys

func NewProviderRepo

func NewProviderRepo(db *sqlx.DB) *ProviderRepo

NewProviderRepo creates a new provider repository

func (*ProviderRepo) Create

func (r *ProviderRepo) Create(ctx context.Context, req *CreateAPIKeyRequest) (*APIKey, error)

Create creates a new API key

func (*ProviderRepo) CreateOrUpdateProviderConfig

func (r *ProviderRepo) CreateOrUpdateProviderConfig(ctx context.Context, req *CreateProviderConfigRequest) (*ProviderConfig, error)

CreateOrUpdateProviderConfig creates or updates provider config

func (*ProviderRepo) Delete

func (r *ProviderRepo) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes an API key

func (*ProviderRepo) GetByID

func (r *ProviderRepo) GetByID(ctx context.Context, id uuid.UUID) (*APIKey, error)

GetByID retrieves an API key by ID

func (*ProviderRepo) GetByName

func (r *ProviderRepo) GetByName(ctx context.Context, providerType llm.ProviderName, name string) (*APIKey, error)

GetByName retrieves an API key by provider type and name

func (*ProviderRepo) GetDefaultAPIKey

func (r *ProviderRepo) GetDefaultAPIKey(ctx context.Context, providerType llm.ProviderName) (*APIKey, error)

GetDefaultAPIKey retrieves the default API key for a provider type

func (*ProviderRepo) GetProviderConfig

func (r *ProviderRepo) GetProviderConfig(ctx context.Context, providerType llm.ProviderName) (*ProviderConfig, error)

GetProviderConfig retrieves provider config by provider type

func (*ProviderRepo) List

func (r *ProviderRepo) List(ctx context.Context, providerType *llm.ProviderName, enabledOnly bool) ([]*APIKey, error)

List retrieves all API keys with optional filtering

func (*ProviderRepo) ListProviderConfigs

func (r *ProviderRepo) ListProviderConfigs(ctx context.Context) ([]*ProviderConfig, error)

ListProviderConfigs retrieves all provider configs

func (*ProviderRepo) Update

func (r *ProviderRepo) Update(ctx context.Context, id uuid.UUID, req *UpdateAPIKeyRequest) (*APIKey, error)

Update updates an API key

func (*ProviderRepo) UpdateProviderConfig

func (r *ProviderRepo) UpdateProviderConfig(ctx context.Context, providerType llm.ProviderName, req *UpdateProviderConfigRequest) (*ProviderConfig, error)

UpdateProviderConfig updates provider config

type ProviderService

type ProviderService struct {
	// contains filtered or unexported fields
}

ProviderService handles business logic for API keys

func NewProviderService

func NewProviderService(repo *ProviderRepo) *ProviderService

NewProviderService creates a new provider service

func (*ProviderService) Create

Create creates a new API key

func (*ProviderService) CreateOrUpdateProviderConfig

func (s *ProviderService) CreateOrUpdateProviderConfig(ctx context.Context, req *CreateProviderConfigRequest) (*ProviderConfig, error)

CreateOrUpdateProviderConfig creates or updates provider config

func (*ProviderService) Delete

func (s *ProviderService) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes an API key

func (*ProviderService) GetByName

func (s *ProviderService) GetByName(ctx context.Context, providerType llm.ProviderName, name string) (*APIKey, error)

GetByName retrieves an API key by provider type and name

func (*ProviderService) GetDefaultAPIKey

func (s *ProviderService) GetDefaultAPIKey(ctx context.Context, providerType llm.ProviderName) (*APIKey, error)

GetDefaultAPIKey retrieves the default API key for a provider type

func (*ProviderService) GetProviderConfig

func (s *ProviderService) GetProviderConfig(ctx context.Context, providerType llm.ProviderName) (*ProviderConfig, error)

GetProviderConfig retrieves provider config by provider type

func (*ProviderService) List

func (s *ProviderService) List(ctx context.Context, providerType *llm.ProviderName, enabledOnly bool) ([]*APIKey, error)

List retrieves all API keys with optional filtering

func (*ProviderService) ListProviderConfigs

func (s *ProviderService) ListProviderConfigs(ctx context.Context) ([]*ProviderConfig, error)

ListProviderConfigs retrieves all provider configs

func (*ProviderService) Update

func (s *ProviderService) Update(ctx context.Context, id uuid.UUID, req *UpdateAPIKeyRequest) (*APIKey, error)

Update updates an API key

func (*ProviderService) UpdateProviderConfig

func (s *ProviderService) UpdateProviderConfig(ctx context.Context, providerType llm.ProviderName, req *UpdateProviderConfigRequest) (*ProviderConfig, error)

UpdateProviderConfig updates provider config

type UpdateAPIKeyRequest

type UpdateAPIKeyRequest struct {
	Name      *string `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
	APIKey    *string `json:"api_key,omitempty" validate:"omitempty,min=1"`
	Enabled   *bool   `json:"enabled,omitempty"`
	IsDefault *bool   `json:"is_default,omitempty"`
}

UpdateAPIKeyRequest represents the request to update an API key

type UpdateProviderConfigRequest

type UpdateProviderConfigRequest struct {
	BaseURL       *string           `json:"base_url,omitempty" validate:"omitempty,url"`
	CustomHeaders *CustomHeadersMap `json:"custom_headers,omitempty"`
}

UpdateProviderConfigRequest represents the request to update provider config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL