Skip to content

Commit

Permalink
added start to exmaple of e2b module
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu committed Oct 20, 2024
1 parent 658095e commit aa5522a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/e2b-go-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# e2b-go-project

This is an example of using groq-go to create a simple golang project using the e2b and groq api powered by the groq-go library.

## Usage

Make sure you have a groq key set in the environment variable `GROQ_KEY`.
Also, make sure that you have a e2b api key set in the environment variable `E2B_API_KEY`.

```bash
export GROQ_KEY=your-groq-key
export E2B_API_KEY=your-e2b-api-key
go run .
```

### System Prompt

```txt
Given the tools given to you, create a golang project with the following files:
<files>
main.go
utils.go
<files>
The main function should call the `utils.run() error` function.
The project should, when run, print the following:
<output>
Hello, World!
<output>
```
67 changes: 67 additions & 0 deletions examples/e2b-go-project/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"context"
"fmt"
"os"

"github.com/conneroisu/groq-go"
"github.com/conneroisu/groq-go/extensions/e2b"
)

func main() {
if err := run(context.Background()); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func run(
ctx context.Context,
) error {
key := os.Getenv("GROQ_KEY")
e2bKey := os.Getenv("E2B_API_KEY")
client, err := groq.NewClient(key)
if err != nil {
return err
}
sb, err := e2b.NewSandbox(
ctx,
e2bKey,
)
if err != nil {
return err
}
chat, err := client.CreateChatCompletion(ctx, groq.ChatCompletionRequest{
Model: groq.ModelLlama3Groq70B8192ToolUsePreview,
Messages: []groq.ChatCompletionMessage{
{
Role: groq.ChatMessageRoleUser,
Content: `
Given the tools given to you, create a golang project with the following files:
<files>
main.go
utils.go
<files>
The main function should call the "utils.run() error" function.
The project should, when run, print the following:
<output>
Hello, World!
<output>
`,
},
},
MaxTokens: 2000,
Tools: sb.GetTools(),
})
if err != nil {
return err
}
fmt.Println(chat.Choices[0].Message.Content)
return nil
}

Check warning on line 67 in examples/e2b-go-project/main.go

View check run for this annotation

Codeac.io / Codeac Code Quality

package-comments

should have a package comment
2 changes: 2 additions & 0 deletions extensions/e2b/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ func TestNewSandbox(t *testing.T) {
proc, err := sb.NewProcess("sleep 5 && echo 'hello world!'", Process{})
a.NoError(err)
events := make(chan Event, 10)
// start the process
err = proc.Start(ctx)
a.NoError(err)
// subscribe to the process's stdout
err = proc.Subscribe(ctx, OnStdout, events)
a.NoError(err)
event := <-events
Expand Down

0 comments on commit aa5522a

Please sign in to comment.