[Bug]: Chat Completions endpoint rejects the array form of messages[].content with HTTP 400
Describe the bug
ChatMessage.content in agentscope-extensions-chat-completions-web is declared as String, but the OpenAI Chat Completions API allows messages[].content to be either a string or an array of content parts. When a client sends the array form, which OpenAI clients use for image input, JSON binding fails and the /v1/chat/completions endpoint of agentscope-chat-completions-web-starter answers 400 Bad Request before the controller runs. Images therefore cannot be sent through this endpoint, although Msg supports ImageBlock.
The existing tests build the DTOs in Java and call the controller methods directly, so the JSON format is never exercised.
To Reproduce
POST this body to the endpoint exposed by the starter:
{
"model": "agent",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}
]
}
]
}
I reproduced it with a MockMvc test against ChatCompletionsController, which uses Spring MVC's own JSON conversion, and with a plain Jackson ObjectMapper reading ChatMessage.
Expected behavior
The request is accepted. The text part becomes a TextBlock and the image part an ImageBlock.
Error messages
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.lang.String` from Array value (token `JsonToken.START_ARRAY`)]
Environment (please complete the following information):
- AgentScope-Java Version: 2.1.0-SNAPSHOT (main at
aeeb3fd18) - Java Version: 17
- OS: macOS
Additional context
I have a fix and will open a PR.