models

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ModelInputText  = "text"
	ModelInputImage = "image"
	ModelInputAudio = "audio"
	ModelInputVideo = "video"
	ModelInputFile  = "file"
)

Variables

View Source
var ErrModelIDAlreadyExists = errors.New("model_id already exists")
View Source
var ErrModelIDAmbiguous = errors.New("model_id is ambiguous across providers")

Functions

func FetchProviderByID

func FetchProviderByID(ctx context.Context, queries *sqlc.Queries, providerID string) (sqlc.LlmProvider, error)

FetchProviderByID fetches a provider by ID.

Types

type AddRequest

type AddRequest Model

type AddResponse

type AddResponse struct {
	ID      string `json:"id"`
	ModelID string `json:"model_id"`
}

type ClientType

type ClientType string
const (
	ClientTypeOpenAIResponses    ClientType = "openai-responses"
	ClientTypeOpenAICompletions  ClientType = "openai-completions"
	ClientTypeAnthropicMessages  ClientType = "anthropic-messages"
	ClientTypeGoogleGenerativeAI ClientType = "google-generative-ai"
)

type CountResponse

type CountResponse struct {
	Count int64 `json:"count"`
}

type DeleteRequest

type DeleteRequest struct {
	ID      string `json:"id,omitempty"`
	ModelID string `json:"model_id,omitempty"`
}

type DeleteResponse

type DeleteResponse struct {
	Message string `json:"message"`
}

type GetRequest

type GetRequest struct {
	ID string `json:"id"`
}

type GetResponse

type GetResponse struct {
	ID      string `json:"id"`
	ModelID string `json:"model_id"`
	Model
}

func SelectMemoryModel

func SelectMemoryModel(ctx context.Context, modelsService *Service, queries *sqlc.Queries) (GetResponse, sqlc.LlmProvider, error)

SelectMemoryModel selects a chat model for memory operations.

func SelectMemoryModelForBot

func SelectMemoryModelForBot(ctx context.Context, modelsService *Service, queries *sqlc.Queries, botID string) (GetResponse, sqlc.LlmProvider, error)

SelectMemoryModelForBot selects memory model by bot settings first, then falls back to SelectMemoryModel.

type ListRequest

type ListRequest struct {
	Type       ModelType  `json:"type,omitempty"`
	ClientType ClientType `json:"client_type,omitempty"`
}

type Model

type Model struct {
	ModelID           string     `json:"model_id"`
	Name              string     `json:"name"`
	LlmProviderID     string     `json:"llm_provider_id"`
	ClientType        ClientType `json:"client_type,omitempty"`
	InputModalities   []string   `json:"input_modalities,omitempty"`
	SupportsReasoning bool       `json:"supports_reasoning"`
	Type              ModelType  `json:"type"`
	Dimensions        int        `json:"dimensions"`
}

func (*Model) HasInputModality

func (m *Model) HasInputModality(mod string) bool

HasInputModality checks whether the model supports a given input modality.

func (*Model) IsMultimodal

func (m *Model) IsMultimodal() bool

IsMultimodal returns true if the model supports any input modality beyond text.

func (*Model) Validate

func (m *Model) Validate() error

type ModelType

type ModelType string
const (
	ModelTypeChat      ModelType = "chat"
	ModelTypeEmbedding ModelType = "embedding"
)

type Service

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

Service provides CRUD operations for models

func NewService

func NewService(log *slog.Logger, queries *sqlc.Queries) *Service

NewService creates a new models service

func (*Service) Count

func (s *Service) Count(ctx context.Context) (int64, error)

Count returns the total number of models

func (*Service) CountByType

func (s *Service) CountByType(ctx context.Context, modelType ModelType) (int64, error)

CountByType returns the number of models of a specific type

func (*Service) Create

func (s *Service) Create(ctx context.Context, req AddRequest) (AddResponse, error)

Create adds a new model to the database

Example
package main

import ()

func main() {
	// Example usage - in real code, you would initialize with actual database connection
	// service := models.NewService(queries)

	// ctx := context.Background()
	// req := models.AddRequest{
	// 	ModelID:    "gpt-4",
	// 	Name:       "GPT-4",
	// 	LlmProviderID: "11111111-1111-1111-1111-111111111111",
	// 	Type:       models.ModelTypeChat,
	// }

	// resp, err := service.Create(ctx, req)
	// if err != nil {
	// 	// handle error
	// }
	// fmt.Printf("Created model with ID: %s\n", resp.ID)
}

func (*Service) DeleteByID

func (s *Service) DeleteByID(ctx context.Context, id string) error

DeleteByID deletes a model by its internal UUID

func (*Service) DeleteByModelID

func (s *Service) DeleteByModelID(ctx context.Context, modelID string) error

DeleteByModelID deletes a model by its model_id field

Example
package main

import ()

func main() {
	// Example usage
	// service := models.NewService(queries)

	// ctx := context.Background()
	// err := service.DeleteByModelID(ctx, "gpt-4")
	// if err != nil {
	// 	// handle error
	// }
	// fmt.Println("Model deleted successfully")
}

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id string) (GetResponse, error)

GetByID retrieves a model by its internal UUID

func (*Service) GetByModelID

func (s *Service) GetByModelID(ctx context.Context, modelID string) (GetResponse, error)

GetByModelID retrieves a model by its model_id field

Example
package main

import ()

func main() {
	// Example usage
	// service := models.NewService(queries)

	// ctx := context.Background()
	// resp, err := service.GetByModelID(ctx, "gpt-4")
	// if err != nil {
	// 	// handle error
	// }
	// fmt.Printf("Model: %+v\n", resp.Model)
}

func (*Service) List

func (s *Service) List(ctx context.Context) ([]GetResponse, error)

List returns all models

Example
package main

import ()

func main() {
	// Example usage
	// service := models.NewService(queries)

	// ctx := context.Background()
	// models, err := service.List(ctx)
	// if err != nil {
	// 	// handle error
	// }
	// for _, model := range models {
	// 	fmt.Printf("Model ID: %s, Type: %s\n", model.ModelID, model.Type)
	// }
}

func (*Service) ListByClientType

func (s *Service) ListByClientType(ctx context.Context, clientType ClientType) ([]GetResponse, error)

ListByClientType returns models filtered by client type

func (*Service) ListByProviderID

func (s *Service) ListByProviderID(ctx context.Context, providerID string) ([]GetResponse, error)

ListByProviderID returns models filtered by provider ID.

func (*Service) ListByProviderIDAndType

func (s *Service) ListByProviderIDAndType(ctx context.Context, providerID string, modelType ModelType) ([]GetResponse, error)

ListByProviderIDAndType returns models filtered by provider ID and type.

func (*Service) ListByType

func (s *Service) ListByType(ctx context.Context, modelType ModelType) ([]GetResponse, error)

ListByType returns models filtered by type (chat or embedding)

Example
package main

import ()

func main() {
	// Example usage
	// service := models.NewService(queries)

	// ctx := context.Background()
	// chatModels, err := service.ListByType(ctx, models.ModelTypeChat)
	// if err != nil {
	// 	// handle error
	// }
	// fmt.Printf("Found %d chat models\n", len(chatModels))
}

func (*Service) UpdateByID

func (s *Service) UpdateByID(ctx context.Context, id string, req UpdateRequest) (GetResponse, error)

UpdateByID updates a model by its internal UUID

func (*Service) UpdateByModelID

func (s *Service) UpdateByModelID(ctx context.Context, modelID string, req UpdateRequest) (GetResponse, error)

UpdateByModelID updates a model by its model_id field

Example
package main

import ()

func main() {
	// Example usage
	// service := models.NewService(queries)

	// ctx := context.Background()
	// req := models.UpdateRequest{
	// 	ModelID:    "gpt-4",
	// 	Name:       "GPT-4 Turbo",
	// 	LlmProviderID: "11111111-1111-1111-1111-111111111111",
	// 	Type:       models.ModelTypeChat,
	// }

	// resp, err := service.UpdateByModelID(ctx, "gpt-4", req)
	// if err != nil {
	// 	// handle error
	// }
	// fmt.Printf("Updated model: %s\n", resp.ModelID)
}

type UpdateRequest

type UpdateRequest Model

Jump to

Keyboard shortcuts

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