This commit is contained in:
mudler
2024-03-31 23:06:28 +02:00
parent aa62d9ef9e
commit 3b1a54083d
6 changed files with 161 additions and 42 deletions

View File

@@ -36,18 +36,39 @@ func (ap ActionParams) String() string {
return string(b)
}
func (ap ActionParams) Unmarshal(v interface{}) error {
b, err := json.Marshal(ap)
if err != nil {
return err
}
if err := json.Unmarshal(b, v); err != nil {
return err
}
return nil
}
//type ActionDefinition openai.FunctionDefinition
type ActionDefinition struct {
Properties map[string]jsonschema.Definition
Required []string
Name string
Name ActionDefinitionName
Description string
}
type ActionDefinitionName string
func (a ActionDefinitionName) Is(name string) bool {
return string(a) == name
}
func (a ActionDefinitionName) String() string {
return string(a)
}
func (a ActionDefinition) ToFunctionDefinition() openai.FunctionDefinition {
return openai.FunctionDefinition{
Name: a.Name,
Name: a.Name.String(),
Description: a.Description,
Parameters: jsonschema.Definition{
Type: jsonschema.Object,

View File

@@ -23,7 +23,7 @@ func (a *IntentAction) Definition() ActionDefinition {
Properties: map[string]jsonschema.Definition{
"reasoning": {
Type: jsonschema.String,
Description: "The city and state, e.g. San Francisco, CA",
Description: "A detailed reasoning on why you want to call this tool.",
},
"tool": {
Type: jsonschema.String,

34
action/reply.go Normal file
View File

@@ -0,0 +1,34 @@
package action
import (
"github.com/sashabaranov/go-openai/jsonschema"
)
// ReplyActionName is the name of the reply action
// used by the LLM to reply to the user without
// any additional processing
const ReplyActionName = "reply"
func NewReply() *ReplyAction {
return &ReplyAction{}
}
type ReplyAction struct{}
func (a *ReplyAction) Run(ActionParams) (string, error) {
return "no-op", nil
}
func (a *ReplyAction) Definition() ActionDefinition {
return ActionDefinition{
Name: ReplyActionName,
Description: "Use this tool to reply to the user once we have all the informations we need.",
Properties: map[string]jsonschema.Definition{
"message": {
Type: jsonschema.String,
Description: "The message to reply with",
},
},
Required: []string{"message"},
}
}