Documentation
¶
Index ¶
- type CompletionRequest
- type CompletionResponse
- type Loader
- type Message
- type Model
- type Provider
- type Service
- func (s *Service) GetExternalProvider(name string) (*models.ExternalLLMProvider, error)
- func (s *Service) GetProvider(name string) (Provider, error)
- func (s *Service) InstallExternalProvider(req *models.ExternalLLMProviderInstallRequest) (*models.ExternalLLMProvider, error)
- func (s *Service) IsEnabled() bool
- func (s *Service) LabelEntityTypes(ctx context.Context, names []string, sourceName string, contextCols []string) map[string]string
- func (s *Service) ListExternalProviders() ([]*models.ExternalLLMProvider, error)
- func (s *Service) ListModels(ctx context.Context) ([]Model, error)
- func (s *Service) ListRegisteredProviders() []string
- func (s *Service) LoadInstalledExternalProviders() error
- func (s *Service) ProviderName() string
- func (s *Service) RegisterProvider(name string, p Provider)
- func (s *Service) SetActiveProvider(p Provider, defaultModel string)
- func (s *Service) UninstallExternalProvider(name string) error
- func (s *Service) WithLoader(loader *Loader) *Service
- func (s *Service) WithStore(store metadatastore.MetadataStore) *Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompletionRequest ¶
CompletionRequest describes a chat-completion call.
type CompletionResponse ¶
CompletionResponse holds the result of a chat-completion call.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader compiles and loads external LLM providers at runtime. It mirrors the approach used by storage.PluginLoader:
- Clone the Git repository.
- Flatten the optional actions/ subdirectory to the root.
- Remove the provider's go.mod/go.sum (the host module is used instead).
- Compile with go build -buildmode=plugin using the host module at appDir.
- Open the resulting .so and resolve the "Plugin" symbol (a Provider).
Compiled .so files are cached at cacheDir so restarts do not require recompilation (unless the provider was updated).
func NewLoader ¶
NewLoader creates a Loader.
- appDir: the directory that contains the host go.mod (usually /app).
- cacheDir: where compiled .so files are cached between runs.
- tempDir: temporary directory for git clones (cleaned up after each compile).
func (*Loader) CompileAndLoad ¶
CompileAndLoad clones repoURL at commitHash (or gitRef if commitHash is empty), compiles the provider, and returns a loaded Provider. If a valid cached .so already exists for commitHash it is used directly.
type Message ¶
type Message struct {
Role string `json:"role"` // "system" | "user" | "assistant"
Content string `json:"content"`
}
Message is a single turn in a chat conversation.
type Model ¶
type Model struct {
ID string `json:"id"`
Name string `json:"name"`
ContextLength int `json:"context_length"`
IsFree bool `json:"is_free"`
ProviderName string `json:"provider_name"`
}
Model represents an LLM model available from a provider.
type Provider ¶
type Provider interface {
// Name returns a human-readable identifier for this provider.
Name() string
// ListModels fetches the live model catalogue. No caching is applied here;
// caching is handled by Service.
ListModels(ctx context.Context) ([]Model, error)
// Complete sends a chat-completion request and returns the response.
Complete(ctx context.Context, req CompletionRequest) (CompletionResponse, error)
}
Provider is the interface that all LLM back-ends must implement.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service wraps a Provider with a TTL model cache and graceful degradation. A nil *Service is safe to use — all methods check the receiver.
func NewService ¶
NewService creates a Service backed by provider. When enabled is false the service is present but all operations are no-ops.
func (*Service) GetExternalProvider ¶
func (s *Service) GetExternalProvider(name string) (*models.ExternalLLMProvider, error)
GetExternalProvider returns metadata for a single external LLM provider.
func (*Service) GetProvider ¶
GetProvider retrieves a provider from the registry by name.
func (*Service) InstallExternalProvider ¶
func (s *Service) InstallExternalProvider(req *models.ExternalLLMProviderInstallRequest) (*models.ExternalLLMProvider, error)
InstallExternalProvider clones, compiles, and registers an LLM provider from a Git repository. The metadata is persisted so it survives restarts.
func (*Service) IsEnabled ¶
IsEnabled returns true when the service is configured and enabled. Safe to call on a nil receiver.
func (*Service) LabelEntityTypes ¶
func (s *Service) LabelEntityTypes(ctx context.Context, names []string, sourceName string, contextCols []string) map[string]string
LabelEntityTypes assigns a PascalCase entity type to each name in names by batching them into groups of labelBatchSize and calling the LLM. It NEVER returns an error — failures are logged and a partial/empty map is returned so the caller can always proceed with heuristic behaviour.
func (*Service) ListExternalProviders ¶
func (s *Service) ListExternalProviders() ([]*models.ExternalLLMProvider, error)
ListExternalProviders returns all persisted external LLM provider records.
func (*Service) ListModels ¶
ListModels returns the cached model list, refreshing it when the TTL has expired. Uses double-checked locking: fast read path avoids write lock.
func (*Service) ListRegisteredProviders ¶
ListRegisteredProviders returns the names of all registered providers.
func (*Service) LoadInstalledExternalProviders ¶
LoadInstalledExternalProviders re-registers all persisted external LLM providers on startup. If a cached .so exists it is used directly; otherwise the provider is recompiled from its recorded repository URL and commit hash.
func (*Service) ProviderName ¶
ProviderName returns the provider name, or "none" when not enabled.
func (*Service) RegisterProvider ¶
RegisterProvider adds a named provider to the in-memory registry.
func (*Service) SetActiveProvider ¶
SetActiveProvider switches the service to the given provider without rebuilding the registry, store, or loader attachments.
func (*Service) UninstallExternalProvider ¶
UninstallExternalProvider removes the provider from the live registry and deletes its persisted metadata. The .so file is removed from the cache. Note: Go plugins cannot be unloaded from memory; a process restart is needed for removal to take full effect on in-flight calls.
func (*Service) WithLoader ¶
WithLoader attaches a Loader for dynamic provider compilation.
func (*Service) WithStore ¶
func (s *Service) WithStore(store metadatastore.MetadataStore) *Service
WithStore attaches a MetadataStore for external provider persistence.