Add more actions, small fixups in the UI, add stop action
This commit is contained in:
2
external/githubissuecloser.go
vendored
2
external/githubissuecloser.go
vendored
@@ -24,7 +24,7 @@ func NewGithubIssueCloser(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCloser) Run(params action.ActionParams) (string, error) {
|
||||
func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
|
||||
2
external/githubissuelabeler.go
vendored
2
external/githubissuelabeler.go
vendored
@@ -36,7 +36,7 @@ func NewGithubIssueLabeler(ctx context.Context, config map[string]string) *Githu
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesLabeler) Run(params action.ActionParams) (string, error) {
|
||||
func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
|
||||
2
external/githubissueopener.go
vendored
2
external/githubissueopener.go
vendored
@@ -25,7 +25,7 @@ func NewGithubIssueOpener(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesOpener) Run(params action.ActionParams) (string, error) {
|
||||
func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"text"`
|
||||
|
||||
2
external/githubissuesearch.go
vendored
2
external/githubissuesearch.go
vendored
@@ -26,7 +26,7 @@ func NewGithubIssueSearch(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssueSearch) Run(params action.ActionParams) (string, error) {
|
||||
func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
Repository string `json:"repository"`
|
||||
|
||||
50
external/scraper.go
vendored
Normal file
50
external/scraper.go
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
package external
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/local-agent-framework/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/scraper"
|
||||
)
|
||||
|
||||
func NewScraper(config map[string]string) *ScraperAction {
|
||||
|
||||
return &ScraperAction{}
|
||||
}
|
||||
|
||||
type ScraperAction struct{}
|
||||
|
||||
func (a *ScraperAction) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
URL string `json:"url"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
scraper, err := scraper.New()
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
return scraper.Call(ctx, result.URL)
|
||||
}
|
||||
|
||||
func (a *ScraperAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "scrape",
|
||||
Description: "Scrapes a website and returns the site data.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"url": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The website URL.",
|
||||
},
|
||||
},
|
||||
Required: []string{"url"},
|
||||
}
|
||||
}
|
||||
22
external/search.go
vendored
22
external/search.go
vendored
@@ -1,12 +1,13 @@
|
||||
package external
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/mudler/local-agent-framework/action"
|
||||
"github.com/sap-nocops/duckduckgogo/client"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/duckduckgo"
|
||||
)
|
||||
|
||||
func NewSearch(config map[string]string) *SearchAction {
|
||||
@@ -21,13 +22,13 @@ func NewSearch(config map[string]string) *SearchAction {
|
||||
}
|
||||
}
|
||||
|
||||
slog.Info("Search action with results: ", intResult)
|
||||
slog.Info("Search action with results: ", "results", intResult)
|
||||
return &SearchAction{results: intResult}
|
||||
}
|
||||
|
||||
type SearchAction struct{ results int }
|
||||
|
||||
func (a *SearchAction) Run(params action.ActionParams) (string, error) {
|
||||
func (a *SearchAction) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
}{}
|
||||
@@ -37,20 +38,13 @@ func (a *SearchAction) Run(params action.ActionParams) (string, error) {
|
||||
|
||||
return "", err
|
||||
}
|
||||
ddg := client.NewDuckDuckGoSearchClient()
|
||||
res, err := ddg.SearchLimited(result.Query, a.results)
|
||||
ddg, err := duckduckgo.New(a.results, "LocalAgent")
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("error duckduckgo: %v", err)
|
||||
fmt.Printf(msg)
|
||||
return msg, err
|
||||
}
|
||||
fmt.Printf("error: %v", 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 "", err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
return ddg.Call(ctx, result.Query)
|
||||
}
|
||||
|
||||
func (a *SearchAction) Definition() action.ActionDefinition {
|
||||
|
||||
44
external/wikipedia.go
vendored
Normal file
44
external/wikipedia.go
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
package external
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/local-agent-framework/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/wikipedia"
|
||||
)
|
||||
|
||||
func NewWikipedia(config map[string]string) *WikipediaAction {
|
||||
return &WikipediaAction{}
|
||||
}
|
||||
|
||||
type WikipediaAction struct{}
|
||||
|
||||
func (a *WikipediaAction) Run(ctx context.Context, 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
|
||||
}
|
||||
wiki := wikipedia.New("LocalAgent")
|
||||
return wiki.Call(ctx, result.Query)
|
||||
}
|
||||
|
||||
func (a *WikipediaAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "wikipedia",
|
||||
Description: "Find wikipedia pages using the wikipedia api",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"query": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The website URL.",
|
||||
},
|
||||
},
|
||||
Required: []string{"query"},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user