Documentation
¶
Index ¶
- Constants
- Variables
- func FetchProviderByID(ctx context.Context, queries *sqlc.Queries, providerID string) (sqlc.LlmProvider, error)
- type AddRequest
- type AddResponse
- type ClientType
- type CountResponse
- type DeleteRequest
- type DeleteResponse
- type GetRequest
- type GetResponse
- type ListRequest
- type Model
- type ModelType
- type Service
- func (s *Service) Count(ctx context.Context) (int64, error)
- func (s *Service) CountByType(ctx context.Context, modelType ModelType) (int64, error)
- func (s *Service) Create(ctx context.Context, req AddRequest) (AddResponse, error)
- func (s *Service) DeleteByID(ctx context.Context, id string) error
- func (s *Service) DeleteByModelID(ctx context.Context, modelID string) error
- func (s *Service) GetByID(ctx context.Context, id string) (GetResponse, error)
- func (s *Service) GetByModelID(ctx context.Context, modelID string) (GetResponse, error)
- func (s *Service) List(ctx context.Context) ([]GetResponse, error)
- func (s *Service) ListByClientType(ctx context.Context, clientType ClientType) ([]GetResponse, error)
- func (s *Service) ListByProviderID(ctx context.Context, providerID string) ([]GetResponse, error)
- func (s *Service) ListByProviderIDAndType(ctx context.Context, providerID string, modelType ModelType) ([]GetResponse, error)
- func (s *Service) ListByType(ctx context.Context, modelType ModelType) ([]GetResponse, error)
- func (s *Service) UpdateByID(ctx context.Context, id string, req UpdateRequest) (GetResponse, error)
- func (s *Service) UpdateByModelID(ctx context.Context, modelID string, req UpdateRequest) (GetResponse, error)
- type UpdateRequest
Examples ¶
Constants ¶
const ( ModelInputText = "text" ModelInputImage = "image" ModelInputAudio = "audio" ModelInputVideo = "video" ModelInputFile = "file" )
Variables ¶
var ErrModelIDAlreadyExists = errors.New("model_id already exists")
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 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 DeleteResponse ¶
type DeleteResponse struct {
Message string `json:"message"`
}
type GetRequest ¶
type GetRequest struct {
ID string `json:"id"`
}
type GetResponse ¶
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 ¶
HasInputModality checks whether the model supports a given input modality.
func (*Model) IsMultimodal ¶
IsMultimodal returns true if the model supports any input modality beyond text.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides CRUD operations for models
func NewService ¶
NewService creates a new models service
func (*Service) CountByType ¶
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 ¶
DeleteByID deletes a model by its internal UUID
func (*Service) DeleteByModelID ¶
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) GetByModelID ¶
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 ¶
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 ¶
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