Finish moving types
This commit is contained in:
committed by
Ettore Di Giacinto
parent
f0b8bfb4f4
commit
75a8d63e83
@@ -6,7 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"jaytaylor.com/html2text"
|
||||
)
|
||||
@@ -18,7 +18,7 @@ func NewBrowse(config map[string]string) *BrowseAction {
|
||||
|
||||
type BrowseAction struct{}
|
||||
|
||||
func (a *BrowseAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *BrowseAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
URL string `json:"url"`
|
||||
}{}
|
||||
@@ -26,35 +26,35 @@ func (a *BrowseAction) Run(ctx context.Context, params action.ActionParams) (act
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
// download page with http.Client
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", result.URL, nil)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
pagebyte, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
rendered, err := html2text.FromString(string(pagebyte), html2text.Options{PrettyTables: true})
|
||||
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: fmt.Sprintf("The webpage '%s' content is:\n%s", result.URL, rendered)}, nil
|
||||
return types.ActionResult{Result: fmt.Sprintf("The webpage '%s' content is:\n%s", result.URL, rendered)}, nil
|
||||
}
|
||||
|
||||
func (a *BrowseAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *BrowseAction) Definition() types.ActionDefinition {
|
||||
return types.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{
|
||||
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/core/state"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
@@ -21,7 +20,7 @@ type CallAgentAction struct {
|
||||
pool *state.AgentPool
|
||||
}
|
||||
|
||||
func (a *CallAgentAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *CallAgentAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
AgentName string `json:"agent_name"`
|
||||
Message string `json:"message"`
|
||||
@@ -30,16 +29,16 @@ func (a *CallAgentAction) Run(ctx context.Context, params action.ActionParams) (
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
ag := a.pool.GetAgent(result.AgentName)
|
||||
if ag == nil {
|
||||
return action.ActionResult{}, fmt.Errorf("agent '%s' not found", result.AgentName)
|
||||
return types.ActionResult{}, fmt.Errorf("agent '%s' not found", result.AgentName)
|
||||
}
|
||||
|
||||
resp := ag.Ask(
|
||||
agent.WithConversationHistory(
|
||||
types.WithConversationHistory(
|
||||
[]openai.ChatCompletionMessage{
|
||||
{
|
||||
Role: "user",
|
||||
@@ -49,13 +48,13 @@ func (a *CallAgentAction) Run(ctx context.Context, params action.ActionParams) (
|
||||
),
|
||||
)
|
||||
if resp.Error != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: resp.Response}, nil
|
||||
return types.ActionResult{Result: resp.Response}, nil
|
||||
}
|
||||
|
||||
func (a *CallAgentAction) Definition() action.ActionDefinition {
|
||||
func (a *CallAgentAction) Definition() types.ActionDefinition {
|
||||
allAgents := a.pool.AllAgents()
|
||||
|
||||
description := "Use this tool to call another agent. Available agents and their roles are:"
|
||||
@@ -68,7 +67,7 @@ func (a *CallAgentAction) Definition() action.ActionDefinition {
|
||||
description += fmt.Sprintf("\n- %s: %s", agent, agentConfig.Description)
|
||||
}
|
||||
|
||||
return action.ActionDefinition{
|
||||
return types.ActionDefinition{
|
||||
Name: "call_agent",
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func NewCounter(config map[string]string) *CounterAction {
|
||||
}
|
||||
|
||||
// Run executes the counter action
|
||||
func (a *CounterAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *CounterAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
// Parse parameters
|
||||
request := struct {
|
||||
Name string `json:"name"`
|
||||
@@ -32,11 +32,11 @@ func (a *CounterAction) Run(ctx context.Context, params action.ActionParams) (ac
|
||||
}{}
|
||||
|
||||
if err := params.Unmarshal(&request); err != nil {
|
||||
return action.ActionResult{}, fmt.Errorf("invalid parameters: %w", err)
|
||||
return types.ActionResult{}, fmt.Errorf("invalid parameters: %w", err)
|
||||
}
|
||||
|
||||
if request.Name == "" {
|
||||
return action.ActionResult{}, fmt.Errorf("counter name cannot be empty")
|
||||
return types.ActionResult{}, fmt.Errorf("counter name cannot be empty")
|
||||
}
|
||||
|
||||
a.mutex.Lock()
|
||||
@@ -63,7 +63,7 @@ func (a *CounterAction) Run(ctx context.Context, params action.ActionParams) (ac
|
||||
message = fmt.Sprintf("Current value of counter '%s' is %d", request.Name, newValue)
|
||||
}
|
||||
|
||||
return action.ActionResult{
|
||||
return types.ActionResult{
|
||||
Result: message,
|
||||
Metadata: map[string]any{
|
||||
"counter_name": request.Name,
|
||||
@@ -75,8 +75,8 @@ func (a *CounterAction) Run(ctx context.Context, params action.ActionParams) (ac
|
||||
}
|
||||
|
||||
// Definition returns the action definition
|
||||
func (a *CounterAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *CounterAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "counter",
|
||||
Description: "Create, update, or query named counters. Specify a name and an adjustment value (positive to increase, negative to decrease, zero to query).",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
@@ -28,18 +28,18 @@ type GenImageAction struct {
|
||||
imageModel string
|
||||
}
|
||||
|
||||
func (a *GenImageAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *GenImageAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Prompt string `json:"prompt"`
|
||||
Size string `json:"size"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if result.Prompt == "" {
|
||||
return action.ActionResult{}, fmt.Errorf("prompt is required")
|
||||
return types.ActionResult{}, fmt.Errorf("prompt is required")
|
||||
}
|
||||
|
||||
req := openai.ImageRequest{
|
||||
@@ -60,22 +60,22 @@ func (a *GenImageAction) Run(ctx context.Context, params action.ActionParams) (a
|
||||
|
||||
resp, err := a.client.CreateImage(ctx, req)
|
||||
if err != nil {
|
||||
return action.ActionResult{Result: "Failed to generate image " + err.Error()}, err
|
||||
return types.ActionResult{Result: "Failed to generate image " + err.Error()}, err
|
||||
}
|
||||
|
||||
if len(resp.Data) == 0 {
|
||||
return action.ActionResult{Result: "Failed to generate image"}, nil
|
||||
return types.ActionResult{Result: "Failed to generate image"}, nil
|
||||
}
|
||||
|
||||
return action.ActionResult{
|
||||
return types.ActionResult{
|
||||
Result: fmt.Sprintf("The image was generated and available at: %s", resp.Data[0].URL),
|
||||
Metadata: map[string]interface{}{
|
||||
MetadataImages: []string{resp.Data[0].URL},
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (a *GenImageAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *GenImageAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "generate_image",
|
||||
Description: "Generate image with.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
. "github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
|
||||
. "github.com/mudler/LocalAgent/services/actions"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -15,7 +15,7 @@ var _ = Describe("GenImageAction", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
action *GenImageAction
|
||||
params ActionParams
|
||||
params types.ActionParams
|
||||
config map[string]string
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ var _ = Describe("GenImageAction", func() {
|
||||
|
||||
Describe("Run", func() {
|
||||
It("should generate an image with valid prompt and size", func() {
|
||||
params = ActionParams{
|
||||
params = types.ActionParams{
|
||||
"prompt": "test prompt",
|
||||
"size": "256x256",
|
||||
}
|
||||
@@ -48,7 +48,7 @@ var _ = Describe("GenImageAction", func() {
|
||||
})
|
||||
|
||||
It("should return an error if the prompt is not provided", func() {
|
||||
params = ActionParams{
|
||||
params = types.ActionParams{
|
||||
"size": "256x256",
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ func NewGithubIssueCloser(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubIssuesCloser) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
@@ -37,7 +37,7 @@ func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" {
|
||||
@@ -67,24 +67,24 @@ func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, 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 action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCloser) Definition() action.ActionDefinition {
|
||||
func (g *GithubIssuesCloser) Definition() types.ActionDefinition {
|
||||
actionName := "close_github_issue"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: "Closes a Github issue.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"issue_number": {
|
||||
@@ -96,8 +96,8 @@ func (g *GithubIssuesCloser) Definition() action.ActionDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: "Closes a Github issue.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"repository": {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func NewGithubIssueCommenter(ctx context.Context, config map[string]string) *Git
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCommenter) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubIssuesCommenter) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
@@ -37,7 +37,7 @@ func (g *GithubIssuesCommenter) Run(ctx context.Context, params action.ActionPar
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
@@ -53,18 +53,18 @@ func (g *GithubIssuesCommenter) Run(ctx context.Context, params action.ActionPar
|
||||
if err != nil {
|
||||
resultString = fmt.Sprintf("Error adding comment to issue %d in repository %s/%s: %v", result.IssueNumber, result.Owner, result.Repository, err)
|
||||
}
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesCommenter) Definition() action.ActionDefinition {
|
||||
func (g *GithubIssuesCommenter) Definition() types.ActionDefinition {
|
||||
actionName := "add_comment_to_github_issue"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
description := "Add a comment to a Github issue to a repository."
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"issue_number": {
|
||||
@@ -79,8 +79,8 @@ func (g *GithubIssuesCommenter) Definition() action.ActionDefinition {
|
||||
Required: []string{"issue_number", "comment"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"issue_number": {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
@@ -39,7 +39,7 @@ func NewGithubIssueLabeler(ctx context.Context, config map[string]string) *Githu
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubIssuesLabeler) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
@@ -48,7 +48,7 @@ func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParam
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
@@ -67,17 +67,17 @@ func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParam
|
||||
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 action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesLabeler) Definition() action.ActionDefinition {
|
||||
func (g *GithubIssuesLabeler) Definition() types.ActionDefinition {
|
||||
actionName := "add_label_to_github_issue"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
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": {
|
||||
@@ -93,8 +93,8 @@ func (g *GithubIssuesLabeler) Definition() action.ActionDefinition {
|
||||
Required: []string{"issue_number", "label"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
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": {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func NewGithubIssueOpener(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubIssuesOpener) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"text"`
|
||||
@@ -39,7 +39,7 @@ func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
@@ -60,17 +60,17 @@ func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams
|
||||
resultString = fmt.Sprintf("Created issue %d in repository %s/%s: %s", createdIssue.GetNumber(), result.Owner, result.Repository, createdIssue.GetURL())
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesOpener) Definition() action.ActionDefinition {
|
||||
func (g *GithubIssuesOpener) Definition() types.ActionDefinition {
|
||||
actionName := "create_github_issue"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: "Create a new issue on a GitHub repository.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"text": {
|
||||
@@ -85,8 +85,8 @@ func (g *GithubIssuesOpener) Definition() action.ActionDefinition {
|
||||
Required: []string{"title", "text"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: "Create a new issue on a GitHub repository.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"text": {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func NewGithubIssueReader(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssuesReader) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubIssuesReader) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
@@ -37,7 +37,7 @@ func (g *GithubIssuesReader) Run(ctx context.Context, params action.ActionParams
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
@@ -47,26 +47,26 @@ func (g *GithubIssuesReader) Run(ctx context.Context, params action.ActionParams
|
||||
|
||||
issue, _, err := g.client.Issues.Get(g.context, result.Owner, result.Repository, result.IssueNumber)
|
||||
if err == nil && issue != nil {
|
||||
return action.ActionResult{
|
||||
return types.ActionResult{
|
||||
Result: fmt.Sprintf(
|
||||
"Issue %d Repository: %s\nTitle: %s\nBody: %s",
|
||||
*issue.Number, *issue.Repository.FullName, *issue.Title, *issue.Body)}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return action.ActionResult{Result: fmt.Sprintf("Error fetching issue: %s", err.Error())}, err
|
||||
return types.ActionResult{Result: fmt.Sprintf("Error fetching issue: %s", err.Error())}, err
|
||||
}
|
||||
return action.ActionResult{Result: fmt.Sprintf("No issue found")}, err
|
||||
return types.ActionResult{Result: fmt.Sprintf("No issue found")}, err
|
||||
}
|
||||
|
||||
func (g *GithubIssuesReader) Definition() action.ActionDefinition {
|
||||
func (g *GithubIssuesReader) Definition() types.ActionDefinition {
|
||||
actionName := "read_github_issue"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
description := "Read a Github issue."
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"issue_number": {
|
||||
@@ -77,8 +77,8 @@ func (g *GithubIssuesReader) Definition() action.ActionDefinition {
|
||||
Required: []string{"issue_number"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"issue_number": {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
@@ -29,7 +29,7 @@ func NewGithubIssueSearch(ctx context.Context, config map[string]string) *Github
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubIssueSearch) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
Repository string `json:"repository"`
|
||||
@@ -39,7 +39,7 @@ func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
@@ -56,7 +56,7 @@ func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams)
|
||||
})
|
||||
if err != nil {
|
||||
resultString = fmt.Sprintf("Error listing issues: %v", err)
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
for _, i := range issues.Issues {
|
||||
xlog.Info("Issue found", "title", i.GetTitle())
|
||||
@@ -65,17 +65,17 @@ func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams)
|
||||
// resultString += fmt.Sprintf("Body: %s\n", i.GetBody())
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
func (g *GithubIssueSearch) Definition() action.ActionDefinition {
|
||||
func (g *GithubIssueSearch) Definition() types.ActionDefinition {
|
||||
actionName := "search_github_issue"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: "Search between github issues",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"query": {
|
||||
@@ -86,8 +86,8 @@ func (g *GithubIssueSearch) Definition() action.ActionDefinition {
|
||||
Required: []string{"query"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: "Search between github issues",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"query": {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ func NewGithubRepositoryCreateOrUpdateContent(ctx context.Context, config map[st
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Path string `json:"path"`
|
||||
Repository string `json:"repository"`
|
||||
@@ -44,7 +44,7 @@ func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if result.Branch == "" {
|
||||
@@ -82,13 +82,13 @@ func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params
|
||||
})
|
||||
if err != nil {
|
||||
resultString := fmt.Sprintf("Error creating content : %v", err)
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: fmt.Sprintf("File created/updated: %s\n", fileContent.GetURL())}, err
|
||||
return types.ActionResult{Result: fmt.Sprintf("File created/updated: %s\n", fileContent.GetURL())}, err
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryCreateOrUpdateContent) Definition() action.ActionDefinition {
|
||||
func (g *GithubRepositoryCreateOrUpdateContent) Definition() types.ActionDefinition {
|
||||
actionName := "github_repository_create_or_update_content"
|
||||
actionDescription := "Create or update a file in a GitHub repository"
|
||||
if g.customActionName != "" {
|
||||
@@ -117,8 +117,8 @@ func (g *GithubRepositoryCreateOrUpdateContent) Definition() action.ActionDefini
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: properties,
|
||||
Required: []string{"path", "content"},
|
||||
@@ -135,8 +135,8 @@ func (g *GithubRepositoryCreateOrUpdateContent) Definition() action.ActionDefini
|
||||
Description: "The repository to search in",
|
||||
}
|
||||
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: properties,
|
||||
Required: []string{"path", "repository", "owner", "content"},
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func NewGithubRepositoryGetContent(ctx context.Context, config map[string]string
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryGetContent) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubRepositoryGetContent) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Path string `json:"path"`
|
||||
Repository string `json:"repository"`
|
||||
@@ -38,7 +38,7 @@ func (g *GithubRepositoryGetContent) Run(ctx context.Context, params action.Acti
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
@@ -49,7 +49,7 @@ func (g *GithubRepositoryGetContent) Run(ctx context.Context, params action.Acti
|
||||
fileContent, directoryContent, _, err := g.client.Repositories.GetContents(g.context, result.Owner, result.Repository, result.Path, nil)
|
||||
if err != nil {
|
||||
resultString := fmt.Sprintf("Error getting content : %v", err)
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
if len(directoryContent) > 0 {
|
||||
@@ -57,26 +57,26 @@ func (g *GithubRepositoryGetContent) Run(ctx context.Context, params action.Acti
|
||||
for _, f := range directoryContent {
|
||||
resultString += fmt.Sprintf("File: %s\n", f.GetName())
|
||||
}
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
content, err := fileContent.GetContent()
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: fmt.Sprintf("File %s\nContent:%s\n", result.Path, content)}, err
|
||||
return types.ActionResult{Result: fmt.Sprintf("File %s\nContent:%s\n", result.Path, content)}, err
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryGetContent) Definition() action.ActionDefinition {
|
||||
func (g *GithubRepositoryGetContent) Definition() types.ActionDefinition {
|
||||
actionName := "get_github_repository_content"
|
||||
actionDescription := "Get content of a file or directory in a github repository"
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"path": {
|
||||
@@ -87,8 +87,8 @@ func (g *GithubRepositoryGetContent) Definition() action.ActionDefinition {
|
||||
Required: []string{"path"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"path": {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ func NewGithubRepositoryREADME(ctx context.Context, config map[string]string) *G
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryREADME) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (g *GithubRepositoryREADME) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
@@ -35,30 +35,30 @@ func (g *GithubRepositoryREADME) Run(ctx context.Context, params action.ActionPa
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
fileContent, _, err := g.client.Repositories.GetReadme(g.context, result.Owner, result.Repository, &github.RepositoryContentGetOptions{})
|
||||
if err != nil {
|
||||
resultString := fmt.Sprintf("Error getting content : %v", err)
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
return types.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
content, err := fileContent.GetContent()
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: content}, err
|
||||
return types.ActionResult{Result: content}, err
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryREADME) Definition() action.ActionDefinition {
|
||||
func (g *GithubRepositoryREADME) Definition() types.ActionDefinition {
|
||||
actionName := "github_readme"
|
||||
actionDescription := "Get the README file of a GitHub repository to have a basic understanding of the project."
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"repository": {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/scraper"
|
||||
)
|
||||
@@ -16,7 +16,7 @@ func NewScraper(config map[string]string) *ScraperAction {
|
||||
|
||||
type ScraperAction struct{}
|
||||
|
||||
func (a *ScraperAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *ScraperAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
URL string `json:"url"`
|
||||
}{}
|
||||
@@ -24,25 +24,25 @@ func (a *ScraperAction) Run(ctx context.Context, params action.ActionParams) (ac
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
scraper, err := scraper.New()
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
res, err := scraper.Call(ctx, result.URL)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
return action.ActionResult{Result: res}, nil
|
||||
return types.ActionResult{Result: res}, nil
|
||||
}
|
||||
|
||||
func (a *ScraperAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *ScraperAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "scrape",
|
||||
Description: "Scrapes a full website content and returns the entire site data.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/duckduckgo"
|
||||
"mvdan.cc/xurls/v2"
|
||||
@@ -34,7 +34,7 @@ func NewSearch(config map[string]string) *SearchAction {
|
||||
|
||||
type SearchAction struct{ results int }
|
||||
|
||||
func (a *SearchAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *SearchAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
}{}
|
||||
@@ -42,19 +42,19 @@ func (a *SearchAction) Run(ctx context.Context, params action.ActionParams) (act
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
ddg, err := duckduckgo.New(a.results, "LocalAgent")
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
res, err := ddg.Call(ctx, result.Query)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
rxStrict := xurls.Strict()
|
||||
@@ -69,11 +69,11 @@ func (a *SearchAction) Run(ctx context.Context, params action.ActionParams) (act
|
||||
results = append(results, u)
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: res, Metadata: map[string]interface{}{MetadataUrls: results}}, nil
|
||||
return types.ActionResult{Result: res, Metadata: map[string]interface{}{MetadataUrls: results}}, nil
|
||||
}
|
||||
|
||||
func (a *SearchAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *SearchAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "search_internet",
|
||||
Description: "Search the internet for something.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ type SendMailAction struct {
|
||||
smtpPort string
|
||||
}
|
||||
|
||||
func (a *SendMailAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *SendMailAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Message string `json:"message"`
|
||||
To string `json:"to"`
|
||||
@@ -37,7 +37,7 @@ func (a *SendMailAction) Run(ctx context.Context, params action.ActionParams) (a
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
// Authentication.
|
||||
@@ -50,13 +50,13 @@ func (a *SendMailAction) Run(ctx context.Context, params action.ActionParams) (a
|
||||
result.To,
|
||||
}, []byte(result.Message))
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
return action.ActionResult{Result: fmt.Sprintf("Email sent to %s", result.To)}, nil
|
||||
return types.ActionResult{Result: fmt.Sprintf("Email sent to %s", result.To)}, nil
|
||||
}
|
||||
|
||||
func (a *SendMailAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *SendMailAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "send_email",
|
||||
Description: "Send an email.",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -27,7 +27,7 @@ type ShellAction struct {
|
||||
customDescription string
|
||||
}
|
||||
|
||||
func (a *ShellAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *ShellAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Command string `json:"command"`
|
||||
Host string `json:"host"`
|
||||
@@ -37,7 +37,7 @@ func (a *ShellAction) Run(ctx context.Context, params action.ActionParams) (acti
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if a.host != "" && a.user != "" {
|
||||
@@ -47,13 +47,13 @@ func (a *ShellAction) Run(ctx context.Context, params action.ActionParams) (acti
|
||||
|
||||
output, err := sshCommand(a.privateKey, result.Command, result.User, result.Host)
|
||||
if err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: output}, nil
|
||||
return types.ActionResult{Result: output}, nil
|
||||
}
|
||||
|
||||
func (a *ShellAction) Definition() action.ActionDefinition {
|
||||
func (a *ShellAction) Definition() types.ActionDefinition {
|
||||
name := "shell"
|
||||
description := "Run a shell command on a remote server."
|
||||
if a.customName != "" {
|
||||
@@ -63,8 +63,8 @@ func (a *ShellAction) Definition() action.ActionDefinition {
|
||||
description = a.customDescription
|
||||
}
|
||||
if a.host != "" && a.user != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(name),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(name),
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"command": {
|
||||
@@ -75,8 +75,8 @@ func (a *ShellAction) Definition() action.ActionDefinition {
|
||||
Required: []string{"command"},
|
||||
}
|
||||
}
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(name),
|
||||
return types.ActionDefinition{
|
||||
Name: types.ActionDefinitionName(name),
|
||||
Description: description,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"command": {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/mudler/LocalAgent/services/connectors/twitter"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
@@ -21,7 +21,7 @@ type PostTweetAction struct {
|
||||
noCharacterLimit bool
|
||||
}
|
||||
|
||||
func (a *PostTweetAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *PostTweetAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Text string `json:"text"`
|
||||
}{}
|
||||
@@ -29,24 +29,24 @@ func (a *PostTweetAction) Run(ctx context.Context, params action.ActionParams) (
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
if !a.noCharacterLimit && len(result.Text) > 280 {
|
||||
return action.ActionResult{}, fmt.Errorf("tweet is too long, max 280 characters")
|
||||
return types.ActionResult{}, fmt.Errorf("tweet is too long, max 280 characters")
|
||||
}
|
||||
|
||||
client := twitter.NewTwitterClient(a.token)
|
||||
|
||||
if err := client.Post(result.Text); err != nil {
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: fmt.Sprintf("twitter post created")}, nil
|
||||
return types.ActionResult{Result: fmt.Sprintf("twitter post created")}, nil
|
||||
}
|
||||
|
||||
func (a *PostTweetAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *PostTweetAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "post_tweet",
|
||||
Description: "Post a tweet",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/types"
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/tmc/langchaingo/tools/wikipedia"
|
||||
)
|
||||
@@ -15,7 +15,7 @@ func NewWikipedia(config map[string]string) *WikipediaAction {
|
||||
|
||||
type WikipediaAction struct{}
|
||||
|
||||
func (a *WikipediaAction) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
func (a *WikipediaAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||
result := struct {
|
||||
Query string `json:"query"`
|
||||
}{}
|
||||
@@ -23,20 +23,20 @@ func (a *WikipediaAction) Run(ctx context.Context, params action.ActionParams) (
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
wiki := wikipedia.New("LocalAgent")
|
||||
res, err := wiki.Call(ctx, result.Query)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v", err)
|
||||
|
||||
return action.ActionResult{}, err
|
||||
return types.ActionResult{}, err
|
||||
}
|
||||
return action.ActionResult{Result: res}, nil
|
||||
return types.ActionResult{Result: res}, nil
|
||||
}
|
||||
|
||||
func (a *WikipediaAction) Definition() action.ActionDefinition {
|
||||
return action.ActionDefinition{
|
||||
func (a *WikipediaAction) Definition() types.ActionDefinition {
|
||||
return types.ActionDefinition{
|
||||
Name: "wikipedia",
|
||||
Description: "Find wikipedia pages using the wikipedia api",
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
|
||||
Reference in New Issue
Block a user