Skip to content

Commit c1934b9

Browse files
committed
support multi modal inputs
1 parent c8aa470 commit c1934b9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pkg/epp/scheduling/types/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package types
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122

2223
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
@@ -97,7 +98,8 @@ func (r *ChatCompletionsRequest) String() string {
9798

9899
messagesLen := 0
99100
for _, msg := range r.Messages {
100-
messagesLen += len(msg.Content)
101+
data, _ := json.Marshal(msg.Content)
102+
messagesLen += len(data)
101103
}
102104

103105
return fmt.Sprintf("{MessagesLength: %d}", messagesLen)
@@ -106,7 +108,7 @@ func (r *ChatCompletionsRequest) String() string {
106108
// Message represents a single message in a chat-completions request.
107109
type Message struct {
108110
Role string
109-
Content string // TODO: support multi-modal content
111+
Content any
110112
}
111113

112114
type Pod interface {

pkg/epp/util/request/body_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,36 @@ func TestExtractRequestData(t *testing.T) {
6464
},
6565
},
6666
},
67+
{
68+
name: "chat completions request body with multi-modal content",
69+
body: map[string]any{
70+
"model": "test",
71+
"messages": []any{
72+
map[string]any{
73+
"role": "system",
74+
"content": map[string]any{
75+
"type": "text",
76+
"text": "Describe this image in one sentence.",
77+
},
78+
},
79+
map[string]any{
80+
"role": "user",
81+
"content": map[string]any{
82+
"type": "image_url",
83+
"image_url": "https://example.com/images/dui.jpg.",
84+
},
85+
},
86+
},
87+
},
88+
want: &types.LLMRequestBody{
89+
ChatCompletions: &types.ChatCompletionsRequest{
90+
Messages: []types.Message{
91+
{Role: "system", Content: map[string]any{"type": "text", "text": "Describe this image in one sentence."}},
92+
{Role: "user", Content: map[string]any{"type": "image_url", "image_url": "https://example.com/images/dui.jpg."}},
93+
},
94+
},
95+
},
96+
},
6797
{
6898
name: "chat completions with all optional fields",
6999
body: map[string]any{

0 commit comments

Comments
 (0)