Simple test to see if VLLM supports structured output
curl 127.0.0.1:8000/v1/chat/completions -s \
-H "Content-Type: application/json" \
-d '{
"model": "/data_pvc2/cache/models--CohereLabs--c4ai-command-r-08-2024/snapshots/96b61ca90ba9a25548d3d4bf68e1938b13506852/",
"messages": [
{
"role": "user",
"content": "Generate a short analysis in the given JSON schema."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "analysis_schema",
"schema": {
"type": "object",
"properties": {
"summary": { "type": "string" },
"importance_score": { "type": "number" },
"key_points": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["summary", "importance_score", "key_points"],
"additionalProperties": false
},
"strict": true
}
}
}' | jq . > /tmp/out
Sample otuput:
{
"id": "chatcmpl-9c3932339c7d4e1bace32c24ef6dbada",
"object": "chat.completion",
"created": 1770201387,
"model": "/data_pvc2/cache/models--CohereLabs--c4ai-command-r-08-2024/snapshots/96b61ca90ba9a25548d3d4bf68e1938b13506852/",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": null,
"content": "{\n \"summary\": \"This analysis focuses on the impact of marketing strategies on customer engagement and sales performance for a hypothetical e-commerce company.\",\n \"importance_score\": 0.85,\n \"key_points\": [\n \"Implemented an email marketing campaign with personalized recommendations based on past purchases: Increased open rates by 15% and contributed to a 12% rise in average order value.\",\n \"Launched an influencer marketing program on social media: Achieved a 20% growth in brand awareness and drove a significant rise in website traffic from social platforms.\",\n \"Optimised product listings through enhanced SEO techniques: Boosted organic visibility, resulting in a 25% increase in search-driven purchases.\",\n \"Implemented an automated email nurturing funnel for abandoned carts: Improved cart recovery rate by 10% and increased overall conversions.\",\n \"Analyzed customer reviews for product feedback and sentiment: Used insights to refine product strategies and enhance customer satisfaction.\"\n ]\n}",
"tool_calls": []
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": null
}
],
"usage": {
"prompt_tokens": 16,
"total_tokens": 219,
"completion_tokens": 203,
"prompt_tokens_details": null
},
"prompt_logprobs": null
}
To pretty-print the content it returned:
jq -r .choices[0].message.content /tmp/out | jq .
Simpler OpenAI-compatible JSON mode test
curl 127.0.0.1:8000/v1/chat/completions -s \
-H "Content-Type: application/json" \
-d '{
"model": "/data_pvc2/cache/models--CohereLabs--c4ai-command-r-08-2024/snapshots/96b61ca90ba9a25548d3d4bf68e1938b13506852/",
"messages": [
{
"role": "user",
"content": "Return a JSON object with keys summary, importance_score (number), key_points (string array)."
}
],
"response_format": { "type": "json_object" }
}'
Bonus: literature
- Structured output Considered Harmful(tm)
- Some people STRONGLY disagree
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus