diff --git a/README.md b/README.md index e00ee5496..09abf2173 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Go OpenAI -[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/sashabaranov/go-openai) -[![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-openai)](https://goreportcard.com/report/github.com/sashabaranov/go-openai) -[![codecov](https://codecov.io/gh/sashabaranov/go-openai/branch/master/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/sashabaranov/go-openai) +[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/giordanobsf/go-openai) +[![Go Report Card](https://goreportcard.com/badge/github.com/giordanobsf/go-openai)](https://goreportcard.com/report/github.com/giordanobsf/go-openai) +[![codecov](https://codecov.io/gh/giordanobsf/go-openai/branch/master/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/giordanobsf/go-openai) > **Note**: the repository was recently renamed from `go-gpt3` to `go-openai` @@ -14,7 +14,7 @@ This library provides Go clients for [OpenAI API](https://platform.openai.com/). Installation: ``` -go get github.com/sashabaranov/go-openai +go get github.com/giordanobsf/go-openai ``` @@ -26,7 +26,7 @@ package main import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/giordanobsf/go-openai" ) func main() { @@ -122,7 +122,7 @@ package main import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/giordanobsf/go-openai" ) func main() { @@ -155,7 +155,7 @@ import ( "context" "fmt" "io" - openai "github.com/sashabaranov/go-openai" + openai "github.com/giordanobsf/go-openai" ) func main() { @@ -204,7 +204,7 @@ import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/giordanobsf/go-openai" ) func main() { @@ -236,7 +236,7 @@ import ( "context" "encoding/base64" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/giordanobsf/go-openai" "image/png" "os" ) @@ -324,7 +324,7 @@ config.HTTPClient = &http.Client{ c := openai.NewClientWithConfig(config) ``` -See also: https://pkg.go.dev/github.com/sashabaranov/go-openai#ClientConfig +See also: https://pkg.go.dev/github.com/giordanobsf/go-openai#ClientConfig
@@ -340,7 +340,7 @@ import ( "os" "strings" - "github.com/sashabaranov/go-openai" + "github.com/giordanobsf/go-openai" ) func main() { diff --git a/api_test.go b/api_test.go index a5a0d1250..6f15449bc 100644 --- a/api_test.go +++ b/api_test.go @@ -1,7 +1,7 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" + . "github.com/giordanobsf/go-openai" "context" "errors" diff --git a/audio.go b/audio.go index 6d1681a51..9391444d1 100644 --- a/audio.go +++ b/audio.go @@ -20,6 +20,7 @@ const ( type AudioRequest struct { Model string FilePath string + File *multipart.File Prompt string // For translation, it should be in English Temperature float32 Language string // For translation, just do not use it. It seems "en" works, not confirmed... @@ -75,27 +76,33 @@ func (c *Client) callAudioAPI( // audioMultipartForm creates a form with audio file contents and the name of the model to use for // audio processing. func audioMultipartForm(request AudioRequest, w *multipart.Writer) error { - f, err := os.Open(request.FilePath) - if err != nil { - return fmt.Errorf("opening audio file: %w", err) - } - - fw, err := w.CreateFormFile("file", f.Name()) + fw, err := w.CreateFormFile("file", request.FilePath) if err != nil { return fmt.Errorf("creating form file: %w", err) } - if _, err = io.Copy(fw, f); err != nil { - return fmt.Errorf("reading from opened audio file: %w", err) + if request.File == nil { + f, err := os.Open(request.FilePath) + if err != nil { + return fmt.Errorf("opening audio file: %w", err) + } + + if _, err = io.Copy(fw, f); err != nil { + return fmt.Errorf("reading from opened audio file: %w", err) + } + } else { + if _, err = io.Copy(fw, *request.File); err != nil { + return fmt.Errorf("reading from opened audio file: %w", err) + } } fw, err = w.CreateFormField("model") if err != nil { return fmt.Errorf("creating form field: %w", err) } - + modelName := bytes.NewReader([]byte(request.Model)) - if _, err = io.Copy(fw, modelName); err != nil { + if _, err := io.Copy(fw, modelName); err != nil { return fmt.Errorf("writing model name: %w", err) } diff --git a/audio_test.go b/audio_test.go index 8a9b5783d..f8936a6ac 100644 --- a/audio_test.go +++ b/audio_test.go @@ -11,8 +11,8 @@ import ( "path/filepath" "strings" - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "testing" diff --git a/chat_stream_test.go b/chat_stream_test.go index e3da2daf7..ed76fe3df 100644 --- a/chat_stream_test.go +++ b/chat_stream_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/chat_test.go b/chat_test.go index 8866ff2ae..caacad69b 100644 --- a/chat_test.go +++ b/chat_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/completion_test.go b/completion_test.go index daa02e383..cc0332426 100644 --- a/completion_test.go +++ b/completion_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/edits_test.go b/edits_test.go index 6a16f7c2c..ddc64f873 100644 --- a/edits_test.go +++ b/edits_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/embeddings_test.go b/embeddings_test.go index 2aa48c51e..698b9a675 100644 --- a/embeddings_test.go +++ b/embeddings_test.go @@ -1,7 +1,7 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" + . "github.com/giordanobsf/go-openai" "bytes" "encoding/json" diff --git a/files_test.go b/files_test.go index 6a78ce104..dae894764 100644 --- a/files_test.go +++ b/files_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/fine_tunes_test.go b/fine_tunes_test.go index 1f6f96764..0f987f2ec 100644 --- a/fine_tunes_test.go +++ b/fine_tunes_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/go.mod b/go.mod index 42cc7b391..f3262ac2c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/sashabaranov/go-openai +module github.com/giordanobsf/go-openai go 1.18 diff --git a/image_test.go b/image_test.go index b7949c896..da9b14e3e 100644 --- a/image_test.go +++ b/image_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/models_test.go b/models_test.go index 972a5fe64..ea61b154a 100644 --- a/models_test.go +++ b/models_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/moderation_test.go b/moderation_test.go index f50124534..15e2013cd 100644 --- a/moderation_test.go +++ b/moderation_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "encoding/json" diff --git a/request_builder_test.go b/request_builder_test.go index f0f99ee5b..d1ec1564f 100644 --- a/request_builder_test.go +++ b/request_builder_test.go @@ -1,7 +1,7 @@ package openai //nolint:testpackage // testing private field import ( - "github.com/sashabaranov/go-openai/internal/test" + "github.com/giordanobsf/go-openai/internal/test" "context" "errors" diff --git a/stream_test.go b/stream_test.go index 8f89e6b85..a757ba2a2 100644 --- a/stream_test.go +++ b/stream_test.go @@ -1,8 +1,8 @@ package openai_test import ( - . "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + . "github.com/giordanobsf/go-openai" + "github.com/giordanobsf/go-openai/internal/test" "context" "errors"