Search might be useful for other agents
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/donseba/go-htmx"
|
"github.com/donseba/go-htmx"
|
||||||
"github.com/donseba/go-htmx/sse"
|
"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"
|
. "github.com/mudler/local-agent-framework/agent"
|
||||||
)
|
)
|
||||||
@@ -65,7 +65,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}),
|
}),
|
||||||
WithActions(actions.NewSearch()),
|
WithActions(external.NewSearch(3)),
|
||||||
WithAgentResultCallback(func(state ActionState) {
|
WithAgentResultCallback(func(state ActionState) {
|
||||||
text := fmt.Sprintf(`Reasoning: %s
|
text := fmt.Sprintf(`Reasoning: %s
|
||||||
Action taken: %+v
|
Action taken: %+v
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package action
|
package external
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -8,11 +8,14 @@ import (
|
|||||||
"github.com/sashabaranov/go-openai/jsonschema"
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewSearch() *SearchAction {
|
func NewSearch(results int) *SearchAction {
|
||||||
return &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) {
|
func (a *SearchAction) Run(params action.ActionParams) (string, error) {
|
||||||
result := struct {
|
result := struct {
|
||||||
@@ -25,7 +28,7 @@ func (a *SearchAction) Run(params action.ActionParams) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
ddg := client.NewDuckDuckGoSearchClient()
|
ddg := client.NewDuckDuckGoSearchClient()
|
||||||
res, err := ddg.SearchLimited(result.Query, 10)
|
res, err := ddg.SearchLimited(result.Query, a.results)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("error: %v", err)
|
msg := fmt.Sprintf("error: %v", err)
|
||||||
fmt.Printf(msg)
|
fmt.Printf(msg)
|
||||||
Reference in New Issue
Block a user