From f9812acbb197fc153437a12360cffcd61c7fe65a Mon Sep 17 00:00:00 2001 From: chenhan Date: Sun, 28 Jan 2024 23:32:16 +0800 Subject: [PATCH 1/3] add new struct filed dimensions for embedding API --- embeddings.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/embeddings.go b/embeddings.go index 517027f5a..90e2b0e83 100644 --- a/embeddings.go +++ b/embeddings.go @@ -157,6 +157,8 @@ type EmbeddingRequest struct { Model EmbeddingModel `json:"model"` User string `json:"user"` EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` + // Dimensions The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. + Dimensions *int `json:"dimensions,omitempty"` } func (r EmbeddingRequest) Convert() EmbeddingRequest { @@ -181,6 +183,8 @@ type EmbeddingRequestStrings struct { // Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. // If not specified OpenAI will use "float". EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` + // Dimensions The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. + Dimensions *int `json:"dimensions,omitempty"` } func (r EmbeddingRequestStrings) Convert() EmbeddingRequest { @@ -189,6 +193,7 @@ func (r EmbeddingRequestStrings) Convert() EmbeddingRequest { Model: r.Model, User: r.User, EncodingFormat: r.EncodingFormat, + Dimensions: r.Dimensions, } } @@ -209,6 +214,8 @@ type EmbeddingRequestTokens struct { // Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. // If not specified OpenAI will use "float". EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` + // Dimensions The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. + Dimensions *int `json:"dimensions,omitempty"` } func (r EmbeddingRequestTokens) Convert() EmbeddingRequest { @@ -217,6 +224,7 @@ func (r EmbeddingRequestTokens) Convert() EmbeddingRequest { Model: r.Model, User: r.User, EncodingFormat: r.EncodingFormat, + Dimensions: r.Dimensions, } } From 30c9b64dc87dbf0836e15ae01638cbcd016e04b3 Mon Sep 17 00:00:00 2001 From: chenhan Date: Sun, 28 Jan 2024 23:45:03 +0800 Subject: [PATCH 2/3] docs: remove long single-line comments --- embeddings.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/embeddings.go b/embeddings.go index 90e2b0e83..f6e2dab34 100644 --- a/embeddings.go +++ b/embeddings.go @@ -157,7 +157,8 @@ type EmbeddingRequest struct { Model EmbeddingModel `json:"model"` User string `json:"user"` EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` - // Dimensions The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. + // Dimensions The number of dimensions the resulting output embeddings should have. + // Only supported in text-embedding-3 and later models. Dimensions *int `json:"dimensions,omitempty"` } @@ -183,7 +184,8 @@ type EmbeddingRequestStrings struct { // Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. // If not specified OpenAI will use "float". EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` - // Dimensions The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. + // Dimensions The number of dimensions the resulting output embeddings should have. + // Only supported in text-embedding-3 and later models. Dimensions *int `json:"dimensions,omitempty"` } @@ -214,7 +216,8 @@ type EmbeddingRequestTokens struct { // Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. // If not specified OpenAI will use "float". EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` - // Dimensions The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. + // Dimensions The number of dimensions the resulting output embeddings should have. + // Only supported in text-embedding-3 and later models. Dimensions *int `json:"dimensions,omitempty"` } From 6084a026994bceddc585bdb444218aee2c6495f5 Mon Sep 17 00:00:00 2001 From: chenhan Date: Mon, 29 Jan 2024 10:37:08 +0800 Subject: [PATCH 3/3] change embedding request param Dimensions type to int --- embeddings.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embeddings.go b/embeddings.go index f6e2dab34..c5633a313 100644 --- a/embeddings.go +++ b/embeddings.go @@ -159,7 +159,7 @@ type EmbeddingRequest struct { EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` // Dimensions The number of dimensions the resulting output embeddings should have. // Only supported in text-embedding-3 and later models. - Dimensions *int `json:"dimensions,omitempty"` + Dimensions int `json:"dimensions,omitempty"` } func (r EmbeddingRequest) Convert() EmbeddingRequest { @@ -186,7 +186,7 @@ type EmbeddingRequestStrings struct { EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` // Dimensions The number of dimensions the resulting output embeddings should have. // Only supported in text-embedding-3 and later models. - Dimensions *int `json:"dimensions,omitempty"` + Dimensions int `json:"dimensions,omitempty"` } func (r EmbeddingRequestStrings) Convert() EmbeddingRequest { @@ -218,7 +218,7 @@ type EmbeddingRequestTokens struct { EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` // Dimensions The number of dimensions the resulting output embeddings should have. // Only supported in text-embedding-3 and later models. - Dimensions *int `json:"dimensions,omitempty"` + Dimensions int `json:"dimensions,omitempty"` } func (r EmbeddingRequestTokens) Convert() EmbeddingRequest {