Move custom action into actions
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package agent
|
||||
package action
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/mudler/local-agent-framework/action"
|
||||
"github.com/mudler/local-agent-framework/xlog"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/traefik/yaegi/interp"
|
||||
@@ -76,7 +75,7 @@ func (a *CustomAction) initializeInterpreter() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *CustomAction) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
func (a *CustomAction) Run(ctx context.Context, params ActionParams) (string, error) {
|
||||
v, err := a.i.Eval(fmt.Sprintf("%s.Run", a.config["name"]))
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -87,12 +86,12 @@ func (a *CustomAction) Run(ctx context.Context, params action.ActionParams) (str
|
||||
return run(params)
|
||||
}
|
||||
|
||||
func (a *CustomAction) Definition() action.ActionDefinition {
|
||||
func (a *CustomAction) Definition() ActionDefinition {
|
||||
|
||||
v, err := a.i.Eval(fmt.Sprintf("%s.Definition", a.config["name"]))
|
||||
if err != nil {
|
||||
xlog.Error("Error getting custom action definition", "error", err)
|
||||
return action.ActionDefinition{}
|
||||
return ActionDefinition{}
|
||||
}
|
||||
|
||||
properties := v.Interface().(func() map[string][]string)
|
||||
@@ -100,7 +99,7 @@ func (a *CustomAction) Definition() action.ActionDefinition {
|
||||
v, err = a.i.Eval(fmt.Sprintf("%s.RequiredFields", a.config["name"]))
|
||||
if err != nil {
|
||||
xlog.Error("Error getting custom action definition", "error", err)
|
||||
return action.ActionDefinition{}
|
||||
return ActionDefinition{}
|
||||
}
|
||||
|
||||
requiredFields := v.Interface().(func() []string)
|
||||
@@ -117,8 +116,8 @@ func (a *CustomAction) Definition() action.ActionDefinition {
|
||||
Description: v[1],
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(a.config["name"]),
|
||||
return ActionDefinition{
|
||||
Name: ActionDefinitionName(a.config["name"]),
|
||||
Description: a.config["description"],
|
||||
Properties: prop,
|
||||
Required: requiredFields(),
|
||||
@@ -1,10 +1,9 @@
|
||||
package agent_test
|
||||
package action_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mudler/local-agent-framework/action"
|
||||
. "github.com/mudler/local-agent-framework/agent"
|
||||
. "github.com/mudler/local-agent-framework/action"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
@@ -64,7 +63,7 @@ return []string{"foo"}
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
definition := customAction.Definition()
|
||||
Expect(definition).To(Equal(action.ActionDefinition{
|
||||
Expect(definition).To(Equal(ActionDefinition{
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"foo": {
|
||||
Type: jsonschema.String,
|
||||
@@ -76,7 +75,7 @@ return []string{"foo"}
|
||||
Description: "A test action",
|
||||
}))
|
||||
|
||||
runResult, err := customAction.Run(context.Background(), action.ActionParams{
|
||||
runResult, err := customAction.Run(context.Background(), ActionParams{
|
||||
"Foo": "bar",
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -106,7 +106,7 @@ func (a *FakeInternetAction) Definition() action.ActionDefinition {
|
||||
|
||||
var _ = Describe("Agent test", func() {
|
||||
Context("jobs", func() {
|
||||
FIt("pick the correct action", func() {
|
||||
It("pick the correct action", func() {
|
||||
agent, err := New(
|
||||
WithLLMAPIURL(apiModel),
|
||||
WithModel(testModel),
|
||||
|
||||
Reference in New Issue
Block a user