Search might be useful for other agents
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/local-agent-framework/action"
|
||||
"github.com/sap-nocops/duckduckgogo/client"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
func NewSearch() *SearchAction {
|
||||
return &SearchAction{}
|
||||
}
|
||||
|
||||
type SearchAction struct{}
|
||||
|
||||
func (a *SearchAction) Run(params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
ddg := client.NewDuckDuckGoSearchClient()
|
||||
res, err := ddg.SearchLimited(result.Query, 10)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("error: %v", err)
|
||||
fmt.Printf(msg)
|
||||
return msg, err
|
||||
}
|
||||
|
||||
results := ""
|
||||
for i, r := range res {
|
||||
results += fmt.Sprintf("*********** RESULT %d\nurl: %s\ntitle: %s\nsnippet: %s\n", i, r.FormattedUrl, r.Title, r.Snippet)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (a *SearchAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "search_internet",
|
||||
Description: "Search the internet for something.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"query": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The query to search for.",
|
||||
},
|
||||
},
|
||||
Required: []string{"query"},
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user