Skip to content

Commit 9fe3e62

Browse files
authored
fix: correctly handles array of token arrays in embedding request (#1404)
**Description** This fixes the embeddings request parser so that it will not reject "array of token arrays" input values which is already supported. Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 85964c2 commit 9fe3e62

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

internal/apischema/openai/openai.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,6 @@ func (s *EmbeddingRequestInput) UnmarshalJSON(data []byte) (err error) {
311311
if err != nil {
312312
return
313313
}
314-
if _, ok := s.Value.([][]int64); ok {
315-
return fmt.Errorf("input has unsupported type [][]int64")
316-
}
317314
return
318315
}
319316

internal/apischema/openai/openai_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,6 @@ func TestEmbeddingRequestInputUnmarshal(t *testing.T) {
627627
data: []byte{},
628628
expectedErr: "truncated input data",
629629
},
630-
{
631-
name: "nested int array (unsupported type)",
632-
data: []byte(`[[1, 2, 3], [4, 5, 6]]`),
633-
expectedErr: "input has unsupported type [][]int64",
634-
},
635630
}
636631

637632
for _, tc := range errorCases {

internal/apischema/openai/union_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ func TestUnmarshalJSONNestedUnion(t *testing.T) {
5252
data: []byte(" \t\n\r\"test\""),
5353
expected: "test",
5454
},
55+
{
56+
name: "array of token arrays",
57+
data: []byte(`[[-1, -2, -3], [1, 2, 3]]`),
58+
expected: [][]int64{{-1, -2, -3}, {1, 2, 3}},
59+
},
60+
{
61+
name: "array of strings",
62+
data: []byte(`[ "aa", "bb", "cc" ]`),
63+
expected: []string{"aa", "bb", "cc"},
64+
},
5565
}
5666

5767
allCases := append(promptUnionBenchmarkCases, additionalSuccessCases...) //nolint:gocritic // intentionally creating new slice

0 commit comments

Comments
 (0)