-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added start to exmaple of e2b module
- Loading branch information
1 parent
658095e
commit aa5522a
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters