chore(prompts): Rename Prompt blocks to Dynamic prompts
This commit is contained in:
@@ -39,7 +39,7 @@ type options struct {
|
|||||||
kbResults int
|
kbResults int
|
||||||
ragdb RAGDB
|
ragdb RAGDB
|
||||||
|
|
||||||
prompts []PromptBlock
|
prompts []DynamicPrompt
|
||||||
|
|
||||||
systemPrompt string
|
systemPrompt string
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ func WithCharacterFile(path string) Option {
|
|||||||
// WithPrompts adds additional block prompts to the agent
|
// WithPrompts adds additional block prompts to the agent
|
||||||
// to be rendered internally in the conversation
|
// to be rendered internally in the conversation
|
||||||
// when processing the conversation to the LLM
|
// when processing the conversation to the LLM
|
||||||
func WithPrompts(prompts ...PromptBlock) Option {
|
func WithPrompts(prompts ...DynamicPrompt) Option {
|
||||||
return func(o *options) error {
|
return func(o *options) error {
|
||||||
o.prompts = prompts
|
o.prompts = prompts
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package agent
|
package agent
|
||||||
|
|
||||||
type PromptBlock interface {
|
type DynamicPrompt interface {
|
||||||
Render(a *Agent) (string, error)
|
Render(a *Agent) (string, error)
|
||||||
Role() string
|
Role() string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,22 +18,22 @@ type ActionsConfig struct {
|
|||||||
Config string `json:"config"`
|
Config string `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PromptBlocksConfig struct {
|
type DynamicPromptsConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Config string `json:"config"`
|
Config string `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d PromptBlocksConfig) ToMap() map[string]string {
|
func (d DynamicPromptsConfig) ToMap() map[string]string {
|
||||||
config := map[string]string{}
|
config := map[string]string{}
|
||||||
json.Unmarshal([]byte(d.Config), &config)
|
json.Unmarshal([]byte(d.Config), &config)
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
type AgentConfig struct {
|
type AgentConfig struct {
|
||||||
Connector []ConnectorConfig `json:"connectors" form:"connectors" `
|
Connector []ConnectorConfig `json:"connectors" form:"connectors" `
|
||||||
Actions []ActionsConfig `json:"actions" form:"actions"`
|
Actions []ActionsConfig `json:"actions" form:"actions"`
|
||||||
PromptBlocks []PromptBlocksConfig `json:"promptblocks" form:"promptblocks"`
|
DynamicPrompts []DynamicPromptsConfig `json:"dynamic_prompts" form:"dynamic_prompts"`
|
||||||
MCPServers []agent.MCPServer `json:"mcp_servers" form:"mcp_servers"`
|
MCPServers []agent.MCPServer `json:"mcp_servers" form:"mcp_servers"`
|
||||||
|
|
||||||
Description string `json:"description" form:"description"`
|
Description string `json:"description" form:"description"`
|
||||||
|
|
||||||
@@ -63,14 +63,18 @@ type AgentConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AgentConfigMeta struct {
|
type AgentConfigMeta struct {
|
||||||
Fields []config.Field
|
Fields []config.Field
|
||||||
Connectors []config.FieldGroup
|
Connectors []config.FieldGroup
|
||||||
Actions []config.FieldGroup
|
Actions []config.FieldGroup
|
||||||
PromptBlocks []config.Field
|
DynamicPrompts []config.FieldGroup
|
||||||
MCPServers []config.Field
|
MCPServers []config.Field
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAgentConfigMeta(actionsConfig []config.FieldGroup, connectorsConfig []config.FieldGroup) AgentConfigMeta {
|
func NewAgentConfigMeta(
|
||||||
|
actionsConfig []config.FieldGroup,
|
||||||
|
connectorsConfig []config.FieldGroup,
|
||||||
|
dynamicPromptsConfig []config.FieldGroup,
|
||||||
|
) AgentConfigMeta {
|
||||||
return AgentConfigMeta{
|
return AgentConfigMeta{
|
||||||
Fields: []config.Field{
|
Fields: []config.Field{
|
||||||
{
|
{
|
||||||
@@ -261,9 +265,9 @@ func NewAgentConfigMeta(actionsConfig []config.FieldGroup, connectorsConfig []co
|
|||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PromptBlocks: []config.Field{},
|
DynamicPrompts: dynamicPromptsConfig,
|
||||||
Connectors: connectorsConfig,
|
Connectors: connectorsConfig,
|
||||||
Actions: actionsConfig,
|
Actions: actionsConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type AgentPool struct {
|
|||||||
imageModel, localRAGAPI, localRAGKey, apiKey string
|
imageModel, localRAGAPI, localRAGKey, apiKey string
|
||||||
availableActions func(*AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action
|
availableActions func(*AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action
|
||||||
connectors func(*AgentConfig) []Connector
|
connectors func(*AgentConfig) []Connector
|
||||||
promptBlocks func(*AgentConfig) []PromptBlock
|
dynamicPrompt func(*AgentConfig) []DynamicPrompt
|
||||||
timeout string
|
timeout string
|
||||||
conversationLogs string
|
conversationLogs string
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ func NewAgentPool(
|
|||||||
LocalRAGAPI string,
|
LocalRAGAPI string,
|
||||||
availableActions func(*AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action,
|
availableActions func(*AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action,
|
||||||
connectors func(*AgentConfig) []Connector,
|
connectors func(*AgentConfig) []Connector,
|
||||||
promptBlocks func(*AgentConfig) []PromptBlock,
|
promptBlocks func(*AgentConfig) []DynamicPrompt,
|
||||||
timeout string,
|
timeout string,
|
||||||
withLogs bool,
|
withLogs bool,
|
||||||
) (*AgentPool, error) {
|
) (*AgentPool, error) {
|
||||||
@@ -107,7 +107,7 @@ func NewAgentPool(
|
|||||||
managers: make(map[string]sse.Manager),
|
managers: make(map[string]sse.Manager),
|
||||||
connectors: connectors,
|
connectors: connectors,
|
||||||
availableActions: availableActions,
|
availableActions: availableActions,
|
||||||
promptBlocks: promptBlocks,
|
dynamicPrompt: promptBlocks,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
conversationLogs: conversationPath,
|
conversationLogs: conversationPath,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -131,7 +131,7 @@ func NewAgentPool(
|
|||||||
pool: *poolData,
|
pool: *poolData,
|
||||||
connectors: connectors,
|
connectors: connectors,
|
||||||
localRAGAPI: LocalRAGAPI,
|
localRAGAPI: LocalRAGAPI,
|
||||||
promptBlocks: promptBlocks,
|
dynamicPrompt: promptBlocks,
|
||||||
availableActions: availableActions,
|
availableActions: availableActions,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
conversationLogs: conversationPath,
|
conversationLogs: conversationPath,
|
||||||
@@ -303,7 +303,7 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
connectors := a.connectors(config)
|
connectors := a.connectors(config)
|
||||||
promptBlocks := a.promptBlocks(config)
|
promptBlocks := a.dynamicPrompt(config)
|
||||||
actions := a.availableActions(config)(ctx, a)
|
actions := a.availableActions(config)(ctx, a)
|
||||||
stateFile, characterFile := a.stateFiles(name)
|
stateFile, characterFile := a.stateFiles(name)
|
||||||
|
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -62,7 +62,7 @@ func main() {
|
|||||||
localRAG,
|
localRAG,
|
||||||
services.Actions,
|
services.Actions,
|
||||||
services.Connectors,
|
services.Connectors,
|
||||||
services.PromptBlocks,
|
services.DynamicPrompts,
|
||||||
timeout,
|
timeout,
|
||||||
withLogs,
|
withLogs,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/mudler/LocalAgent/pkg/config"
|
||||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||||
"github.com/mudler/LocalAgent/services/prompts"
|
"github.com/mudler/LocalAgent/services/prompts"
|
||||||
|
|
||||||
@@ -11,7 +12,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Connectors
|
|
||||||
DynamicPromptCustom = "custom"
|
DynamicPromptCustom = "custom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,10 +19,16 @@ var AvailableBlockPrompts = []string{
|
|||||||
DynamicPromptCustom,
|
DynamicPromptCustom,
|
||||||
}
|
}
|
||||||
|
|
||||||
func PromptBlocks(a *state.AgentConfig) []agent.PromptBlock {
|
func DynamicPromptsConfigMeta() []config.FieldGroup {
|
||||||
promptblocks := []agent.PromptBlock{}
|
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
|
var config map[string]string
|
||||||
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
||||||
xlog.Info("Error unmarshalling connector config", err)
|
xlog.Info("Error unmarshalling connector config", err)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mudler/LocalAgent/core/agent"
|
"github.com/mudler/LocalAgent/core/agent"
|
||||||
|
"github.com/mudler/LocalAgent/pkg/config"
|
||||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||||
"github.com/traefik/yaegi/interp"
|
"github.com/traefik/yaegi/interp"
|
||||||
"github.com/traefik/yaegi/stdlib"
|
"github.com/traefik/yaegi/stdlib"
|
||||||
@@ -48,6 +49,38 @@ func (a *DynamicPrompt) callInit() error {
|
|||||||
return run()
|
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 {
|
func (a *DynamicPrompt) initializeInterpreter() error {
|
||||||
if _, exists := a.config["code"]; exists && a.i == nil {
|
if _, exists := a.config["code"]; exists && a.i == nil {
|
||||||
unsafe := strings.ToLower(a.config["unsafe"]) == "true"
|
unsafe := strings.ToLower(a.config["unsafe"]) == "true"
|
||||||
|
|||||||
@@ -607,6 +607,7 @@ func (a *App) GetAgentConfigMeta() func(c *fiber.Ctx) error {
|
|||||||
configMeta := state.NewAgentConfigMeta(
|
configMeta := state.NewAgentConfigMeta(
|
||||||
services.ActionsConfigMeta(),
|
services.ActionsConfigMeta(),
|
||||||
services.ConnectorsConfigMeta(),
|
services.ConnectorsConfigMeta(),
|
||||||
|
services.DynamicPromptsConfigMeta(),
|
||||||
)
|
)
|
||||||
return c.JSON(configMeta)
|
return c.JSON(configMeta)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user