From b69335b889ff912b32230e72a56bb2b6ebc8c7ba Mon Sep 17 00:00:00 2001 From: ayush Date: Sat, 23 Nov 2024 18:12:19 +0000 Subject: [PATCH] improved code coverage and removed unnecessary checks --- client.go | 18 ++++++------------ embeddings_test.go | 1 + 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/client.go b/client.go index 1bb79e5b..4782726c 100644 --- a/client.go +++ b/client.go @@ -86,20 +86,14 @@ func withBody(body any) requestOption { func withExtraBody(extraBody map[string]any) requestOption { return func(args *requestOptions) { - // Initialize args.body as a map[string]any if it's nil. - if args.body == nil { - args.body = make(map[string]any) - } // Assert that args.body is a map[string]any. bodyMap, ok := args.body.(map[string]any) - if !ok { - // If it's not, initialize it as a map[string]any. - bodyMap = make(map[string]any) - args.body = bodyMap - } - // Add extraBody fields to args.body. - for key, value := range extraBody { - bodyMap[key] = value + if ok { + // If it's a map[string]any then only add extraBody + // fields to args.body otherwise keep only fields in request struct. + for key, value := range extraBody { + bodyMap[key] = value + } } } } diff --git a/embeddings_test.go b/embeddings_test.go index 3eca4c31..095a8f47 100644 --- a/embeddings_test.go +++ b/embeddings_test.go @@ -150,6 +150,7 @@ func TestEmbeddingEndpoint(t *testing.T) { "input_type": "query", "truncate": "NONE", }, + Dimensions: 1, }, ) checks.NoError(t, err, "CreateEmbeddings error")