@@ -17,6 +17,7 @@ limitations under the License.
17
17
package types
18
18
19
19
import (
20
+ "encoding/json"
20
21
"fmt"
21
22
22
23
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
@@ -48,12 +49,14 @@ func (r *LLMRequest) String() string {
48
49
49
50
// LLMRequestBody contains the request-body fields that we parse out as user input,
50
51
// 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 .
52
53
type LLMRequestBody struct {
53
54
// CompletionsRequest is the representation of the OpenAI /v1/completions request body.
54
55
Completions * CompletionsRequest `json:"completions,omitempty"`
55
56
// ChatCompletionsRequest is the representation of the OpenAI /v1/chat_completions request body.
56
57
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"`
57
60
}
58
61
59
62
// CompletionsRequest is a structured representation of the fields we parse out of the
@@ -79,8 +82,8 @@ func (r *CompletionsRequest) String() string {
79
82
// API spec.
80
83
type ChatCompletionsRequest struct {
81
84
/* 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"`
84
87
/* parameters from the HuggingFace transformers chat-templates API */
85
88
Documents []interface {} `json:"documents,omitempty"`
86
89
ChatTemplate string `json:"chat_template,omitempty"`
@@ -97,16 +100,52 @@ func (r *ChatCompletionsRequest) String() string {
97
100
98
101
messagesLen := 0
99
102
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 )
101
136
}
102
137
103
138
return fmt .Sprintf ("{MessagesLength: %d}" , messagesLen )
104
139
}
105
140
106
141
// Message represents a single message in a chat-completions request.
107
- type Message struct {
142
+ type Message [ T ContentConstraint ] struct {
108
143
Role string
109
- Content string // TODO: support multi-modal content
144
+ Content T
145
+ }
146
+
147
+ type ContentConstraint interface {
148
+ string | map [string ]any
110
149
}
111
150
112
151
type Pod interface {
0 commit comments