- golem15_golem_models (encrypted write-only api_key) with its cabana list and form under golem15.golem.access_settings, and the Settings lookups (Models, DefaultModel with PHP's position-0 quirk, Vision, Image, File, ByName), every one Trusted - golem:import-settings copies the WinterCMS golem_settings repeater once - AnthropicAdapter; SendStream, SendFile/SendFilePath/SendFileReader, SendWithModel, SendToImageModel, SendToVisionModel, GenerateImage, Ask - PromptFactory; README documents the config keys, the environment variable, the command and the admin screen
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
// Package services is the AI service of the golem15.golem plugin: the
|
|
// model configuration a call runs with, the admin-configured models and
|
|
// AIService, which sends prompts through the provider adapters.
|
|
package services
|
|
|
|
// ModelConfig is one AI model a call runs with (PHP's model config
|
|
// array): the adapter (openai or anthropic), the API key, the base URL ("" means
|
|
// the provider default), the model id and the model's default system
|
|
// prompt. Trusted is set only for models an operator configured in the
|
|
// admin: their calls may reach local-network endpoints (fetchguard
|
|
// TrustedMode). Every other config, such as a user's or an organisation's
|
|
// own key, runs guarded (fetchguard PublicOnlyMode). APIKey is a secret:
|
|
// never log or serialize a ModelConfig.
|
|
type ModelConfig struct {
|
|
Name string `json:"-"`
|
|
Adapter string `json:"-"`
|
|
APIKey string `json:"-"`
|
|
BaseURL string `json:"-"`
|
|
Model string `json:"-"`
|
|
SystemPrompt string `json:"-"`
|
|
MaxCompletionTokens int `json:"-"`
|
|
HasFilesEndpoint bool `json:"-"`
|
|
AcceptsImages bool `json:"-"`
|
|
GeneratesImages bool `json:"-"`
|
|
Trusted bool `json:"-"`
|
|
// Position is an admin model's place among all configured models
|
|
// (the WinterCMS repeater index); only the configs Models returns
|
|
// carry one.
|
|
Position int `json:"-"`
|
|
|
|
isDefault bool
|
|
}
|
|
|
|
// DefaultModelID is the model a config without one uses (PHP's
|
|
// `$config['model'] ?? 'gpt-4o'`).
|
|
const DefaultModelID = "gpt-4o"
|
|
|
|
func (c *ModelConfig) modelID(def string) string {
|
|
if c.Model == "" {
|
|
return def
|
|
}
|
|
return c.Model
|
|
}
|