Skip to content

Commit

Permalink
make toolhouse and e2b their own go packages
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu committed Oct 19, 2024
1 parent eafae73 commit 4b6feed
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

//go:generate go run ./scripts/generate-models/
//go:generate make docs
//go:generate gomarkdoc -o README.md -e .

type (
// Format is the format of a response.
Expand Down
14 changes: 14 additions & 0 deletions extensions/e2b/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/conneroisu/groq-go/extensions/e2b

go 1.23.1

require (
github.com/gorilla/websocket v1.5.3
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions extensions/e2b/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2 changes: 0 additions & 2 deletions extensions/e2b/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,6 @@ func (s *Sandbox) read(ctx context.Context) (err error) {
}
}
}

// writeRequest writes a request to the websocket.
func (s *Sandbox) writeRequest(
ctx context.Context,
method Method,
Expand Down
141 changes: 141 additions & 0 deletions extensions/toolhouse/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,144 @@
# Toolhouse

This is an extension for groq-go that allows you to use the Toolhouse API to give tools to your ai models.

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# toolhouse

```go
import "github.com/conneroisu/groq-go/extensions/toolhouse"
```

Package toolhouse provides a Toolhouse extension for groq\-go.

It allows you to use the Toolhouse API to give tools to your ai models.

Package toolhouse provides a Toolhouse extension for groq\-go.

## Index

- [type Extension](<#Extension>)
- [func NewExtension\(apiKey string, opts ...Options\) \(e \*Extension, err error\)](<#NewExtension>)
- [func \(e \*Extension\) GetTools\(ctx context.Context\) \(\[\]groq.Tool, error\)](<#Extension.GetTools>)
- [func \(e \*Extension\) MustGetTools\(ctx context.Context\) \[\]groq.Tool](<#Extension.MustGetTools>)
- [func \(e \*Extension\) MustRun\(ctx context.Context, response groq.ChatCompletionResponse\) \[\]groq.ChatCompletionMessage](<#Extension.MustRun>)
- [func \(e \*Extension\) Run\(ctx context.Context, response groq.ChatCompletionResponse\) \(\[\]groq.ChatCompletionMessage, error\)](<#Extension.Run>)
- [type Options](<#Options>)
- [func WithBaseURL\(baseURL string\) Options](<#WithBaseURL>)
- [func WithClient\(client \*http.Client\) Options](<#WithClient>)
- [func WithLogger\(logger \*slog.Logger\) Options](<#WithLogger>)
- [func WithMetadata\(metadata map\[string\]any\) Options](<#WithMetadata>)


<a name="Extension"></a>
## type [Extension](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/toolhouse.go#L24-L34>)

Extension is a Toolhouse extension.

```go
type Extension struct {
// contains filtered or unexported fields
}
```

<a name="NewExtension"></a>
### func [NewExtension](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/toolhouse.go#L41>)

```go
func NewExtension(apiKey string, opts ...Options) (e *Extension, err error)
```

NewExtension creates a new Toolhouse extension.

<a name="Extension.GetTools"></a>
### func \(\*Extension\) [GetTools](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/tools.go#L28-L30>)

```go
func (e *Extension) GetTools(ctx context.Context) ([]groq.Tool, error)
```

GetTools returns a list of tools that the extension can use.

<a name="Extension.MustGetTools"></a>
### func \(\*Extension\) [MustGetTools](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/tools.go#L17-L19>)

```go
func (e *Extension) MustGetTools(ctx context.Context) []groq.Tool
```

MustGetTools returns a list of tools that the extension can use.

It panics if an error occurs.

<a name="Extension.MustRun"></a>
### func \(\*Extension\) [MustRun](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/run.go#L26-L29>)

```go
func (e *Extension) MustRun(ctx context.Context, response groq.ChatCompletionResponse) []groq.ChatCompletionMessage
```

MustRun runs the extension on the given history.

It panics if an error occurs.

<a name="Extension.Run"></a>
### func \(\*Extension\) [Run](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/run.go#L38-L41>)

```go
func (e *Extension) Run(ctx context.Context, response groq.ChatCompletionResponse) ([]groq.ChatCompletionMessage, error)
```

Run runs the extension on the given history.

<a name="Options"></a>
## type [Options](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/toolhouse.go#L37>)

Options is a function that sets options for a Toolhouse extension.

```go
type Options func(*Extension)
```

<a name="WithBaseURL"></a>
### func [WithBaseURL](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/options.go#L9>)

```go
func WithBaseURL(baseURL string) Options
```

WithBaseURL sets the base URL for the Toolhouse extension.

<a name="WithClient"></a>
### func [WithClient](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/options.go#L16>)

```go
func WithClient(client *http.Client) Options
```

WithClient sets the client for the Toolhouse extension.

<a name="WithLogger"></a>
### func [WithLogger](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/options.go#L30>)

```go
func WithLogger(logger *slog.Logger) Options
```

WithLogger sets the logger for the Toolhouse extension.

<a name="WithMetadata"></a>
### func [WithMetadata](<https://github.com/conneroisu/groq-go/blob/main/extensions/toolhouse/options.go#L23>)

```go
func WithMetadata(metadata map[string]any) Options
```

WithMetadata sets the metadata for the get tools request.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->
3 changes: 0 additions & 3 deletions extensions/toolhouse/errors.go

This file was deleted.

11 changes: 11 additions & 0 deletions extensions/toolhouse/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/conneroisu/groq-go/extensions/toolhouse

go 1.23.1

require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
5 changes: 5 additions & 0 deletions extensions/toolhouse/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8 changes: 4 additions & 4 deletions extensions/toolhouse/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import (

// WithBaseURL sets the base URL for the Toolhouse extension.
func WithBaseURL(baseURL string) Options {
return func(e *Extension) {
return func(e *Toolhouse) {
e.baseURL = baseURL
}
}

// WithClient sets the client for the Toolhouse extension.
func WithClient(client *http.Client) Options {
return func(e *Extension) {
return func(e *Toolhouse) {
e.client = client
}
}

// WithMetadata sets the metadata for the get tools request.
func WithMetadata(metadata map[string]any) Options {
return func(r *Extension) {
return func(r *Toolhouse) {
r.metadata = metadata
}
}

// WithLogger sets the logger for the Toolhouse extension.
func WithLogger(logger *slog.Logger) Options {
return func(r *Extension) {
return func(r *Toolhouse) {
r.logger = logger
}
}
4 changes: 2 additions & 2 deletions extensions/toolhouse/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type (
// MustRun runs the extension on the given history.
//
// It panics if an error occurs.
func (e *Extension) MustRun(
func (e *Toolhouse) MustRun(
ctx context.Context,
response groq.ChatCompletionResponse,
) []groq.ChatCompletionMessage {
Expand All @@ -35,7 +35,7 @@ func (e *Extension) MustRun(
}

// Run runs the extension on the given history.
func (e *Extension) Run(
func (e *Toolhouse) Run(
ctx context.Context,
response groq.ChatCompletionResponse,
) ([]groq.ChatCompletionMessage, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/conneroisu/groq-go/pkg/builders"
)

//go:generate gomarkdoc -o README.md -e .

const (
defaultBaseURL = "https://api.toolhouse.ai/v1"
getToolsEndpoint = "/get_tools"
Expand All @@ -18,8 +20,8 @@ const (
)

type (
// Extension is a Toolhouse extension.
Extension struct {
// Toolhouse is a Toolhouse extension.
Toolhouse struct {
apiKey string
baseURL string
client *http.Client
Expand All @@ -32,12 +34,12 @@ type (
}

// Options is a function that sets options for a Toolhouse extension.
Options func(*Extension)
Options func(*Toolhouse)
)

// NewExtension creates a new Toolhouse extension.
func NewExtension(apiKey string, opts ...Options) (e *Extension, err error) {
e = &Extension{
func NewExtension(apiKey string, opts ...Options) (e *Toolhouse, err error) {
e = &Toolhouse{
apiKey: apiKey,
baseURL: defaultBaseURL,
client: http.DefaultClient,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions extensions/toolhouse/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// MustGetTools returns a list of tools that the extension can use.
//
// It panics if an error occurs.
func (e *Extension) MustGetTools(
func (e *Toolhouse) MustGetTools(
ctx context.Context,
) []groq.Tool {
tools, err := e.GetTools(ctx)
Expand All @@ -25,7 +25,7 @@ func (e *Extension) MustGetTools(
}

// GetTools returns a list of tools that the extension can use.
func (e *Extension) GetTools(
func (e *Toolhouse) GetTools(
ctx context.Context,
) ([]groq.Tool, error) {
if len(e.tools) > 0 {
Expand Down
3 changes: 3 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6/go.mod h1:39R/xuhNgVhi+K0/zst4TLrJrVmbm6LVgl4A0+ZFS5M=
Expand Down Expand Up @@ -150,6 +152,7 @@ google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:CCviP9RmpZ1mxVr8MUjCnSiY09IbAXZxhLE6EhHIdPU=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
k8s.io/api v0.26.2/go.mod h1:1kjMQsFE+QHPfskEcVNgL3+Hp88B80uj0QtSOlj8itU=
k8s.io/apimachinery v0.26.2/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I=
Expand Down

0 comments on commit 4b6feed

Please sign in to comment.