Skip to content

Commit

Permalink
adjusted to new moderation method structure and added better test for…
Browse files Browse the repository at this point in the history
… whisper in models_test.go (aka the generated test file)
  • Loading branch information
conneroisu committed Nov 4, 2024
1 parent a6ec956 commit 091a6f9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ type Client struct {
```

<a name="NewClient"></a>
### func [NewClient](<https://github.com/conneroisu/groq-go/blob/main/client.go#L119>)
### func [NewClient](<https://github.com/conneroisu/groq-go/blob/main/client.go#L118>)

```go
func NewClient(groqAPIKey string, opts ...Opts) (*Client, error)
Expand Down Expand Up @@ -794,7 +794,6 @@ const (
// FormatVerboseJSON is the verbose JSON format. This is a JSON format
// that is only supported for the transcription API.
FormatVerboseJSON Format = "verbose_json"

// FormatJSONObject is the json object chat
// completion response format type.
FormatJSONObject Format = "json_object"
Expand Down Expand Up @@ -864,7 +863,7 @@ type Opts func(*Client)
```

<a name="WithBaseURL"></a>
### func [WithBaseURL](<https://github.com/conneroisu/groq-go/blob/main/client.go#L158>)
### func [WithBaseURL](<https://github.com/conneroisu/groq-go/blob/main/client.go#L157>)

```go
func WithBaseURL(baseURL string) Opts
Expand All @@ -873,7 +872,7 @@ func WithBaseURL(baseURL string) Opts
WithBaseURL sets the base URL for the Groq client.

<a name="WithClient"></a>
### func [WithClient](<https://github.com/conneroisu/groq-go/blob/main/client.go#L153>)
### func [WithClient](<https://github.com/conneroisu/groq-go/blob/main/client.go#L152>)

```go
func WithClient(client *http.Client) Opts
Expand All @@ -882,7 +881,7 @@ func WithClient(client *http.Client) Opts
WithClient sets the client for the Groq client.

<a name="WithLogger"></a>
### func [WithLogger](<https://github.com/conneroisu/groq-go/blob/main/client.go#L163>)
### func [WithLogger](<https://github.com/conneroisu/groq-go/blob/main/client.go#L162>)

```go
func WithLogger(logger *slog.Logger) Opts
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions pkg/models/models_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added pkg/models/testdata/whisper.mp3
Binary file not shown.
20 changes: 14 additions & 6 deletions scripts/generate-models/models_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
package models_test

import (
"bytes"
"context"
"os"
"testing"
"time"

"github.com/conneroisu/groq-go"
"github.com/conneroisu/groq-go/pkg/models"
"github.com/conneroisu/groq-go/pkg/moderation"
"github.com/conneroisu/groq-go/pkg/test"
"github.com/stretchr/testify/assert"

_ "embed"
)

//go:embed testdata/whisper.mp3
var whisperBytes []byte

{{- range $model := .ChatModels }}
// TestChatModels{{ $model.Name }} tests the {{ $model.Name }} model.
Expand Down Expand Up @@ -68,9 +74,11 @@ func Test{{ $model.Name }}(t *testing.T) {
a.NoError(err, "GetAPIKey error")
client, err := groq.NewClient(apiKey)
a.NoError(err, "NewClient error")
reader := bytes.NewReader(whisperBytes)
response, err := client.CreateTranscription(ctx, groq.AudioRequest{
Model: models.ModelWhisperLargeV3,
FilePath: "./examples/audio-lex-fridman/The Roman Emperors who went insane Gregory Aldrete and Lex Fridman.mp3",
Reader: reader,
FilePath: "whisper.mp3",
})
a.NoError(err, "CreateTranscription error")
a.NotEmpty(response.Text, "response.Text is empty for model WhisperLargeV3 calling CreateTranscription")
Expand All @@ -93,20 +101,20 @@ func Test{{ $model.Name }}(t *testing.T) {
a.NoError(err, "GetAPIKey error")
client, err := groq.NewClient(apiKey)
a.NoError(err, "NewClient error")
response, err := client.Moderate(ctx, groq.ModerationRequest{
Model: models.Model{{ $model.Name }},
Messages: []groq.ChatCompletionMessage{
response, err := client.Moderate(ctx,
[]groq.ChatCompletionMessage{
{
Role: groq.ChatMessageRoleUser,
Content: "I want to kill them.",
},
},
})
models.Model{{ $model.Name }},
)
a.NoError(err, "Moderation error")
a.Equal(true, response.Flagged)
a.Contains(
response.Categories,
groq.CategoryViolentCrimes,
moderation.CategoryViolentCrimes,
)
}
{{- end }}
Expand Down

0 comments on commit 091a6f9

Please sign in to comment.