Skip to content

Commit

Permalink
run go generate and update audio_test to be pkg: groq_test
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu committed Oct 26, 2024
1 parent 880b402 commit d1a7deb
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 1,072 deletions.
1,119 changes: 78 additions & 1,041 deletions README.md

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,14 @@ type (
)

// SetHeader sets the header of the response.
func (r *AudioResponse) SetHeader(header http.Header) {
r.Header = header
}
func (r *AudioResponse) SetHeader(header http.Header) { r.Header = header }

// SetHeader sets the header of the audio text response.
func (r *audioTextResponse) SetHeader(header http.Header) {
r.header = header
}
func (r *audioTextResponse) SetHeader(header http.Header) { r.header = header }

// toAudioResponse converts the audio text response to an audio response.
func (r *audioTextResponse) toAudioResponse() AudioResponse {
return AudioResponse{
Text: r.Text,
Header: r.header,
}
return AudioResponse{Text: r.Text, Header: r.header}
}

// CreateTranscription calls the transcriptions endpoint with the given request.
Expand Down Expand Up @@ -130,7 +123,7 @@ func (c *Client) callAudioAPI(
) (response AudioResponse, err error) {
var formBody bytes.Buffer
c.requestFormBuilder = c.createFormBuilder(&formBody)
err = audioMultipartForm(request, c.requestFormBuilder)
err = AudioMultipartForm(request, c.requestFormBuilder)
if err != nil {
return AudioResponse{}, err
}
Expand Down Expand Up @@ -164,10 +157,10 @@ func (r AudioRequest) hasJSONResponse() bool {
r.Format == AudioResponseFormatVerboseJSON
}

// audioMultipartForm creates a form with audio file contents and the name of
// AudioMultipartForm creates a form with audio file contents and the name of
// the model to use for audio processing.
func audioMultipartForm(request AudioRequest, b builders.FormBuilder) error {
err := createFileField(request, b)
func AudioMultipartForm(request AudioRequest, b builders.FormBuilder) error {
err := CreateFileField(request, b)
if err != nil {
return err
}
Expand Down Expand Up @@ -209,9 +202,9 @@ func audioMultipartForm(request AudioRequest, b builders.FormBuilder) error {
return b.Close()
}

// createFileField creates the "file" form field from either an existing file
// CreateFileField creates the "file" form field from either an existing file
// or by using the reader.
func createFileField(
func CreateFileField(
request AudioRequest,
b builders.FormBuilder,
) (err error) {
Expand Down
23 changes: 12 additions & 11 deletions audio_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package groq
package groq_test

import (
"bytes"
Expand All @@ -8,6 +8,7 @@ import (
"path/filepath"
"testing"

groq "github.com/conneroisu/groq-go"
"github.com/conneroisu/groq-go/pkg/builders"
"github.com/conneroisu/groq-go/pkg/test"
"github.com/stretchr/testify/assert"
Expand All @@ -20,12 +21,12 @@ func TestAudioWithFailingFormBuilder(t *testing.T) {
path := filepath.Join(dir, "fake.mp3")
test.CreateTestFile(t, path)

req := AudioRequest{
req := groq.AudioRequest{
FilePath: path,
Prompt: "test",
Temperature: 0.5,
Language: "en",
Format: AudioResponseFormatSRT,
Format: groq.AudioResponseFormatSRT,
}

mockFailedErr := fmt.Errorf("mock form builder fail")
Expand All @@ -34,7 +35,7 @@ func TestAudioWithFailingFormBuilder(t *testing.T) {
mockBuilder.mockCreateFormFile = func(string, *os.File) error {
return mockFailedErr
}
err := audioMultipartForm(req, mockBuilder)
err := groq.AudioMultipartForm(req, mockBuilder)
a.ErrorIs(
err,
mockFailedErr,
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestAudioWithFailingFormBuilder(t *testing.T) {
failingField,
)

err = audioMultipartForm(req, mockBuilder)
err = groq.AudioMultipartForm(req, mockBuilder)
a.Error(
err,
mockFailedErr,
Expand All @@ -84,7 +85,7 @@ func TestCreateFileField(t *testing.T) {
defer cleanup()
path := filepath.Join(dir, "fake.mp3")
test.CreateTestFile(t, path)
req := AudioRequest{
req := groq.AudioRequest{
FilePath: path,
}
mockFailedErr := fmt.Errorf("mock form builder fail")
Expand All @@ -93,7 +94,7 @@ func TestCreateFileField(t *testing.T) {
return mockFailedErr
},
}
err := createFileField(req, mockBuilder)
err := groq.CreateFileField(req, mockBuilder)
a.ErrorIs(
err,
mockFailedErr,
Expand All @@ -103,7 +104,7 @@ func TestCreateFileField(t *testing.T) {

t.Run("createFileField failing reader", func(t *testing.T) {
t.Parallel()
req := AudioRequest{
req := groq.AudioRequest{
FilePath: "test.wav",
Reader: bytes.NewBuffer([]byte(`wav test contents`)),
}
Expand All @@ -115,7 +116,7 @@ func TestCreateFileField(t *testing.T) {
},
}

err := createFileField(req, mockBuilder)
err := groq.CreateFileField(req, mockBuilder)
a.ErrorIs(
err,
mockFailedErr,
Expand All @@ -125,11 +126,11 @@ func TestCreateFileField(t *testing.T) {

t.Run("createFileField failing open", func(t *testing.T) {
t.Parallel()
req := AudioRequest{
req := groq.AudioRequest{
FilePath: "non_existing_file.wav",
}
mockBuilder := builders.NewFormBuilder(&test.FailingErrorBuffer{})
err := createFileField(req, mockBuilder)
err := groq.CreateFileField(req, mockBuilder)
a.Error(
err,
"createFileField using file should return error when open file fails",
Expand Down
6 changes: 6 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ github.com/containers/ocicrypt v1.1.10/go.mod h1:YfzSSr06PTHQwSTUKqDSjish9BeW1E4
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
Expand All @@ -56,8 +57,10 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/intel/goresctrl v0.3.0/go.mod h1:fdz3mD85cmP9sHD8JUlrNWAxvwM86CrbmVXltEKd7zk=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/logrusorgru/aurora/v4 v4.0.0/go.mod h1:lP0iIa2nrnT/qoFXcOZSrZQpJ1o6n2CUf/hyHi2Q4ZQ=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand All @@ -82,6 +85,7 @@ github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626/go.
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/pelletier/go-toml v1.9.1/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/princjef/termdiff v0.1.0/go.mod h1:JJOfCA/eR6T1JfsoxQQ6jsG3LGoQDoKUIRQrKqAO+p4=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
Expand Down Expand Up @@ -133,6 +137,7 @@ golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -154,6 +159,7 @@ golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:CCviP9RmpZ1mxVr8MUjCnSiY09IbAXZxhLE6EhHIdPU=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
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=
Expand Down
4 changes: 2 additions & 2 deletions models.go

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

2 changes: 1 addition & 1 deletion models_test.go

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

2 changes: 1 addition & 1 deletion moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ var (
}
)

// Moderate — perform a moderation api call over a string.
// Moderate performs a moderation api call over a string.
// Input can be an array or slice but a string will reduce the complexity.
func (c *Client) Moderate(
ctx context.Context,
Expand Down

0 comments on commit d1a7deb

Please sign in to comment.