Skip to content

Commit

Permalink
optimize readability in composio and make sure e2b is concurrent safe
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu committed Oct 25, 2024
1 parent 8bcb569 commit 2e523c3
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 169 deletions.
18 changes: 13 additions & 5 deletions examples/composio-github-star/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# composio-github-star

Adapted from the [quickstart](https://docs.composio.dev/introduction/intro/quickstart) guide.

Install the `composio` CLI and login to your account (also add github to your account if you haven't already)

```bash
pip install -U composio_core composio_openai

pip install composio-langchain
pip install langchain-groq
composio login

#Connect your Github so agents can use it
composio add github

#Check all different apps which you can connect with
composio apps
```

Congratulations! You’ve just:

🔐 Authenticated your GitHub account with Composio
🛠 Fetched GitHub tools for the llm
⭐ Instructed the AI to star the conneroisu/groq-go repository
✅ Successfully executed the action on GitHub
5 changes: 2 additions & 3 deletions examples/composio-github-star/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ func run(
{
Role: groq.ChatMessageRoleUser,
Content: `
You are a github star bot.
You will be given a repo name and you will star it.
Star a repo conneroisu/groq-go on GitHub
You are a github star bot. You will be given a repo name and you will star it.
Star the repo conneroisu/groq-go on GitHub.
`,
},
},
Expand Down
14 changes: 7 additions & 7 deletions extensions/composio/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package composio

// https://backend.composio.dev/api/v1/connectedAccounts?user_uuid=default&showActiveOnly=true

import (
"context"
"fmt"
Expand All @@ -18,6 +16,8 @@ type (
GetConnectedAccounts(ctx context.Context, opts ...AuthOption) (ConnectedAccounts, error)
}
// ConnectedAccounts represents a composio connected account.
//
// Gotten from similar url to: https://backend.composio.dev/api/v1/connectedAccounts?user_uuid=default&showActiveOnly=true
ConnectedAccounts struct {
Items []struct {
IntegrationID string `json:"integrationId"`
Expand Down Expand Up @@ -72,13 +72,13 @@ func (c *Composio) GetConnectedAccounts(ctx context.Context, opts ...AuthOption)
if err != nil {
return ca, err
}
ps := url.Values{}
ps.Add("user_uuid", "default")
ps.Add("showActiveOnly", "true")
urlValues := u.Query()
urlValues.Add("user_uuid", "default")
urlValues.Add("showActiveOnly", "true")
for _, opt := range opts {
opt(u)
opt(&urlValues)
}
u.RawQuery = ps.Encode()
u.RawQuery = urlValues.Encode()
uri = u.String()
c.logger.Debug("auth", "url", uri)
req, err := builders.NewRequest(
Expand Down
1 change: 0 additions & 1 deletion extensions/composio/composio
Submodule composio deleted from f26383
2 changes: 1 addition & 1 deletion extensions/composio/composio.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type (
)

// NewComposer creates a new composio client.
func NewComposer(apiKey string, opts ...ComposerOption) (*Composio, error) {
func NewComposer(apiKey string, opts ...Option) (*Composio, error) {
c := &Composio{
apiKey: apiKey,
header: builders.Header{SetCommonHeaders: func(r *http.Request) {
Expand Down
1 change: 0 additions & 1 deletion extensions/composio/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestRun(t *testing.T) {
a.NoError(err)
ts, err := client.GetTools(
ctx, WithApp("GITHUB"), WithUseCase("StarRepo"))
t.Logf("%+v\n", len(ts))
a.NoError(err)

Check warning on line 28 in extensions/composio/execute_test.go

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 15 lines is too similar to extensions/composio/tools_test.go:12
a.NotEmpty(ts)
groqClient, err := groq.NewClient(
Expand Down
22 changes: 9 additions & 13 deletions extensions/composio/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import (
)

type (
// ComposerOption is an option for the composio client.
// Option is an option for the composio client.
//
// WithLogger sets the logger for the composio client.
ComposerOption func(*Composio)
Option func(*Composio)

// ToolsOption is an option for the tools request.
ToolsOption func(*url.Values)

// AuthOption is an option for the auth request.
AuthOption func(*url.URL)
AuthOption func(*url.Values)
)

// Composer Options

// WithLogger sets the logger for the composio client.
func WithLogger(logger *slog.Logger) ComposerOption {
func WithLogger(logger *slog.Logger) Option {
return func(c *Composio) { c.logger = logger }
}

// Tool Options
// Get Tool Options

// WithTags sets the tags for the tools request.
func WithTags(tags ...string) ToolsOption {
Expand All @@ -53,18 +53,14 @@ func WithUseCase(useCase string) ToolsOption {

// WithShowActiveOnly sets the show active only for the auth request.
func WithShowActiveOnly(showActiveOnly bool) AuthOption {
return func(u *url.URL) {
ps := u.Query()
ps.Add("showActiveOnly", fmt.Sprintf("%t", showActiveOnly))
u.RawQuery = ps.Encode()
return func(u *url.Values) {
u.Set("showActiveOnly", fmt.Sprintf("%t", showActiveOnly))
}
}

// WithUserUUID sets the user uuid for the auth request.
func WithUserUUID(userUUID string) AuthOption {
return func(u *url.URL) {
ps := u.Query()
ps.Add("user_uuid", userUUID)
u.RawQuery = ps.Encode()
return func(u *url.Values) {
u.Set("user_uuid", userUUID)
}
}
2 changes: 2 additions & 0 deletions extensions/e2b/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package e2b provides an e2b client for groq-go.
package e2b
10 changes: 4 additions & 6 deletions extensions/e2b/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type (
Read(ctx context.Context) error
io.Closer
}
// Identifier is an interface for a constantly running process to identify new request ids.
// Identifier is an interface for a constantly running process to
// identify new request ids.
Identifier interface {
Identify(ctx context.Context)
}
Expand Down Expand Up @@ -50,11 +51,8 @@ type (
cmd string,
timeout time.Duration,
)
Subscribe(
ctx context.Context,
event ProcessEvents,
eCh chan<- Event,
)
SubscribeStdout() (events chan Event, err error)
SubscribeStderr() (events chan Event, err error)
}
// Watcher is an interface for a instance that can watch a filesystem.
Watcher interface {
Expand Down
41 changes: 41 additions & 0 deletions extensions/e2b/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package e2b

import (
"log/slog"
"net/http"
)

// WithBaseURL sets the base URL for the e2b sandbox.
func WithBaseURL(baseURL string) Option {
return func(s *Sandbox) { s.baseURL = baseURL }
}

// WithClient sets the client for the e2b sandbox.
func WithClient(client *http.Client) Option {
return func(s *Sandbox) { s.client = client }
}

// WithLogger sets the logger for the e2b sandbox.
func WithLogger(logger *slog.Logger) Option {
return func(s *Sandbox) { s.logger = logger }
}

// WithTemplate sets the template for the e2b sandbox.
func WithTemplate(template SandboxTemplate) Option {
return func(s *Sandbox) { s.Template = template }
}

// WithMetaData sets the meta data for the e2b sandbox.
func WithMetaData(metaData map[string]string) Option {
return func(s *Sandbox) { s.Metadata = metaData }
}

// WithCwd sets the current working directory.
func WithCwd(cwd string) Option {
return func(s *Sandbox) { s.Cwd = cwd }
}

// WithWsURL sets the websocket url for the e2b sandbox.
func WithWsURL(wsURL func(s *Sandbox) string) Option {
return func(s *Sandbox) { s.wsURL = wsURL }
}
Loading

0 comments on commit 2e523c3

Please sign in to comment.