@@ -17,6 +17,7 @@ limitations under the License.
1717package types
1818
1919import (
20+ "encoding/json"
2021 "fmt"
2122
2223 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
@@ -48,12 +49,14 @@ func (r *LLMRequest) String() string {
4849
4950// LLMRequestBody contains the request-body fields that we parse out as user input,
5051// to be used in forming scheduling decisions.
51- // An LLMRequestBody must contain exactly one of CompletionsRequest or ChatCompletionsRequest .
52+ // An LLMRequestBody must contain exactly one of CompletionsRequest,ChatCompletionsRequest or MultiModalChatCompletions .
5253type LLMRequestBody struct {
5354 // CompletionsRequest is the representation of the OpenAI /v1/completions request body.
5455 Completions * CompletionsRequest `json:"completions,omitempty"`
5556 // ChatCompletionsRequest is the representation of the OpenAI /v1/chat_completions request body.
5657 ChatCompletions * ChatCompletionsRequest `json:"chat_completions,omitempty"`
58+ // MultiModalChatCompletionsRequest is the representation of the OpenAI /v1/chat/completions request body.
59+ MultiModalChatCompletions * MultiModalChatCompletionsRequest `json:"multi_modal_chat_completions,omitempty"`
5760}
5861
5962// CompletionsRequest is a structured representation of the fields we parse out of the
@@ -79,8 +82,8 @@ func (r *CompletionsRequest) String() string {
7982// API spec.
8083type ChatCompletionsRequest struct {
8184 /* parameters from the official OpenAI chat-completions API */
82- Messages []Message `json:"messages,omitempty"`
83- Tools []interface {} `json:"tools,omitempty"`
85+ Messages []Message [ string ] `json:"messages,omitempty"`
86+ Tools []interface {} `json:"tools,omitempty"`
8487 /* parameters from the HuggingFace transformers chat-templates API */
8588 Documents []interface {} `json:"documents,omitempty"`
8689 ChatTemplate string `json:"chat_template,omitempty"`
@@ -97,16 +100,52 @@ func (r *ChatCompletionsRequest) String() string {
97100
98101 messagesLen := 0
99102 for _ , msg := range r .Messages {
100- messagesLen += len (msg .Content )
103+ data , _ := json .Marshal (msg .Content )
104+ messagesLen += len (data )
105+ }
106+
107+ return fmt .Sprintf ("{MessagesLength: %d}" , messagesLen )
108+ }
109+
110+ // MultiModalChatCompletionsRequest is a structured representation of the fields we parse out of the
111+ // /v1/chat/completions request body.
112+ // This struct includes fields usable for plugins and scheduling decisions - and not the entire
113+ // API spec.
114+ type MultiModalChatCompletionsRequest struct {
115+ /* parameters from the official OpenAI chat-completions API */
116+ Messages []Message [map [string ]interface {}] `json:"messages,omitempty"`
117+ Tools []interface {} `json:"tools,omitempty"`
118+ /* parameters from the HuggingFace transformers chat-templates API */
119+ Documents []interface {} `json:"documents,omitempty"`
120+ ChatTemplate string `json:"chat_template,omitempty"`
121+ ReturnAssistantTokensMask bool `json:"return_assistant_tokens_mask,omitempty"`
122+ ContinueFinalMessage bool `json:"continue_final_message,omitempty"`
123+ AddGenerationPrompt bool `json:"add_generation_prompt,omitempty"`
124+ ChatTemplateKWArgs map [string ]interface {} `json:"chat_template_kwargs,omitempty"`
125+ }
126+
127+ func (r * MultiModalChatCompletionsRequest ) String () string {
128+ if r == nil {
129+ return nilString
130+ }
131+
132+ messagesLen := 0
133+ for _ , msg := range r .Messages {
134+ data , _ := json .Marshal (msg .Content )
135+ messagesLen += len (data )
101136 }
102137
103138 return fmt .Sprintf ("{MessagesLength: %d}" , messagesLen )
104139}
105140
106141// Message represents a single message in a chat-completions request.
107- type Message struct {
142+ type Message [ T ContentConstraint ] struct {
108143 Role string
109- Content string // TODO: support multi-modal content
144+ Content T
145+ }
146+
147+ type ContentConstraint interface {
148+ string | map [string ]any
110149}
111150
112151type Pod interface {
0 commit comments