chore(prompts): Rename Prompt blocks to Dynamic prompts

This commit is contained in:
Richard Palethorpe
2025-03-31 15:33:08 +01:00
parent 045fb1f8d6
commit 4c40e47e8d
8 changed files with 72 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ package services
import (
"encoding/json"
"github.com/mudler/LocalAgent/pkg/config"
"github.com/mudler/LocalAgent/pkg/xlog"
"github.com/mudler/LocalAgent/services/prompts"
@@ -11,7 +12,6 @@ import (
)
const (
// Connectors
DynamicPromptCustom = "custom"
)
@@ -19,10 +19,16 @@ var AvailableBlockPrompts = []string{
DynamicPromptCustom,
}
func PromptBlocks(a *state.AgentConfig) []agent.PromptBlock {
promptblocks := []agent.PromptBlock{}
func DynamicPromptsConfigMeta() []config.FieldGroup {
return []config.FieldGroup{
prompts.NewDynamicPromptConfigMeta(),
}
}
for _, c := range a.PromptBlocks {
func DynamicPrompts(a *state.AgentConfig) []agent.DynamicPrompt {
promptblocks := []agent.DynamicPrompt{}
for _, c := range a.DynamicPrompts {
var config map[string]string
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
xlog.Info("Error unmarshalling connector config", err)

View File

@@ -5,6 +5,7 @@ import (
"strings"
"github.com/mudler/LocalAgent/core/agent"
"github.com/mudler/LocalAgent/pkg/config"
"github.com/mudler/LocalAgent/pkg/xlog"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
@@ -48,6 +49,38 @@ func (a *DynamicPrompt) callInit() error {
return run()
}
func NewDynamicPromptConfigMeta() config.FieldGroup {
return config.FieldGroup {
Name: "custom",
Label: "Custom Prompt",
Fields: []config.Field{
{
Name: "name",
Label: "Name",
Type: config.FieldTypeText,
Required: true,
HelpText: "A unique name for your custom prompt",
Placeholder: "Enter a unique name",
},
{
Name: "code",
Label: "Go Code",
Type: config.FieldTypeTextarea,
Required: true,
HelpText: "Enter code that implements the Render and Role functions here",
Placeholder: "Write your Go code here",
},
{
Name: "unsafe",
Label: "Unsafe Code",
Type: config.FieldTypeCheckbox,
Required: false,
HelpText: "Enable if the code needs to use unsafe Go features",
},
},
}
}
func (a *DynamicPrompt) initializeInterpreter() error {
if _, exists := a.config["code"]; exists && a.i == nil {
unsafe := strings.ToLower(a.config["unsafe"]) == "true"