reordering
This commit is contained in:
68
services/actions/browse.go
Normal file
68
services/actions/browse.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"jaytaylor.com/html2text"
|
||||
)
|
||||
|
||||
func NewBrowse(config map[string]string) *BrowseAction {
|
||||
|
||||
return &BrowseAction{}
|
||||
}
|
||||
|
||||
type BrowseAction struct{}
|
||||
|
||||
func (a *BrowseAction) 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
|
||||
}
|
||||
// download page with http.Client
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", result.URL, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
pagebyte, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
rendered, err := html2text.FromString(string(pagebyte), html2text.Options{PrettyTables: true})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("The webpage '%s' content is:\n%s", result.URL, rendered), nil
|
||||
}
|
||||
|
||||
func (a *BrowseAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "browse",
|
||||
Description: "Use this tool to visit an URL. It browse a website page and return the text content.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"url": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The website URL.",
|
||||
},
|
||||
},
|
||||
Required: []string{"url"},
|
||||
}
|
||||
}
|
||||
90
services/actions/githubissuecloser.go
Normal file
90
services/actions/githubissuecloser.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v61/github"
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
type GithubIssuesCloser struct {
|
||||
token string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
func NewGithubIssueCloser(ctx context.Context, config map[string]string) *GithubIssuesCloser {
|
||||
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||
return &GithubIssuesCloser{
|
||||
client: client,
|
||||
token: config["token"],
|
||||
context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
IssueNumber int `json:"issue_number"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
// _, _, err = g.client.Issues.CreateComment(
|
||||
// g.context,
|
||||
// result.Owner, result.Repository,
|
||||
// result.IssueNumber, &github.IssueComment{
|
||||
// //Body: &result.Text,
|
||||
// },
|
||||
// )
|
||||
// if err != nil {
|
||||
// fmt.Printf("error: %v", err)
|
||||
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
_, _, err = g.client.Issues.Edit(g.context, result.Owner, result.Repository, result.IssueNumber, &github.IssueRequest{
|
||||
State: github.String("closed"),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
resultString := fmt.Sprintf("Closed issue %d in repository %s/%s", result.IssueNumber, result.Owner, result.Repository)
|
||||
if err != nil {
|
||||
resultString = fmt.Sprintf("Error closing issue %d in repository %s/%s: %v", result.IssueNumber, result.Owner, result.Repository, err)
|
||||
}
|
||||
return resultString, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCloser) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "close_github_issue",
|
||||
Description: "Closes a Github issue.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"repository": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The repository to close the issue in.",
|
||||
},
|
||||
"owner": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The owner of the repository.",
|
||||
},
|
||||
"issue_number": {
|
||||
Type: jsonschema.Number,
|
||||
Description: "The issue number to close",
|
||||
},
|
||||
},
|
||||
Required: []string{"issue_number", "repository", "owner"},
|
||||
}
|
||||
}
|
||||
92
services/actions/githubissuelabeler.go
Normal file
92
services/actions/githubissuelabeler.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v61/github"
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
type GithubIssuesLabeler struct {
|
||||
token string
|
||||
availableLabels []string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
func NewGithubIssueLabeler(ctx context.Context, config map[string]string) *GithubIssuesLabeler {
|
||||
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||
|
||||
// Get available labels
|
||||
availableLabels := []string{"bug", "enhancement"}
|
||||
|
||||
if config["availableLabels"] != "" {
|
||||
availableLabels = strings.Split(config["availableLabels"], ",")
|
||||
}
|
||||
|
||||
return &GithubIssuesLabeler{
|
||||
client: client,
|
||||
token: config["token"],
|
||||
context: ctx,
|
||||
availableLabels: availableLabels,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
Label string `json:"label"`
|
||||
IssueNumber int `json:"issue_number"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
labels, _, err := g.client.Issues.AddLabelsToIssue(g.context, result.Owner, result.Repository, result.IssueNumber, []string{result.Label})
|
||||
//labelsNames := []string{}
|
||||
for _, l := range labels {
|
||||
slog.Info("Label added:", l.Name)
|
||||
//labelsNames = append(labelsNames, l.GetName())
|
||||
}
|
||||
|
||||
resultString := fmt.Sprintf("Added label '%s' to issue %d in repository %s/%s", result.Label, result.IssueNumber, result.Owner, result.Repository)
|
||||
if err != nil {
|
||||
resultString = fmt.Sprintf("Error adding label '%s' to issue %d in repository %s/%s: %v", result.Label, result.IssueNumber, result.Owner, result.Repository, err)
|
||||
}
|
||||
return resultString, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesLabeler) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "add_label_to_github_issue",
|
||||
Description: "Add a label to a Github issue. You might want to assign labels to issues to categorize them.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"issue_number": {
|
||||
Type: jsonschema.Number,
|
||||
Description: "The number of the issue to add the label to.",
|
||||
},
|
||||
"repository": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The repository to add the label to.",
|
||||
},
|
||||
"owner": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The owner of the repository.",
|
||||
},
|
||||
"label": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The label to add to the issue.",
|
||||
Enum: g.availableLabels,
|
||||
},
|
||||
},
|
||||
Required: []string{"issue_number", "repository", "owner", "label"},
|
||||
}
|
||||
}
|
||||
82
services/actions/githubissueopener.go
Normal file
82
services/actions/githubissueopener.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v61/github"
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
type GithubIssuesOpener struct {
|
||||
token string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
func NewGithubIssueOpener(ctx context.Context, config map[string]string) *GithubIssuesOpener {
|
||||
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||
|
||||
return &GithubIssuesOpener{
|
||||
client: client,
|
||||
token: config["token"],
|
||||
context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"text"`
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
issue := &github.IssueRequest{
|
||||
Title: &result.Title,
|
||||
Body: &result.Body,
|
||||
}
|
||||
|
||||
resultString := ""
|
||||
createdIssue, _, err := g.client.Issues.Create(g.context, result.Owner, result.Repository, issue)
|
||||
if err != nil {
|
||||
resultString = fmt.Sprintf("Error creating issue: %v", err)
|
||||
} else {
|
||||
resultString = fmt.Sprintf("Created issue %d in repository %s/%s", createdIssue.GetNumber(), result.Owner, result.Repository)
|
||||
}
|
||||
|
||||
return resultString, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesOpener) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "create_github_issue",
|
||||
Description: "Create a new issue on a GitHub repository.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"text": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The text of the new issue",
|
||||
},
|
||||
"title": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The title of the issue.",
|
||||
},
|
||||
"owner": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The owner of the repository.",
|
||||
},
|
||||
"repository": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The repository where to create the issue.",
|
||||
},
|
||||
},
|
||||
Required: []string{"title", "text", "owner", "repository"},
|
||||
}
|
||||
}
|
||||
83
services/actions/githubissuesearch.go
Normal file
83
services/actions/githubissuesearch.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/google/go-github/v61/github"
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
type GithubIssueSearch struct {
|
||||
token string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
func NewGithubIssueSearch(ctx context.Context, config map[string]string) *GithubIssueSearch {
|
||||
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||
|
||||
return &GithubIssueSearch{
|
||||
client: client,
|
||||
token: config["token"],
|
||||
context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("%s in:%s user:%s", result.Query, result.Repository, result.Owner)
|
||||
resultString := ""
|
||||
issues, _, err := g.client.Search.Issues(g.context, query, &github.SearchOptions{
|
||||
ListOptions: github.ListOptions{PerPage: 5},
|
||||
Order: "desc",
|
||||
//Sort: "created",
|
||||
})
|
||||
if err != nil {
|
||||
resultString = fmt.Sprintf("Error listing issues: %v", err)
|
||||
return resultString, err
|
||||
}
|
||||
for _, i := range issues.Issues {
|
||||
slog.Info("Issue found:", i.GetTitle())
|
||||
resultString += fmt.Sprintf("Issue found: %s\n", i.GetTitle())
|
||||
resultString += fmt.Sprintf("URL: %s\n", i.GetHTMLURL())
|
||||
// resultString += fmt.Sprintf("Body: %s\n", i.GetBody())
|
||||
}
|
||||
|
||||
return resultString, err
|
||||
}
|
||||
|
||||
func (g *GithubIssueSearch) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "search_github_issue",
|
||||
Description: "Search between github issues",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"query": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The text to search for",
|
||||
},
|
||||
"repository": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The repository to search in",
|
||||
},
|
||||
"owner": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The owner of the repository",
|
||||
},
|
||||
},
|
||||
Required: []string{"text", "repository", "owner"},
|
||||
}
|
||||
}
|
||||
50
services/actions/scrape.go
Normal file
50
services/actions/scrape.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/local-agent-framework/core/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 full website content and returns the entire site data.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"url": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The website URL.",
|
||||
},
|
||||
},
|
||||
Required: []string{"url"},
|
||||
}
|
||||
}
|
||||
62
services/actions/search.go
Normal file
62
services/actions/search.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/duckduckgo"
|
||||
)
|
||||
|
||||
func NewSearch(config map[string]string) *SearchAction {
|
||||
results := config["results"]
|
||||
intResult := 1
|
||||
|
||||
// decode int from string
|
||||
if results != "" {
|
||||
_, err := fmt.Sscanf(results, "%d", &intResult)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
slog.Info("Search action with results: ", "results", intResult)
|
||||
return &SearchAction{results: intResult}
|
||||
}
|
||||
|
||||
type SearchAction struct{ results int }
|
||||
|
||||
func (a *SearchAction) 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
|
||||
}
|
||||
ddg, err := duckduckgo.New(a.results, "LocalAgent")
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
return ddg.Call(ctx, result.Query)
|
||||
}
|
||||
|
||||
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"},
|
||||
}
|
||||
}
|
||||
78
services/actions/sendmail.go
Normal file
78
services/actions/sendmail.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
|
||||
"github.com/mudler/local-agent-framework/core/action"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
func NewSendMail(config map[string]string) *SendMailAction {
|
||||
return &SendMailAction{
|
||||
username: config["username"],
|
||||
password: config["password"],
|
||||
email: config["email"],
|
||||
smtpHost: config["smtpHost"],
|
||||
smtpPort: config["smtpPort"],
|
||||
}
|
||||
}
|
||||
|
||||
type SendMailAction struct {
|
||||
username string
|
||||
password string
|
||||
email string
|
||||
smtpHost string
|
||||
smtpPort string
|
||||
}
|
||||
|
||||
func (a *SendMailAction) Run(ctx context.Context, params action.ActionParams) (string, error) {
|
||||
result := struct {
|
||||
Message string `json:"message"`
|
||||
To string `json:"to"`
|
||||
Subject string `json:"subject"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Authentication.
|
||||
auth := smtp.PlainAuth("", a.email, a.password, a.smtpHost)
|
||||
|
||||
// Sending email.
|
||||
err = smtp.SendMail(
|
||||
fmt.Sprintf("%s:%s", a.smtpHost, a.smtpPort),
|
||||
auth, a.email, []string{
|
||||
result.To,
|
||||
}, []byte(result.Message))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("Email sent to %s", result.To), nil
|
||||
}
|
||||
|
||||
func (a *SendMailAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
Name: "send_email",
|
||||
Description: "Send an email.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"to": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The email address to send the email to.",
|
||||
},
|
||||
"subject": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The subject of the email.",
|
||||
},
|
||||
"message": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The message to send.",
|
||||
},
|
||||
},
|
||||
Required: []string{"to", "subject", "message"},
|
||||
}
|
||||
}
|
||||
44
services/actions/wikipedia.go
Normal file
44
services/actions/wikipedia.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/local-agent-framework/core/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