From 02a1da97a4389fc7966249337a1e365902bef96b Mon Sep 17 00:00:00 2001 From: Skye Gill Date: Mon, 13 May 2024 12:16:24 +0100 Subject: [PATCH 1/9] feat: add top_k & repetition_penalty to completion request --- completion.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/completion.go b/completion.go index 00f43ff1c..4ea4a44a5 100644 --- a/completion.go +++ b/completion.go @@ -144,6 +144,9 @@ type CompletionRequest struct { // refs: https://platform.openai.com/docs/api-reference/completions/create#completions/create-logit_bias LogitBias map[string]int `json:"logit_bias,omitempty"` User string `json:"user,omitempty"` + + TopK int32 `json:"top_k,omitempty"` + RepetitionPenalty float64 `json:"repetition_penalty,omitempty"` } // CompletionChoice represents one of possible completions. From 89e8ae32b598a3b4f0cfb00f7d9435eed500e560 Mon Sep 17 00:00:00 2001 From: Skye Gill Date: Mon, 13 May 2024 12:19:07 +0100 Subject: [PATCH 2/9] fix: fork replace --- .github/FUNDING.yml | 2 +- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CONTRIBUTING.md | 12 +++---- README.md | 42 +++++++++++------------ api_integration_test.go | 6 ++-- assistant_test.go | 4 +-- audio.go | 2 +- audio_api_test.go | 6 ++-- audio_test.go | 4 +-- chat_stream_test.go | 4 +-- chat_test.go | 6 ++-- client.go | 2 +- client_test.go | 4 +-- completion_test.go | 4 +-- config_test.go | 2 +- edits_test.go | 4 +-- embeddings_test.go | 4 +-- engines_test.go | 4 +-- error.go | 4 +-- error_test.go | 2 +- example_test.go | 2 +- examples/chatbot/main.go | 2 +- examples/completion-with-tool/main.go | 4 +-- examples/completion/main.go | 2 +- examples/images/main.go | 2 +- examples/voice-to-text/main.go | 2 +- files_api_test.go | 4 +-- files_test.go | 4 +-- fine_tunes_test.go | 4 +-- fine_tuning_job_test.go | 4 +-- go.mod | 2 +- image_api_test.go | 4 +-- image_test.go | 4 +-- internal/error_accumulator_test.go | 4 +-- internal/form_builder_test.go | 4 +-- internal/test/helpers.go | 2 +- jsonschema/json_test.go | 2 +- messages_test.go | 4 +-- models_test.go | 4 +-- moderation_test.go | 4 +-- openai_test.go | 4 +-- run_test.go | 4 +-- speech_test.go | 6 ++-- stream_reader.go | 2 +- stream_reader_test.go | 6 ++-- stream_test.go | 4 +-- thread_test.go | 4 +-- 49 files changed, 109 insertions(+), 109 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index e36c38239..9f25acc17 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ # These are supported funding model platforms -github: [sashabaranov, vvatanabe] +github: [lookfirst-io, vvatanabe] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 536a2ee29..14305e816 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,7 +8,7 @@ assignees: '' --- Your issue may already be reported! -Please search on the [issue tracker](https://github.com/sashabaranov/go-openai/issues) before creating one. +Please search on the [issue tracker](https://github.com/lookfirst-io/go-openai/issues) before creating one. **Describe the bug** A clear and concise description of what the bug is. If it's an API-related bug, please provide relevant endpoint(s). diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 2359e5c00..b40b9a039 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -8,7 +8,7 @@ assignees: '' --- Your issue may already be reported! -Please search on the [issue tracker](https://github.com/sashabaranov/go-openai/issues) before creating one. +Please search on the [issue tracker](https://github.com/lookfirst-io/go-openai/issues) before creating one. **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 222c065ce..1393a453f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,5 @@ A similar PR may already be submitted! -Please search among the [Pull request](https://github.com/sashabaranov/go-openai/pulls) before creating one. +Please search among the [Pull request](https://github.com/lookfirst-io/go-openai/pulls) before creating one. If your changes introduce breaking changes, please prefix the title of your pull request with "[BREAKING_CHANGES]". This allows for clear identification of such changes in the 'What's Changed' section on the release page, making it developer-friendly. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4dd184042..8427a2d4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,22 +1,22 @@ # Contributing Guidelines ## Overview -Thank you for your interest in contributing to the "Go OpenAI" project! By following this guideline, we hope to ensure that your contributions are made smoothly and efficiently. The Go OpenAI project is licensed under the [Apache 2.0 License](https://github.com/sashabaranov/go-openai/blob/master/LICENSE), and we welcome contributions through GitHub pull requests. +Thank you for your interest in contributing to the "Go OpenAI" project! By following this guideline, we hope to ensure that your contributions are made smoothly and efficiently. The Go OpenAI project is licensed under the [Apache 2.0 License](https://github.com/lookfirst-io/go-openai/blob/master/LICENSE), and we welcome contributions through GitHub pull requests. ## Reporting Bugs -If you discover a bug, first check the [GitHub Issues page](https://github.com/sashabaranov/go-openai/issues) to see if the issue has already been reported. If you're reporting a new issue, please use the "Bug report" template and provide detailed information about the problem, including steps to reproduce it. +If you discover a bug, first check the [GitHub Issues page](https://github.com/lookfirst-io/go-openai/issues) to see if the issue has already been reported. If you're reporting a new issue, please use the "Bug report" template and provide detailed information about the problem, including steps to reproduce it. ## Suggesting Features -If you want to suggest a new feature or improvement, first check the [GitHub Issues page](https://github.com/sashabaranov/go-openai/issues) to ensure a similar suggestion hasn't already been made. Use the "Feature request" template to provide a detailed description of your suggestion. +If you want to suggest a new feature or improvement, first check the [GitHub Issues page](https://github.com/lookfirst-io/go-openai/issues) to ensure a similar suggestion hasn't already been made. Use the "Feature request" template to provide a detailed description of your suggestion. ## Reporting Vulnerabilities -If you identify a security concern, please use the "Report a security vulnerability" template on the [GitHub Issues page](https://github.com/sashabaranov/go-openai/issues) to share the details. This report will only be viewable to repository maintainers. You will be credited if the advisory is published. +If you identify a security concern, please use the "Report a security vulnerability" template on the [GitHub Issues page](https://github.com/lookfirst-io/go-openai/issues) to share the details. This report will only be viewable to repository maintainers. You will be credited if the advisory is published. ## Questions for Users -If you have questions, please utilize [StackOverflow](https://stackoverflow.com/) or the [GitHub Discussions page](https://github.com/sashabaranov/go-openai/discussions). +If you have questions, please utilize [StackOverflow](https://stackoverflow.com/) or the [GitHub Discussions page](https://github.com/lookfirst-io/go-openai/discussions). ## Contributing Code -There might already be a similar pull requests submitted! Please search for [pull requests](https://github.com/sashabaranov/go-openai/pulls) before creating one. +There might already be a similar pull requests submitted! Please search for [pull requests](https://github.com/lookfirst-io/go-openai/pulls) before creating one. ### Requirements for Merging a Pull Request diff --git a/README.md b/README.md index 7946f4d9b..1504e847d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Go OpenAI -[![Go Reference](https://pkg.go.dev/badge/github.com/sashabaranov/go-openai.svg)](https://pkg.go.dev/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) +[![Go Reference](https://pkg.go.dev/badge/github.com/lookfirst-io/go-openai.svg)](https://pkg.go.dev/github.com/lookfirst-io/go-openai) +[![Go Report Card](https://goreportcard.com/badge/github.com/lookfirst-io/go-openai)](https://goreportcard.com/report/github.com/lookfirst-io/go-openai) +[![codecov](https://codecov.io/gh/lookfirst-io/go-openai/branch/master/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/lookfirst-io/go-openai) This library provides unofficial Go clients for [OpenAI API](https://platform.openai.com/). We support: @@ -13,7 +13,7 @@ This library provides unofficial Go clients for [OpenAI API](https://platform.op ## Installation ``` -go get github.com/sashabaranov/go-openai +go get github.com/lookfirst-io/go-openai ``` Currently, go-openai requires Go version 1.18 or greater. @@ -28,7 +28,7 @@ package main import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -80,7 +80,7 @@ import ( "errors" "fmt" "io" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -133,7 +133,7 @@ package main import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -166,7 +166,7 @@ import ( "context" "fmt" "io" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -215,7 +215,7 @@ import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -247,7 +247,7 @@ import ( "fmt" "os" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -288,7 +288,7 @@ import ( "context" "encoding/base64" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" "image/png" "os" ) @@ -376,7 +376,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/lookfirst-io/go-openai#ClientConfig
@@ -392,7 +392,7 @@ import ( "os" "strings" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func main() { @@ -446,7 +446,7 @@ import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -492,7 +492,7 @@ package main import ( "context" "log" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) @@ -549,7 +549,7 @@ import ( "context" "fmt" - openai "github.com/sashabaranov/go-openai" + openai "github.com/lookfirst-io/go-openai" ) func main() { @@ -680,7 +680,7 @@ package main import ( "context" "fmt" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func main() { @@ -764,7 +764,7 @@ Due to the factors mentioned above, different answers may be returned even for t By adopting these strategies, you can expect more consistent results. **Related Issues:** -[omitempty option of request struct will generate incorrect request when parameter is 0.](https://github.com/sashabaranov/go-openai/issues/9) +[omitempty option of request struct will generate incorrect request when parameter is 0.](https://github.com/lookfirst-io/go-openai/issues/9) ### Does Go OpenAI provide a method to count tokens? @@ -775,15 +775,15 @@ For counting tokens, you might find the following links helpful: - [How to count tokens with tiktoken](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) **Related Issues:** -[Is it possible to join the implementation of GPT3 Tokenizer](https://github.com/sashabaranov/go-openai/issues/62) +[Is it possible to join the implementation of GPT3 Tokenizer](https://github.com/lookfirst-io/go-openai/issues/62) ## Contributing -By following [Contributing Guidelines](https://github.com/sashabaranov/go-openai/blob/master/CONTRIBUTING.md), we hope to ensure that your contributions are made smoothly and efficiently. +By following [Contributing Guidelines](https://github.com/lookfirst-io/go-openai/blob/master/CONTRIBUTING.md), we hope to ensure that your contributions are made smoothly and efficiently. ## Thank you -We want to take a moment to express our deepest gratitude to the [contributors](https://github.com/sashabaranov/go-openai/graphs/contributors) and sponsors of this project: +We want to take a moment to express our deepest gratitude to the [contributors](https://github.com/lookfirst-io/go-openai/graphs/contributors) and sponsors of this project: - [Carson Kahn](https://carsonkahn.com) of [Spindle AI](https://spindleai.com) To all of you: thank you. You've helped us achieve more than we ever imagined possible. Can't wait to see where we go next, together! diff --git a/api_integration_test.go b/api_integration_test.go index 736040c50..ff6f5db6b 100644 --- a/api_integration_test.go +++ b/api_integration_test.go @@ -9,9 +9,9 @@ import ( "os" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" - "github.com/sashabaranov/go-openai/jsonschema" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai/jsonschema" ) func TestAPI(t *testing.T) { diff --git a/assistant_test.go b/assistant_test.go index 40de0e50f..89a6d0484 100644 --- a/assistant_test.go +++ b/assistant_test.go @@ -3,8 +3,8 @@ package openai_test import ( "context" - openai "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + openai "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" "encoding/json" "fmt" diff --git a/audio.go b/audio.go index dbc26d154..8bf3f782d 100644 --- a/audio.go +++ b/audio.go @@ -8,7 +8,7 @@ import ( "net/http" "os" - utils "github.com/sashabaranov/go-openai/internal" + utils "github.com/lookfirst-io/go-openai/internal" ) // Whisper Defines the models provided by OpenAI to use when processing audio with OpenAI. diff --git a/audio_api_test.go b/audio_api_test.go index c24598443..6a347fae2 100644 --- a/audio_api_test.go +++ b/audio_api_test.go @@ -12,9 +12,9 @@ import ( "strings" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) // TestAudio Tests the transcription and translation endpoints of the API using the mocked server. diff --git a/audio_test.go b/audio_test.go index 235931f36..c8e4b9921 100644 --- a/audio_test.go +++ b/audio_test.go @@ -8,8 +8,8 @@ import ( "path/filepath" "testing" - "github.com/sashabaranov/go-openai/internal/test" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai/internal/test" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestAudioWithFailingFormBuilder(t *testing.T) { diff --git a/chat_stream_test.go b/chat_stream_test.go index 63e45ee23..9ccb8b01c 100644 --- a/chat_stream_test.go +++ b/chat_stream_test.go @@ -10,8 +10,8 @@ import ( "strconv" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestChatCompletionsStreamWrongModel(t *testing.T) { diff --git a/chat_test.go b/chat_test.go index 520bf5ca4..8782312de 100644 --- a/chat_test.go +++ b/chat_test.go @@ -12,9 +12,9 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" - "github.com/sashabaranov/go-openai/jsonschema" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai/jsonschema" ) const ( diff --git a/client.go b/client.go index c57ba17c7..2484ed70b 100644 --- a/client.go +++ b/client.go @@ -9,7 +9,7 @@ import ( "net/http" "strings" - utils "github.com/sashabaranov/go-openai/internal" + utils "github.com/lookfirst-io/go-openai/internal" ) // Client is OpenAI GPT-3 API client. diff --git a/client_test.go b/client_test.go index a08d10f21..5860ace5c 100644 --- a/client_test.go +++ b/client_test.go @@ -10,8 +10,8 @@ import ( "reflect" "testing" - "github.com/sashabaranov/go-openai/internal/test" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai/internal/test" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) var errTestRequestBuilderFailed = errors.New("test request builder failed") diff --git a/completion_test.go b/completion_test.go index 89950bf94..34a5040df 100644 --- a/completion_test.go +++ b/completion_test.go @@ -12,8 +12,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestCompletionsWrongModel(t *testing.T) { diff --git a/config_test.go b/config_test.go index 3e528c3e9..c1e829b48 100644 --- a/config_test.go +++ b/config_test.go @@ -3,7 +3,7 @@ package openai_test import ( "testing" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func TestGetAzureDeploymentByModel(t *testing.T) { diff --git a/edits_test.go b/edits_test.go index d2a6db40d..363c8cedd 100644 --- a/edits_test.go +++ b/edits_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) // TestEdits Tests the edits endpoint of the API using the mocked server. diff --git a/embeddings_test.go b/embeddings_test.go index 438978169..5a60ec949 100644 --- a/embeddings_test.go +++ b/embeddings_test.go @@ -11,8 +11,8 @@ import ( "reflect" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestEmbedding(t *testing.T) { diff --git a/engines_test.go b/engines_test.go index d26aa5541..db7bd45c2 100644 --- a/engines_test.go +++ b/engines_test.go @@ -7,8 +7,8 @@ import ( "net/http" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) // TestGetEngine Tests the retrieve engine endpoint of the API using the mocked server. diff --git a/error.go b/error.go index 37959a272..5e70f02f6 100644 --- a/error.go +++ b/error.go @@ -51,7 +51,7 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) { err = json.Unmarshal(rawMap["message"], &e.Message) if err != nil { // If the parameter field of a function call is invalid as a JSON schema - // refs: https://github.com/sashabaranov/go-openai/issues/381 + // refs: https://github.com/lookfirst-io/go-openai/issues/381 var messages []string err = json.Unmarshal(rawMap["message"], &messages) if err != nil { @@ -61,7 +61,7 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) { } // optional fields for azure openai - // refs: https://github.com/sashabaranov/go-openai/issues/343 + // refs: https://github.com/lookfirst-io/go-openai/issues/343 if _, ok := rawMap["type"]; ok { err = json.Unmarshal(rawMap["type"], &e.Type) if err != nil { diff --git a/error_test.go b/error_test.go index 48cbe4f29..8d5f9e0c7 100644 --- a/error_test.go +++ b/error_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func TestAPIErrorUnmarshalJSON(t *testing.T) { diff --git a/example_test.go b/example_test.go index de67c57cd..014b6dc2c 100644 --- a/example_test.go +++ b/example_test.go @@ -11,7 +11,7 @@ import ( "net/url" "os" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func Example() { diff --git a/examples/chatbot/main.go b/examples/chatbot/main.go index ad41e957d..138874221 100644 --- a/examples/chatbot/main.go +++ b/examples/chatbot/main.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func main() { diff --git a/examples/completion-with-tool/main.go b/examples/completion-with-tool/main.go index 26126e41b..973f07541 100644 --- a/examples/completion-with-tool/main.go +++ b/examples/completion-with-tool/main.go @@ -5,8 +5,8 @@ import ( "fmt" "os" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/jsonschema" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/jsonschema" ) func main() { diff --git a/examples/completion/main.go b/examples/completion/main.go index 22af1fd82..3b7ae5008 100644 --- a/examples/completion/main.go +++ b/examples/completion/main.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func main() { diff --git a/examples/images/main.go b/examples/images/main.go index 5ee649d22..bd0d980ee 100644 --- a/examples/images/main.go +++ b/examples/images/main.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func main() { diff --git a/examples/voice-to-text/main.go b/examples/voice-to-text/main.go index 713e748e1..f767039d5 100644 --- a/examples/voice-to-text/main.go +++ b/examples/voice-to-text/main.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/sashabaranov/go-openai" + "github.com/lookfirst-io/go-openai" ) func main() { diff --git a/files_api_test.go b/files_api_test.go index c92162a84..a7afc73d4 100644 --- a/files_api_test.go +++ b/files_api_test.go @@ -12,8 +12,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestFileBytesUpload(t *testing.T) { diff --git a/files_test.go b/files_test.go index 3c1b99fb4..704e82292 100644 --- a/files_test.go +++ b/files_test.go @@ -7,8 +7,8 @@ import ( "os" "testing" - utils "github.com/sashabaranov/go-openai/internal" - "github.com/sashabaranov/go-openai/internal/test/checks" + utils "github.com/lookfirst-io/go-openai/internal" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestFileBytesUploadWithFailingFormBuilder(t *testing.T) { diff --git a/fine_tunes_test.go b/fine_tunes_test.go index 2ab6817f7..ef10e5b13 100644 --- a/fine_tunes_test.go +++ b/fine_tunes_test.go @@ -7,8 +7,8 @@ import ( "net/http" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) const testFineTuneID = "fine-tune-id" diff --git a/fine_tuning_job_test.go b/fine_tuning_job_test.go index d2fbcd4c7..e0cd31784 100644 --- a/fine_tuning_job_test.go +++ b/fine_tuning_job_test.go @@ -7,8 +7,8 @@ import ( "net/http" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) const testFineTuninigJobID = "fine-tuning-job-id" diff --git a/go.mod b/go.mod index 42cc7b391..0b8b631af 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/sashabaranov/go-openai +module github.com/lookfirst-io/go-openai go 1.18 diff --git a/image_api_test.go b/image_api_test.go index 48416b1e2..c85eedd81 100644 --- a/image_api_test.go +++ b/image_api_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestImages(t *testing.T) { diff --git a/image_test.go b/image_test.go index 9332dd5cd..16f6f0149 100644 --- a/image_test.go +++ b/image_test.go @@ -1,8 +1,8 @@ package openai //nolint:testpackage // testing private field import ( - utils "github.com/sashabaranov/go-openai/internal" - "github.com/sashabaranov/go-openai/internal/test/checks" + utils "github.com/lookfirst-io/go-openai/internal" + "github.com/lookfirst-io/go-openai/internal/test/checks" "context" "fmt" diff --git a/internal/error_accumulator_test.go b/internal/error_accumulator_test.go index d48f28177..fa4de0d1e 100644 --- a/internal/error_accumulator_test.go +++ b/internal/error_accumulator_test.go @@ -5,8 +5,8 @@ import ( "errors" "testing" - utils "github.com/sashabaranov/go-openai/internal" - "github.com/sashabaranov/go-openai/internal/test" + utils "github.com/lookfirst-io/go-openai/internal" + "github.com/lookfirst-io/go-openai/internal/test" ) func TestErrorAccumulatorBytes(t *testing.T) { diff --git a/internal/form_builder_test.go b/internal/form_builder_test.go index d3faf9982..a7bf532f5 100644 --- a/internal/form_builder_test.go +++ b/internal/form_builder_test.go @@ -1,8 +1,8 @@ package openai //nolint:testpackage // testing private field import ( - "github.com/sashabaranov/go-openai/internal/test" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai/internal/test" + "github.com/lookfirst-io/go-openai/internal/test/checks" "bytes" "errors" diff --git a/internal/test/helpers.go b/internal/test/helpers.go index 0e63ae82f..042522d4b 100644 --- a/internal/test/helpers.go +++ b/internal/test/helpers.go @@ -1,7 +1,7 @@ package test import ( - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai/internal/test/checks" "net/http" "os" diff --git a/jsonschema/json_test.go b/jsonschema/json_test.go index 744706082..24792fc8f 100644 --- a/jsonschema/json_test.go +++ b/jsonschema/json_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/sashabaranov/go-openai/jsonschema" + "github.com/lookfirst-io/go-openai/jsonschema" ) func TestDefinition_MarshalJSON(t *testing.T) { diff --git a/messages_test.go b/messages_test.go index a18be20bd..7f184d9e7 100644 --- a/messages_test.go +++ b/messages_test.go @@ -7,8 +7,8 @@ import ( "net/http" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) var emptyStr = "" diff --git a/models_test.go b/models_test.go index 24a28ed23..141311df1 100644 --- a/models_test.go +++ b/models_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) const testFineTuneModelID = "fine-tune-model-id" diff --git a/moderation_test.go b/moderation_test.go index 61171c384..747a2bebf 100644 --- a/moderation_test.go +++ b/moderation_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) // TestModeration Tests the moderations endpoint of the API using the mocked server. diff --git a/openai_test.go b/openai_test.go index 729d8880c..9cccd4b89 100644 --- a/openai_test.go +++ b/openai_test.go @@ -1,8 +1,8 @@ package openai_test import ( - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test" ) func setupOpenAITestServer() (client *openai.Client, server *test.ServerTest, teardown func()) { diff --git a/run_test.go b/run_test.go index cdf99db05..b1474ced3 100644 --- a/run_test.go +++ b/run_test.go @@ -3,8 +3,8 @@ package openai_test import ( "context" - openai "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + openai "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" "encoding/json" "fmt" diff --git a/speech_test.go b/speech_test.go index d9ba58b13..c815a7008 100644 --- a/speech_test.go +++ b/speech_test.go @@ -11,9 +11,9 @@ import ( "path/filepath" "testing" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestSpeechIntegration(t *testing.T) { diff --git a/stream_reader.go b/stream_reader.go index 4210a1948..156bbc45f 100644 --- a/stream_reader.go +++ b/stream_reader.go @@ -7,7 +7,7 @@ import ( "io" "net/http" - utils "github.com/sashabaranov/go-openai/internal" + utils "github.com/lookfirst-io/go-openai/internal" ) var ( diff --git a/stream_reader_test.go b/stream_reader_test.go index cd6e46eff..25c10eafd 100644 --- a/stream_reader_test.go +++ b/stream_reader_test.go @@ -6,9 +6,9 @@ import ( "errors" "testing" - utils "github.com/sashabaranov/go-openai/internal" - "github.com/sashabaranov/go-openai/internal/test" - "github.com/sashabaranov/go-openai/internal/test/checks" + utils "github.com/lookfirst-io/go-openai/internal" + "github.com/lookfirst-io/go-openai/internal/test" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) var errTestUnmarshalerFailed = errors.New("test unmarshaler failed") diff --git a/stream_test.go b/stream_test.go index 2822a3535..8a808284e 100644 --- a/stream_test.go +++ b/stream_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) func TestCompletionsStreamWrongModel(t *testing.T) { diff --git a/thread_test.go b/thread_test.go index 1ac0f3c0e..967433b34 100644 --- a/thread_test.go +++ b/thread_test.go @@ -7,8 +7,8 @@ import ( "net/http" "testing" - openai "github.com/sashabaranov/go-openai" - "github.com/sashabaranov/go-openai/internal/test/checks" + openai "github.com/lookfirst-io/go-openai" + "github.com/lookfirst-io/go-openai/internal/test/checks" ) // TestThread Tests the thread endpoint of the API using the mocked server. From 78803c397e6c5c44d29baf3436c7b4836ebcd92e Mon Sep 17 00:00:00 2001 From: Skye Gill Date: Tue, 14 May 2024 17:56:20 +0100 Subject: [PATCH 3/9] feat: disable supported models check --- stream.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stream.go b/stream.go index b277f3c29..3b5e9135a 100644 --- a/stream.go +++ b/stream.go @@ -22,10 +22,10 @@ func (c *Client) CreateCompletionStream( request CompletionRequest, ) (stream *CompletionStream, err error) { urlSuffix := "/completions" - if !checkEndpointSupportsModel(urlSuffix, request.Model) { - err = ErrCompletionUnsupportedModel - return - } + //if !checkEndpointSupportsModel(urlSuffix, request.Model) { + // err = ErrCompletionUnsupportedModel + // return + //} if !checkPromptType(request.Prompt) { err = ErrCompletionRequestPromptTypeNotSupported From 432d878d247150f213576bb00309b790831adcb8 Mon Sep 17 00:00:00 2001 From: Arash Khazraie Date: Fri, 21 Jun 2024 12:07:25 -0700 Subject: [PATCH 4/9] adds min_p --- chat.go | 1 + completion.go | 1 + edits.go | 1 + 3 files changed, 3 insertions(+) diff --git a/chat.go b/chat.go index a1eb11720..aedd5e6f0 100644 --- a/chat.go +++ b/chat.go @@ -189,6 +189,7 @@ type ChatCompletionRequest struct { MaxTokens int `json:"max_tokens,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` + MinP float32 `json:"min_p,omitempty"` N int `json:"n,omitempty"` Stream bool `json:"stream,omitempty"` Stop []string `json:"stop,omitempty"` diff --git a/completion.go b/completion.go index 4ea4a44a5..88bd909b9 100644 --- a/completion.go +++ b/completion.go @@ -131,6 +131,7 @@ type CompletionRequest struct { MaxTokens int `json:"max_tokens,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` + MinP float32 `json:"min_p,omitempty"` N int `json:"n,omitempty"` Stream bool `json:"stream,omitempty"` LogProbs int `json:"logprobs,omitempty"` diff --git a/edits.go b/edits.go index 97d026029..7aa381528 100644 --- a/edits.go +++ b/edits.go @@ -14,6 +14,7 @@ type EditsRequest struct { N int `json:"n,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` + MinP float32 `json:"min_p,omitempty"` } // EditsChoice represents one of possible edits. From 4abf4719928f33e643197c2b7e8b700c8ad925aa Mon Sep 17 00:00:00 2001 From: Arash Khazraie Date: Fri, 21 Jun 2024 12:09:22 -0700 Subject: [PATCH 5/9] update go mod --- go.mod | 2 ++ go.sum | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 go.sum diff --git a/go.mod b/go.mod index 0b8b631af..995d4f91f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/lookfirst-io/go-openai go 1.18 + +require github.com/sashabaranov/go-openai v1.26.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..5ac9d401b --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/sashabaranov/go-openai v1.26.0 h1:upM565hxdqvCxNzuAcEBZ1XsfGehH0/9kgk9rFVpDxQ= +github.com/sashabaranov/go-openai v1.26.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= From 3b11a0065110763171835857e19db81ff932db50 Mon Sep 17 00:00:00 2001 From: Arash Khazraie Date: Mon, 24 Jun 2024 10:00:02 -0700 Subject: [PATCH 6/9] update go mod --- go.mod | 2 -- go.sum | 2 -- 2 files changed, 4 deletions(-) diff --git a/go.mod b/go.mod index 995d4f91f..0b8b631af 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/lookfirst-io/go-openai go 1.18 - -require github.com/sashabaranov/go-openai v1.26.0 // indirect diff --git a/go.sum b/go.sum index 5ac9d401b..e69de29bb 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +0,0 @@ -github.com/sashabaranov/go-openai v1.26.0 h1:upM565hxdqvCxNzuAcEBZ1XsfGehH0/9kgk9rFVpDxQ= -github.com/sashabaranov/go-openai v1.26.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= From 9dddaf0bcdc8f55c497c7b3acb63e92f81d4acb1 Mon Sep 17 00:00:00 2001 From: Arash Khazraie Date: Fri, 12 Jul 2024 12:40:13 -0700 Subject: [PATCH 7/9] add url to stream function --- api_internal_test.go | 4 ++-- assistant.go | 18 +++++++++--------- client.go | 4 ++-- client_test.go | 4 ++-- engines.go | 4 ++-- example_test.go | 1 + files.go | 12 ++++++------ fine_tunes.go | 12 ++++++------ fine_tuning_job.go | 8 ++++---- messages.go | 12 ++++++------ models.go | 6 +++--- run.go | 18 +++++++++--------- stream.go | 3 ++- stream_test.go | 15 ++++++++------- thread.go | 8 ++++---- 15 files changed, 66 insertions(+), 63 deletions(-) diff --git a/api_internal_test.go b/api_internal_test.go index a590ec9ab..0dcbebe1b 100644 --- a/api_internal_test.go +++ b/api_internal_test.go @@ -27,7 +27,7 @@ func TestOpenAIFullURL(t *testing.T) { t.Run(c.Name, func(t *testing.T) { az := DefaultConfig("dummy") cli := NewClientWithConfig(az) - actual := cli.fullURL(c.Suffix) + actual := cli.fullURL(c.Expect, c.Suffix) if actual != c.Expect { t.Errorf("Expected %s, got %s", c.Expect, actual) } @@ -176,7 +176,7 @@ func TestCloudflareAzureFullURL(t *testing.T) { cli := NewClientWithConfig(az) - actual := cli.fullURL("/chat/completions") + actual := cli.fullURL(az.BaseURL, "/chat/completions") if actual != c.Expect { t.Errorf("Expected %s, got %s", c.Expect, actual) } diff --git a/assistant.go b/assistant.go index 661681e83..2f96859c3 100644 --- a/assistant.go +++ b/assistant.go @@ -114,7 +114,7 @@ type AssistantFilesList struct { // CreateAssistant creates a new assistant. func (c *Client) CreateAssistant(ctx context.Context, request AssistantRequest) (response Assistant, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(assistantsSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, assistantsSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -130,7 +130,7 @@ func (c *Client) RetrieveAssistant( assistantID string, ) (response Assistant, err error) { urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -147,7 +147,7 @@ func (c *Client) ModifyAssistant( request AssistantRequest, ) (response Assistant, err error) { urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -163,7 +163,7 @@ func (c *Client) DeleteAssistant( assistantID string, ) (response AssistantDeleteResponse, err error) { urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID) - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -201,7 +201,7 @@ func (c *Client) ListAssistants( } urlSuffix := fmt.Sprintf("%s%s", assistantsSuffix, encodedValues) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -218,7 +218,7 @@ func (c *Client) CreateAssistantFile( request AssistantFileRequest, ) (response AssistantFile, err error) { urlSuffix := fmt.Sprintf("%s/%s%s", assistantsSuffix, assistantID, assistantsFilesSuffix) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -236,7 +236,7 @@ func (c *Client) RetrieveAssistantFile( fileID string, ) (response AssistantFile, err error) { urlSuffix := fmt.Sprintf("%s/%s%s/%s", assistantsSuffix, assistantID, assistantsFilesSuffix, fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -253,7 +253,7 @@ func (c *Client) DeleteAssistantFile( fileID string, ) (err error) { urlSuffix := fmt.Sprintf("%s/%s%s/%s", assistantsSuffix, assistantID, assistantsFilesSuffix, fileID) - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -292,7 +292,7 @@ func (c *Client) ListAssistantFiles( } urlSuffix := fmt.Sprintf("%s/%s%s%s", assistantsSuffix, assistantID, assistantsFilesSuffix, encodedValues) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return diff --git a/client.go b/client.go index 2484ed70b..3e7c43a34 100644 --- a/client.go +++ b/client.go @@ -223,7 +223,7 @@ func decodeString(body io.Reader, output *string) error { // fullURL returns full URL for request. // args[0] is model name, if API type is Azure, model name is required to get deployment name. -func (c *Client) fullURL(suffix string, args ...any) string { +func (c *Client) fullURL(baseURL string, suffix string, args ...any) string { // /openai/deployments/{model}/chat/completions?api-version={api_version} if c.config.APIType == APITypeAzure || c.config.APIType == APITypeAzureAD { baseURL := c.config.BaseURL @@ -253,7 +253,7 @@ func (c *Client) fullURL(suffix string, args ...any) string { return fmt.Sprintf("%s%s?api-version=%s", baseURL, suffix, c.config.APIVersion) } - return fmt.Sprintf("%s%s", c.config.BaseURL, suffix) + return fmt.Sprintf("%s%s", baseURL, suffix) } func (c *Client) handleErrorResp(resp *http.Response) error { diff --git a/client_test.go b/client_test.go index 5860ace5c..a5cb7009e 100644 --- a/client_test.go +++ b/client_test.go @@ -229,7 +229,7 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) { return client.CreateCompletion(ctx, CompletionRequest{Prompt: "testing"}) }}, {"CreateCompletionStream", func() (any, error) { - return client.CreateCompletionStream(ctx, CompletionRequest{Prompt: ""}) + return client.CreateCompletionStream(ctx, CompletionRequest{Prompt: ""}, config.BaseURL) }}, {"CreateChatCompletion", func() (any, error) { return client.CreateChatCompletion(ctx, ChatCompletionRequest{Model: GPT3Dot5Turbo}) @@ -415,7 +415,7 @@ func TestClientReturnsRequestBuilderErrorsAddition(t *testing.T) { if !errors.Is(err, ErrCompletionRequestPromptTypeNotSupported) { t.Fatalf("Did not return error when request builder failed: %v", err) } - _, err = client.CreateCompletionStream(ctx, CompletionRequest{Prompt: 1}) + _, err = client.CreateCompletionStream(ctx, CompletionRequest{Prompt: 1}, config.BaseURL) if !errors.Is(err, ErrCompletionRequestPromptTypeNotSupported) { t.Fatalf("Did not return error when request builder failed: %v", err) } diff --git a/engines.go b/engines.go index 5a0dba858..31dc62bf2 100644 --- a/engines.go +++ b/engines.go @@ -26,7 +26,7 @@ type EnginesList struct { // ListEngines Lists the currently available engines, and provides basic // information about each option such as the owner and availability. func (c *Client) ListEngines(ctx context.Context) (engines EnginesList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/engines")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/engines")) if err != nil { return } @@ -42,7 +42,7 @@ func (c *Client) GetEngine( engineID string, ) (engine Engine, err error) { urlSuffix := fmt.Sprintf("/engines/%s", engineID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) if err != nil { return } diff --git a/example_test.go b/example_test.go index 014b6dc2c..5c2652dba 100644 --- a/example_test.go +++ b/example_test.go @@ -104,6 +104,7 @@ func ExampleClient_CreateCompletionStream() { Prompt: "Lorem ipsum", Stream: true, }, + "https://api.openai.com", ) if err != nil { fmt.Printf("CompletionStream error: %v\n", err) diff --git a/files.go b/files.go index b40a44f15..9986ae347 100644 --- a/files.go +++ b/files.go @@ -76,7 +76,7 @@ func (c *Client) CreateFileBytes(ctx context.Context, request FileBytesRequest) return } - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/files"), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/files"), withBody(&b), withContentType(builder.FormDataContentType())) if err != nil { return @@ -112,7 +112,7 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File return } - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/files"), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/files"), withBody(&b), withContentType(builder.FormDataContentType())) if err != nil { return @@ -124,7 +124,7 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File // DeleteFile deletes an existing file. func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) { - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/files/"+fileID)) + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, "/files/"+fileID)) if err != nil { return } @@ -136,7 +136,7 @@ func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) { // ListFiles Lists the currently available files, // and provides basic information about each file such as the file name and purpose. func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/files")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/files")) if err != nil { return } @@ -149,7 +149,7 @@ func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) { // such as the file name and purpose. func (c *Client) GetFile(ctx context.Context, fileID string) (file File, err error) { urlSuffix := fmt.Sprintf("/files/%s", fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) if err != nil { return } @@ -160,7 +160,7 @@ func (c *Client) GetFile(ctx context.Context, fileID string) (file File, err err func (c *Client) GetFileContent(ctx context.Context, fileID string) (content RawResponse, err error) { urlSuffix := fmt.Sprintf("/files/%s/content", fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) if err != nil { return } diff --git a/fine_tunes.go b/fine_tunes.go index ca840781c..999b61f9e 100644 --- a/fine_tunes.go +++ b/fine_tunes.go @@ -101,7 +101,7 @@ type FineTuneDeleteResponse struct { // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (response FineTune, err error) { urlSuffix := "/fine-tunes" - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request)) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request)) if err != nil { return } @@ -115,7 +115,7 @@ func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (r // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/fine-tunes/"+fineTuneID+"/cancel")) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/fine-tunes/"+fineTuneID+"/cancel")) if err != nil { return } @@ -128,7 +128,7 @@ func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (respons // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/fine-tunes")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/fine-tunes")) if err != nil { return } @@ -142,7 +142,7 @@ func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error) { urlSuffix := fmt.Sprintf("/fine-tunes/%s", fineTuneID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) if err != nil { return } @@ -155,7 +155,7 @@ func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response F // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (response FineTuneDeleteResponse, err error) { - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/fine-tunes/"+fineTuneID)) + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, "/fine-tunes/"+fineTuneID)) if err != nil { return } @@ -168,7 +168,7 @@ func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (respons // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) ListFineTuneEvents(ctx context.Context, fineTuneID string) (response FineTuneEventList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/fine-tunes/"+fineTuneID+"/events")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/fine-tunes/"+fineTuneID+"/events")) if err != nil { return } diff --git a/fine_tuning_job.go b/fine_tuning_job.go index 9dcb49de1..01d017e21 100644 --- a/fine_tuning_job.go +++ b/fine_tuning_job.go @@ -61,7 +61,7 @@ func (c *Client) CreateFineTuningJob( request FineTuningJobRequest, ) (response FineTuningJob, err error) { urlSuffix := "/fine_tuning/jobs" - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request)) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request)) if err != nil { return } @@ -72,7 +72,7 @@ func (c *Client) CreateFineTuningJob( // CancelFineTuningJob cancel a fine tuning job. func (c *Client) CancelFineTuningJob(ctx context.Context, fineTuningJobID string) (response FineTuningJob, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/fine_tuning/jobs/"+fineTuningJobID+"/cancel")) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/fine_tuning/jobs/" + fineTuningJobID + "/cancel")) if err != nil { return } @@ -87,7 +87,7 @@ func (c *Client) RetrieveFineTuningJob( fineTuningJobID string, ) (response FineTuningJob, err error) { urlSuffix := fmt.Sprintf("/fine_tuning/jobs/%s", fineTuningJobID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) if err != nil { return } @@ -146,7 +146,7 @@ func (c *Client) ListFineTuningJobEvents( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL("/fine_tuning/jobs/"+fineTuningJobID+"/events"+encodedValues), + c.fullURL(c.config.BaseURL, "/fine_tuning/jobs/"+fineTuningJobID+"/events"+encodedValues), ) if err != nil { return diff --git a/messages.go b/messages.go index 6af118445..22dd76575 100644 --- a/messages.go +++ b/messages.go @@ -76,7 +76,7 @@ type MessageFilesList struct { // CreateMessage creates a new message. func (c *Client) CreateMessage(ctx context.Context, threadID string, request MessageRequest) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s", threadID, messagesSuffix) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -112,7 +112,7 @@ func (c *Client) ListMessage(ctx context.Context, threadID string, } urlSuffix := fmt.Sprintf("/threads/%s/%s%s", threadID, messagesSuffix, encodedValues) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -128,7 +128,7 @@ func (c *Client) RetrieveMessage( threadID, messageID string, ) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -145,7 +145,7 @@ func (c *Client) ModifyMessage( metadata map[string]string, ) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(map[string]any{"metadata": metadata}), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -161,7 +161,7 @@ func (c *Client) RetrieveMessageFile( threadID, messageID, fileID string, ) (file MessageFile, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s/files/%s", threadID, messagesSuffix, messageID, fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -177,7 +177,7 @@ func (c *Client) ListMessageFiles( threadID, messageID string, ) (files MessageFilesList, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s/files", threadID, messagesSuffix, messageID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return diff --git a/models.go b/models.go index d94f98836..c0db9a99e 100644 --- a/models.go +++ b/models.go @@ -54,7 +54,7 @@ type ModelsList struct { // ListModels Lists the currently available models, // and provides basic information about each model such as the model id and parent. func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/models")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/models")) if err != nil { return } @@ -67,7 +67,7 @@ func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error) // the model such as the owner and permissioning. func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err error) { urlSuffix := fmt.Sprintf("/models/%s", modelID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) if err != nil { return } @@ -80,7 +80,7 @@ func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err // role in your organization to delete a model. func (c *Client) DeleteFineTuneModel(ctx context.Context, modelID string) ( response FineTuneModelDeleteResponse, err error) { - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/models/"+modelID)) + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, "/models/"+modelID)) if err != nil { return } diff --git a/run.go b/run.go index 094b0a4db..794f91a02 100644 --- a/run.go +++ b/run.go @@ -224,7 +224,7 @@ func (c *Client) CreateRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -245,7 +245,7 @@ func (c *Client) RetrieveRun( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -266,7 +266,7 @@ func (c *Client) ModifyRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -306,7 +306,7 @@ func (c *Client) ListRuns( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -326,7 +326,7 @@ func (c *Client) SubmitToolOutputs( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -346,7 +346,7 @@ func (c *Client) CancelRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -364,7 +364,7 @@ func (c *Client) CreateThreadAndRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -386,7 +386,7 @@ func (c *Client) RetrieveRunStep( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -426,7 +426,7 @@ func (c *Client) ListRunSteps( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(urlSuffix), + c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return diff --git a/stream.go b/stream.go index 3b5e9135a..e0c768dfd 100644 --- a/stream.go +++ b/stream.go @@ -20,6 +20,7 @@ type CompletionStream struct { func (c *Client) CreateCompletionStream( ctx context.Context, request CompletionRequest, + baseURL string, ) (stream *CompletionStream, err error) { urlSuffix := "/completions" //if !checkEndpointSupportsModel(urlSuffix, request.Model) { @@ -33,7 +34,7 @@ func (c *Client) CreateCompletionStream( } request.Stream = true - req, err := c.newRequest(ctx, "POST", c.fullURL(urlSuffix, request.Model), withBody(request)) + req, err := c.newRequest(ctx, "POST", c.fullURL(baseURL, urlSuffix, request.Model), withBody(request)) if err != nil { return nil, err } diff --git a/stream_test.go b/stream_test.go index 8a808284e..85477bbff 100644 --- a/stream_test.go +++ b/stream_test.go @@ -25,6 +25,7 @@ func TestCompletionsStreamWrongModel(t *testing.T) { MaxTokens: 5, Model: openai.GPT3Dot5Turbo, }, + config.BaseURL, ) if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel, but returned: %v", err) @@ -61,7 +62,7 @@ func TestCreateCompletionStream(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }) + }, "http://localhost") checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -134,7 +135,7 @@ func TestCreateCompletionStreamError(t *testing.T) { Model: openai.GPT3TextDavinci003, Prompt: "Hello!", Stream: true, - }) + }, "http://localhost") checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -172,7 +173,7 @@ func TestCreateCompletionStreamRateLimitError(t *testing.T) { Model: openai.GPT3Ada, Prompt: "Hello!", Stream: true, - }) + }, "http://localhost") if !errors.As(err, &apiErr) { t.Errorf("TestCreateCompletionStreamRateLimitError did not return APIError") } @@ -214,7 +215,7 @@ func TestCreateCompletionStreamTooManyEmptyStreamMessagesError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }) + }, "http://localhost") checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -249,7 +250,7 @@ func TestCreateCompletionStreamUnexpectedTerminatedError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }) + }, "http://localhost") checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -290,7 +291,7 @@ func TestCreateCompletionStreamBrokenJSONError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }) + }, "http://localhost") checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -317,7 +318,7 @@ func TestCreateCompletionStreamReturnTimeoutError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }) + }, "http://localhost") if err == nil { t.Fatal("Did not return error") } diff --git a/thread.go b/thread.go index 900e3f2ea..1f13bdd5f 100644 --- a/thread.go +++ b/thread.go @@ -50,7 +50,7 @@ type ThreadDeleteResponse struct { // CreateThread creates a new thread. func (c *Client) CreateThread(ctx context.Context, request ThreadRequest) (response Thread, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(threadsSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, threadsSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -63,7 +63,7 @@ func (c *Client) CreateThread(ctx context.Context, request ThreadRequest) (respo // RetrieveThread retrieves a thread. func (c *Client) RetrieveThread(ctx context.Context, threadID string) (response Thread, err error) { urlSuffix := threadsSuffix + "/" + threadID - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -80,7 +80,7 @@ func (c *Client) ModifyThread( request ModifyThreadRequest, ) (response Thread, err error) { urlSuffix := threadsSuffix + "/" + threadID - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -96,7 +96,7 @@ func (c *Client) DeleteThread( threadID string, ) (response ThreadDeleteResponse, err error) { urlSuffix := threadsSuffix + "/" + threadID - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix), + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return From e8e401e0c951ede0d8d515d5a1354d8416dcfe79 Mon Sep 17 00:00:00 2001 From: Arash Khazraie <46855206+akhazr@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:20:09 -0700 Subject: [PATCH 8/9] Revert "add url to stream function" --- api_internal_test.go | 4 ++-- assistant.go | 18 +++++++++--------- client.go | 4 ++-- client_test.go | 4 ++-- engines.go | 4 ++-- example_test.go | 1 - files.go | 12 ++++++------ fine_tunes.go | 12 ++++++------ fine_tuning_job.go | 8 ++++---- messages.go | 12 ++++++------ models.go | 6 +++--- run.go | 18 +++++++++--------- stream.go | 3 +-- stream_test.go | 15 +++++++-------- thread.go | 8 ++++---- 15 files changed, 63 insertions(+), 66 deletions(-) diff --git a/api_internal_test.go b/api_internal_test.go index 0dcbebe1b..a590ec9ab 100644 --- a/api_internal_test.go +++ b/api_internal_test.go @@ -27,7 +27,7 @@ func TestOpenAIFullURL(t *testing.T) { t.Run(c.Name, func(t *testing.T) { az := DefaultConfig("dummy") cli := NewClientWithConfig(az) - actual := cli.fullURL(c.Expect, c.Suffix) + actual := cli.fullURL(c.Suffix) if actual != c.Expect { t.Errorf("Expected %s, got %s", c.Expect, actual) } @@ -176,7 +176,7 @@ func TestCloudflareAzureFullURL(t *testing.T) { cli := NewClientWithConfig(az) - actual := cli.fullURL(az.BaseURL, "/chat/completions") + actual := cli.fullURL("/chat/completions") if actual != c.Expect { t.Errorf("Expected %s, got %s", c.Expect, actual) } diff --git a/assistant.go b/assistant.go index 2f96859c3..661681e83 100644 --- a/assistant.go +++ b/assistant.go @@ -114,7 +114,7 @@ type AssistantFilesList struct { // CreateAssistant creates a new assistant. func (c *Client) CreateAssistant(ctx context.Context, request AssistantRequest) (response Assistant, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, assistantsSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(assistantsSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -130,7 +130,7 @@ func (c *Client) RetrieveAssistant( assistantID string, ) (response Assistant, err error) { urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -147,7 +147,7 @@ func (c *Client) ModifyAssistant( request AssistantRequest, ) (response Assistant, err error) { urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -163,7 +163,7 @@ func (c *Client) DeleteAssistant( assistantID string, ) (response AssistantDeleteResponse, err error) { urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID) - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -201,7 +201,7 @@ func (c *Client) ListAssistants( } urlSuffix := fmt.Sprintf("%s%s", assistantsSuffix, encodedValues) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -218,7 +218,7 @@ func (c *Client) CreateAssistantFile( request AssistantFileRequest, ) (response AssistantFile, err error) { urlSuffix := fmt.Sprintf("%s/%s%s", assistantsSuffix, assistantID, assistantsFilesSuffix) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -236,7 +236,7 @@ func (c *Client) RetrieveAssistantFile( fileID string, ) (response AssistantFile, err error) { urlSuffix := fmt.Sprintf("%s/%s%s/%s", assistantsSuffix, assistantID, assistantsFilesSuffix, fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -253,7 +253,7 @@ func (c *Client) DeleteAssistantFile( fileID string, ) (err error) { urlSuffix := fmt.Sprintf("%s/%s%s/%s", assistantsSuffix, assistantID, assistantsFilesSuffix, fileID) - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -292,7 +292,7 @@ func (c *Client) ListAssistantFiles( } urlSuffix := fmt.Sprintf("%s/%s%s%s", assistantsSuffix, assistantID, assistantsFilesSuffix, encodedValues) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return diff --git a/client.go b/client.go index 3e7c43a34..2484ed70b 100644 --- a/client.go +++ b/client.go @@ -223,7 +223,7 @@ func decodeString(body io.Reader, output *string) error { // fullURL returns full URL for request. // args[0] is model name, if API type is Azure, model name is required to get deployment name. -func (c *Client) fullURL(baseURL string, suffix string, args ...any) string { +func (c *Client) fullURL(suffix string, args ...any) string { // /openai/deployments/{model}/chat/completions?api-version={api_version} if c.config.APIType == APITypeAzure || c.config.APIType == APITypeAzureAD { baseURL := c.config.BaseURL @@ -253,7 +253,7 @@ func (c *Client) fullURL(baseURL string, suffix string, args ...any) string { return fmt.Sprintf("%s%s?api-version=%s", baseURL, suffix, c.config.APIVersion) } - return fmt.Sprintf("%s%s", baseURL, suffix) + return fmt.Sprintf("%s%s", c.config.BaseURL, suffix) } func (c *Client) handleErrorResp(resp *http.Response) error { diff --git a/client_test.go b/client_test.go index a5cb7009e..5860ace5c 100644 --- a/client_test.go +++ b/client_test.go @@ -229,7 +229,7 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) { return client.CreateCompletion(ctx, CompletionRequest{Prompt: "testing"}) }}, {"CreateCompletionStream", func() (any, error) { - return client.CreateCompletionStream(ctx, CompletionRequest{Prompt: ""}, config.BaseURL) + return client.CreateCompletionStream(ctx, CompletionRequest{Prompt: ""}) }}, {"CreateChatCompletion", func() (any, error) { return client.CreateChatCompletion(ctx, ChatCompletionRequest{Model: GPT3Dot5Turbo}) @@ -415,7 +415,7 @@ func TestClientReturnsRequestBuilderErrorsAddition(t *testing.T) { if !errors.Is(err, ErrCompletionRequestPromptTypeNotSupported) { t.Fatalf("Did not return error when request builder failed: %v", err) } - _, err = client.CreateCompletionStream(ctx, CompletionRequest{Prompt: 1}, config.BaseURL) + _, err = client.CreateCompletionStream(ctx, CompletionRequest{Prompt: 1}) if !errors.Is(err, ErrCompletionRequestPromptTypeNotSupported) { t.Fatalf("Did not return error when request builder failed: %v", err) } diff --git a/engines.go b/engines.go index 31dc62bf2..5a0dba858 100644 --- a/engines.go +++ b/engines.go @@ -26,7 +26,7 @@ type EnginesList struct { // ListEngines Lists the currently available engines, and provides basic // information about each option such as the owner and availability. func (c *Client) ListEngines(ctx context.Context) (engines EnginesList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/engines")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/engines")) if err != nil { return } @@ -42,7 +42,7 @@ func (c *Client) GetEngine( engineID string, ) (engine Engine, err error) { urlSuffix := fmt.Sprintf("/engines/%s", engineID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) if err != nil { return } diff --git a/example_test.go b/example_test.go index 5c2652dba..014b6dc2c 100644 --- a/example_test.go +++ b/example_test.go @@ -104,7 +104,6 @@ func ExampleClient_CreateCompletionStream() { Prompt: "Lorem ipsum", Stream: true, }, - "https://api.openai.com", ) if err != nil { fmt.Printf("CompletionStream error: %v\n", err) diff --git a/files.go b/files.go index 9986ae347..b40a44f15 100644 --- a/files.go +++ b/files.go @@ -76,7 +76,7 @@ func (c *Client) CreateFileBytes(ctx context.Context, request FileBytesRequest) return } - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/files"), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/files"), withBody(&b), withContentType(builder.FormDataContentType())) if err != nil { return @@ -112,7 +112,7 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File return } - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/files"), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/files"), withBody(&b), withContentType(builder.FormDataContentType())) if err != nil { return @@ -124,7 +124,7 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File // DeleteFile deletes an existing file. func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) { - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, "/files/"+fileID)) + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/files/"+fileID)) if err != nil { return } @@ -136,7 +136,7 @@ func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) { // ListFiles Lists the currently available files, // and provides basic information about each file such as the file name and purpose. func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/files")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/files")) if err != nil { return } @@ -149,7 +149,7 @@ func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) { // such as the file name and purpose. func (c *Client) GetFile(ctx context.Context, fileID string) (file File, err error) { urlSuffix := fmt.Sprintf("/files/%s", fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) if err != nil { return } @@ -160,7 +160,7 @@ func (c *Client) GetFile(ctx context.Context, fileID string) (file File, err err func (c *Client) GetFileContent(ctx context.Context, fileID string) (content RawResponse, err error) { urlSuffix := fmt.Sprintf("/files/%s/content", fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) if err != nil { return } diff --git a/fine_tunes.go b/fine_tunes.go index 999b61f9e..ca840781c 100644 --- a/fine_tunes.go +++ b/fine_tunes.go @@ -101,7 +101,7 @@ type FineTuneDeleteResponse struct { // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (response FineTune, err error) { urlSuffix := "/fine-tunes" - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request)) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request)) if err != nil { return } @@ -115,7 +115,7 @@ func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (r // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/fine-tunes/"+fineTuneID+"/cancel")) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/fine-tunes/"+fineTuneID+"/cancel")) if err != nil { return } @@ -128,7 +128,7 @@ func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (respons // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/fine-tunes")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/fine-tunes")) if err != nil { return } @@ -142,7 +142,7 @@ func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error) { urlSuffix := fmt.Sprintf("/fine-tunes/%s", fineTuneID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) if err != nil { return } @@ -155,7 +155,7 @@ func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response F // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (response FineTuneDeleteResponse, err error) { - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, "/fine-tunes/"+fineTuneID)) + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/fine-tunes/"+fineTuneID)) if err != nil { return } @@ -168,7 +168,7 @@ func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (respons // This API will be officially deprecated on January 4th, 2024. // OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go. func (c *Client) ListFineTuneEvents(ctx context.Context, fineTuneID string) (response FineTuneEventList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/fine-tunes/"+fineTuneID+"/events")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/fine-tunes/"+fineTuneID+"/events")) if err != nil { return } diff --git a/fine_tuning_job.go b/fine_tuning_job.go index 01d017e21..9dcb49de1 100644 --- a/fine_tuning_job.go +++ b/fine_tuning_job.go @@ -61,7 +61,7 @@ func (c *Client) CreateFineTuningJob( request FineTuningJobRequest, ) (response FineTuningJob, err error) { urlSuffix := "/fine_tuning/jobs" - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request)) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request)) if err != nil { return } @@ -72,7 +72,7 @@ func (c *Client) CreateFineTuningJob( // CancelFineTuningJob cancel a fine tuning job. func (c *Client) CancelFineTuningJob(ctx context.Context, fineTuningJobID string) (response FineTuningJob, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, "/fine_tuning/jobs/" + fineTuningJobID + "/cancel")) + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/fine_tuning/jobs/"+fineTuningJobID+"/cancel")) if err != nil { return } @@ -87,7 +87,7 @@ func (c *Client) RetrieveFineTuningJob( fineTuningJobID string, ) (response FineTuningJob, err error) { urlSuffix := fmt.Sprintf("/fine_tuning/jobs/%s", fineTuningJobID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) if err != nil { return } @@ -146,7 +146,7 @@ func (c *Client) ListFineTuningJobEvents( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(c.config.BaseURL, "/fine_tuning/jobs/"+fineTuningJobID+"/events"+encodedValues), + c.fullURL("/fine_tuning/jobs/"+fineTuningJobID+"/events"+encodedValues), ) if err != nil { return diff --git a/messages.go b/messages.go index 22dd76575..6af118445 100644 --- a/messages.go +++ b/messages.go @@ -76,7 +76,7 @@ type MessageFilesList struct { // CreateMessage creates a new message. func (c *Client) CreateMessage(ctx context.Context, threadID string, request MessageRequest) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s", threadID, messagesSuffix) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -112,7 +112,7 @@ func (c *Client) ListMessage(ctx context.Context, threadID string, } urlSuffix := fmt.Sprintf("/threads/%s/%s%s", threadID, messagesSuffix, encodedValues) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -128,7 +128,7 @@ func (c *Client) RetrieveMessage( threadID, messageID string, ) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -145,7 +145,7 @@ func (c *Client) ModifyMessage( metadata map[string]string, ) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID) - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(map[string]any{"metadata": metadata}), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -161,7 +161,7 @@ func (c *Client) RetrieveMessageFile( threadID, messageID, fileID string, ) (file MessageFile, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s/files/%s", threadID, messagesSuffix, messageID, fileID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -177,7 +177,7 @@ func (c *Client) ListMessageFiles( threadID, messageID string, ) (files MessageFilesList, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s/files", threadID, messagesSuffix, messageID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return diff --git a/models.go b/models.go index c0db9a99e..d94f98836 100644 --- a/models.go +++ b/models.go @@ -54,7 +54,7 @@ type ModelsList struct { // ListModels Lists the currently available models, // and provides basic information about each model such as the model id and parent. func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error) { - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, "/models")) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/models")) if err != nil { return } @@ -67,7 +67,7 @@ func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error) // the model such as the owner and permissioning. func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err error) { urlSuffix := fmt.Sprintf("/models/%s", modelID) - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix)) + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) if err != nil { return } @@ -80,7 +80,7 @@ func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err // role in your organization to delete a model. func (c *Client) DeleteFineTuneModel(ctx context.Context, modelID string) ( response FineTuneModelDeleteResponse, err error) { - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, "/models/"+modelID)) + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL("/models/"+modelID)) if err != nil { return } diff --git a/run.go b/run.go index 794f91a02..094b0a4db 100644 --- a/run.go +++ b/run.go @@ -224,7 +224,7 @@ func (c *Client) CreateRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -245,7 +245,7 @@ func (c *Client) RetrieveRun( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -266,7 +266,7 @@ func (c *Client) ModifyRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -306,7 +306,7 @@ func (c *Client) ListRuns( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -326,7 +326,7 @@ func (c *Client) SubmitToolOutputs( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -346,7 +346,7 @@ func (c *Client) CancelRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -364,7 +364,7 @@ func (c *Client) CreateThreadAndRun( req, err := c.newRequest( ctx, http.MethodPost, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { @@ -386,7 +386,7 @@ func (c *Client) RetrieveRunStep( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -426,7 +426,7 @@ func (c *Client) ListRunSteps( req, err := c.newRequest( ctx, http.MethodGet, - c.fullURL(c.config.BaseURL, urlSuffix), + c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return diff --git a/stream.go b/stream.go index e0c768dfd..3b5e9135a 100644 --- a/stream.go +++ b/stream.go @@ -20,7 +20,6 @@ type CompletionStream struct { func (c *Client) CreateCompletionStream( ctx context.Context, request CompletionRequest, - baseURL string, ) (stream *CompletionStream, err error) { urlSuffix := "/completions" //if !checkEndpointSupportsModel(urlSuffix, request.Model) { @@ -34,7 +33,7 @@ func (c *Client) CreateCompletionStream( } request.Stream = true - req, err := c.newRequest(ctx, "POST", c.fullURL(baseURL, urlSuffix, request.Model), withBody(request)) + req, err := c.newRequest(ctx, "POST", c.fullURL(urlSuffix, request.Model), withBody(request)) if err != nil { return nil, err } diff --git a/stream_test.go b/stream_test.go index 85477bbff..8a808284e 100644 --- a/stream_test.go +++ b/stream_test.go @@ -25,7 +25,6 @@ func TestCompletionsStreamWrongModel(t *testing.T) { MaxTokens: 5, Model: openai.GPT3Dot5Turbo, }, - config.BaseURL, ) if !errors.Is(err, openai.ErrCompletionUnsupportedModel) { t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel, but returned: %v", err) @@ -62,7 +61,7 @@ func TestCreateCompletionStream(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }, "http://localhost") + }) checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -135,7 +134,7 @@ func TestCreateCompletionStreamError(t *testing.T) { Model: openai.GPT3TextDavinci003, Prompt: "Hello!", Stream: true, - }, "http://localhost") + }) checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -173,7 +172,7 @@ func TestCreateCompletionStreamRateLimitError(t *testing.T) { Model: openai.GPT3Ada, Prompt: "Hello!", Stream: true, - }, "http://localhost") + }) if !errors.As(err, &apiErr) { t.Errorf("TestCreateCompletionStreamRateLimitError did not return APIError") } @@ -215,7 +214,7 @@ func TestCreateCompletionStreamTooManyEmptyStreamMessagesError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }, "http://localhost") + }) checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -250,7 +249,7 @@ func TestCreateCompletionStreamUnexpectedTerminatedError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }, "http://localhost") + }) checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -291,7 +290,7 @@ func TestCreateCompletionStreamBrokenJSONError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }, "http://localhost") + }) checks.NoError(t, err, "CreateCompletionStream returned error") defer stream.Close() @@ -318,7 +317,7 @@ func TestCreateCompletionStreamReturnTimeoutError(t *testing.T) { Model: "text-davinci-002", MaxTokens: 10, Stream: true, - }, "http://localhost") + }) if err == nil { t.Fatal("Did not return error") } diff --git a/thread.go b/thread.go index 1f13bdd5f..900e3f2ea 100644 --- a/thread.go +++ b/thread.go @@ -50,7 +50,7 @@ type ThreadDeleteResponse struct { // CreateThread creates a new thread. func (c *Client) CreateThread(ctx context.Context, request ThreadRequest) (response Thread, err error) { - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, threadsSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(threadsSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -63,7 +63,7 @@ func (c *Client) CreateThread(ctx context.Context, request ThreadRequest) (respo // RetrieveThread retrieves a thread. func (c *Client) RetrieveThread(ctx context.Context, threadID string) (response Thread, err error) { urlSuffix := threadsSuffix + "/" + threadID - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -80,7 +80,7 @@ func (c *Client) ModifyThread( request ModifyThreadRequest, ) (response Thread, err error) { urlSuffix := threadsSuffix + "/" + threadID - req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(c.config.BaseURL, urlSuffix), withBody(request), + req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return @@ -96,7 +96,7 @@ func (c *Client) DeleteThread( threadID string, ) (response ThreadDeleteResponse, err error) { urlSuffix := threadsSuffix + "/" + threadID - req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(c.config.BaseURL, urlSuffix), + req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix), withBetaAssistantVersion(c.config.AssistantVersion)) if err != nil { return From 2c4e2d7d45bca3e12af238f9f9e037d26c35dc7e Mon Sep 17 00:00:00 2001 From: Manba Date: Tue, 6 Aug 2024 02:27:54 +0700 Subject: [PATCH 9/9] Feat: Add override model name tensoropera llm --- completion.go | 1 + 1 file changed, 1 insertion(+) diff --git a/completion.go b/completion.go index 88bd909b9..3726ce4ec 100644 --- a/completion.go +++ b/completion.go @@ -148,6 +148,7 @@ type CompletionRequest struct { TopK int32 `json:"top_k,omitempty"` RepetitionPenalty float64 `json:"repetition_penalty,omitempty"` + OverrideModelName string `json:"override_model_name,omitempty"` } // CompletionChoice represents one of possible completions.