Skip to content

Commit c7da095

Browse files
committed
fix
Signed-off-by: zhengkezhou1 <[email protected]>
1 parent 2fc0b9a commit c7da095

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

pkg/epp/scheduling/types/types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ func (r *ChatCompletionsRequest) String() string {
9797

9898
messagesLen := 0
9999
for _, msg := range r.Messages {
100-
messagesLen += len(msg.Content)
100+
switch content := msg.Content.(type) {
101+
case string:
102+
messagesLen += len(content)
103+
case []interface{}:
104+
// For content arrays, we'll count each element as contributing some length
105+
messagesLen += len(content) * 10 // arbitrary multiplier for array elements
106+
default:
107+
// For other types, just add a small constant
108+
messagesLen += 1
109+
}
101110
}
102111

103112
return fmt.Sprintf("{MessagesLength: %d}", messagesLen)
@@ -106,7 +115,7 @@ func (r *ChatCompletionsRequest) String() string {
106115
// Message represents a single message in a chat-completions request.
107116
type Message struct {
108117
Role string
109-
Content string // TODO: support multi-modal content
118+
Content any // Support both string and array content (OpenAI content blocks)
110119
}
111120

112121
type Pod interface {

test/e2e/epp/e2e_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ import (
3939
testutils "sigs.k8s.io/gateway-api-inference-extension/test/utils"
4040
)
4141

42+
type ContentBlock struct {
43+
Type string `json:"type"`
44+
Text string `json:"text,omitempty"`
45+
ImageURL *ImageBlock `json:"image_url,omitempty"`
46+
}
47+
48+
type ImageBlock struct {
49+
Url string `json:"url"`
50+
}
51+
4252
var _ = ginkgo.Describe("InferencePool", func() {
4353
var infObjective *v1alpha2.InferenceObjective
4454
ginkgo.BeforeEach(func() {
@@ -206,16 +216,14 @@ func verifyTrafficRouting() {
206216
promptOrMessages: []map[string]any{
207217
{
208218
"role": "user",
209-
"content": []map[string]any{
219+
"content": []ContentBlock{
210220
{
211-
"type": "text",
212-
"text": `What's in this image?`,
221+
Type: "text",
222+
Text: `What's in this image?`,
213223
},
214224
{
215-
"type": "image_url",
216-
"image_url": map[string]any{
217-
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
218-
},
225+
Type: "image_url",
226+
ImageURL: &ImageBlock{Url: "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"},
219227
},
220228
},
221229
},

0 commit comments

Comments
 (0)