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 {
97
97
98
98
messagesLen := 0
99
99
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
+ }
101
110
}
102
111
103
112
return fmt .Sprintf ("{MessagesLength: %d}" , messagesLen )
@@ -106,7 +115,7 @@ func (r *ChatCompletionsRequest) String() string {
106
115
// Message represents a single message in a chat-completions request.
107
116
type Message struct {
108
117
Role string
109
- Content string // TODO: support multi-modal content
118
+ Content any // Support both string and array content (OpenAI content blocks)
110
119
}
111
120
112
121
type Pod interface {
Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ import (
39
39
testutils "sigs.k8s.io/gateway-api-inference-extension/test/utils"
40
40
)
41
41
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
+
42
52
var _ = ginkgo .Describe ("InferencePool" , func () {
43
53
var infObjective * v1alpha2.InferenceObjective
44
54
ginkgo .BeforeEach (func () {
@@ -206,16 +216,14 @@ func verifyTrafficRouting() {
206
216
promptOrMessages : []map [string ]any {
207
217
{
208
218
"role" : "user" ,
209
- "content" : []map [ string ] any {
219
+ "content" : []ContentBlock {
210
220
{
211
- "type" : "text" ,
212
- "text" : `What's in this image?` ,
221
+ Type : "text" ,
222
+ Text : `What's in this image?` ,
213
223
},
214
224
{
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" },
219
227
},
220
228
},
221
229
},
You can’t perform that action at this time.
0 commit comments