feat: golem15.golem plugin with the OpenAI-compatible adapter and AIService.Send
- Prompt, Payload and AIResponse value objects ported from Golem15.Golem - OpenAIAdapter: chat completions mapping with PHP's response_format, max_completion_tokens and reasoning_effort rules - AIService.Send through fetchguard (TrustedMode for operator models, PublicOnlyMode otherwise) with PHP's failure messages - config defaults for the SSRF allowlist and the AI timeout, lang, README
This commit is contained in:
37
classes/services/model_config.go
Normal file
37
classes/services/model_config.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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:"-"`
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user