From 899e3c0771716f7fe9252fb674fe7568fc2d1186 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Fri, 5 Apr 2024 23:59:48 +0200 Subject: [PATCH] Search might be useful for other agents --- example/webui/main.go | 4 ++-- {example/webui/actions => external}/search.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) rename {example/webui/actions => external}/search.go (82%) diff --git a/example/webui/main.go b/example/webui/main.go index b36a90e..33c25dd 100644 --- a/example/webui/main.go +++ b/example/webui/main.go @@ -12,7 +12,7 @@ import ( "github.com/donseba/go-htmx" "github.com/donseba/go-htmx/sse" - actions "github.com/mudler/local-agent-framework/example/webui/actions" + external "github.com/mudler/local-agent-framework/external" . "github.com/mudler/local-agent-framework/agent" ) @@ -65,7 +65,7 @@ func main() { ) return true }), - WithActions(actions.NewSearch()), + WithActions(external.NewSearch(3)), WithAgentResultCallback(func(state ActionState) { text := fmt.Sprintf(`Reasoning: %s Action taken: %+v diff --git a/example/webui/actions/search.go b/external/search.go similarity index 82% rename from example/webui/actions/search.go rename to external/search.go index 7230e28..865c470 100644 --- a/example/webui/actions/search.go +++ b/external/search.go @@ -1,4 +1,4 @@ -package action +package external import ( "fmt" @@ -8,11 +8,14 @@ import ( "github.com/sashabaranov/go-openai/jsonschema" ) -func NewSearch() *SearchAction { - return &SearchAction{} +func NewSearch(results int) *SearchAction { + if results == 0 { + results = 3 + } + return &SearchAction{results: results} } -type SearchAction struct{} +type SearchAction struct{ results int } func (a *SearchAction) Run(params action.ActionParams) (string, error) { result := struct { @@ -25,7 +28,7 @@ func (a *SearchAction) Run(params action.ActionParams) (string, error) { return "", err } ddg := client.NewDuckDuckGoSearchClient() - res, err := ddg.SearchLimited(result.Query, 10) + res, err := ddg.SearchLimited(result.Query, a.results) if err != nil { msg := fmt.Sprintf("error: %v", err) fmt.Printf(msg)