File tree Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Original file line number Diff line number Diff 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.
107116type 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
112121type Pod interface {
Original file line number Diff line number Diff 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+
4252var _ = 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 },
You can’t perform that action at this time.
0 commit comments