-
Notifications
You must be signed in to change notification settings - Fork 176
test: add openai api content array test case #1410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,16 @@ func (r *ChatCompletionsRequest) String() string { | |
|
||
messagesLen := 0 | ||
for _, msg := range r.Messages { | ||
messagesLen += len(msg.Content) | ||
switch content := msg.Content.(type) { | ||
case string: | ||
messagesLen += len(content) | ||
case []interface{}: | ||
// For content arrays, we'll count each element as contributing some length | ||
messagesLen += len(content) * 10 // arbitrary multiplier for array elements | ||
default: | ||
// For other types, just add a small constant | ||
messagesLen += 1 | ||
} | ||
} | ||
|
||
return fmt.Sprintf("{MessagesLength: %d}", messagesLen) | ||
|
@@ -106,7 +115,7 @@ func (r *ChatCompletionsRequest) String() string { | |
// Message represents a single message in a chat-completions request. | ||
type Message struct { | ||
Role string | ||
Content string // TODO: support multi-modal content | ||
Content any // Support both string and array content (OpenAI content blocks) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is the problem, i think we can do the same thing just like llm-d-sim https://github.com/llm-d/llm-d-inference-sim/blob/main/pkg/openai-server-api/response.go#L84-L91 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nirrozenbaum @danehans i think we need to support this first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zhengkezhou1 +1 to follow the llm-d-sim types. |
||
} | ||
|
||
type Pod interface { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,16 @@ import ( | |
testutils "sigs.k8s.io/gateway-api-inference-extension/test/utils" | ||
) | ||
|
||
type ContentBlock struct { | ||
Type string `json:"type"` | ||
Text string `json:"text,omitempty"` | ||
ImageURL *ImageBlock `json:"image_url,omitempty"` | ||
} | ||
|
||
type ImageBlock struct { | ||
Url string `json:"url"` | ||
} | ||
zhengkezhou1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var _ = ginkgo.Describe("InferencePool", func() { | ||
var infObjective *v1alpha2.InferenceObjective | ||
ginkgo.BeforeEach(func() { | ||
|
@@ -201,6 +211,24 @@ func verifyTrafficRouting() { | |
{"role": "user", "content": "Now summarize your thoughts."}, | ||
}, | ||
}, | ||
{ | ||
api: "/chat/completions", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we have multiple test cases using the same |
||
promptOrMessages: []map[string]any{ | ||
{ | ||
"role": "user", | ||
"content": []ContentBlock{ | ||
{ | ||
Type: "text", | ||
Text: `What's in this image?`, | ||
}, | ||
{ | ||
Type: "image_url", | ||
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"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} { | ||
ginkgo.By(fmt.Sprintf("Verifying connectivity through the inference extension with %s api and prompt/messages: %v", t.api, t.promptOrMessages)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the arbitrary multiplier needed?