Skip to content

Commit 8a30835

Browse files
authored
server : match OAI structured output response (ggml-org#9527)
1 parent f799155 commit 8a30835

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

examples/server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ Given a ChatML-formatted json description in `messages`, it returns the predicte
501501

502502
See [OpenAI Chat Completions API documentation](https://platform.openai.com/docs/api-reference/chat). While some OpenAI-specific features such as function calling aren't supported, llama.cpp `/completion`-specific features such as `mirostat` are supported.
503503

504-
The `response_format` parameter supports both plain JSON output (e.g. `{"type": "json_object"}`) and schema-constrained JSON (e.g. `{"type": "json_object", "schema": {"type": "string", "minLength": 10, "maxLength": 100}}`), similar to other OpenAI-inspired API providers.
504+
The `response_format` parameter supports both plain JSON output (e.g. `{"type": "json_object"}`) and schema-constrained JSON (e.g. `{"type": "json_object", "schema": {"type": "string", "minLength": 10, "maxLength": 100}}` or `{"type": "json_schema", "schema": {"properties": { "name": { "title": "Name", "type": "string" }, "date": { "title": "Date", "type": "string" }, "participants": { "items": {"type: "string" }, "title": "Participants", "type": "string" } } } }`), similar to other OpenAI-inspired API providers.
505505

506506
*Examples:*
507507

examples/server/utils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ static json oaicompat_completion_params_parse(
331331
std::string response_type = json_value(response_format, "type", std::string());
332332
if (response_type == "json_object") {
333333
llama_params["json_schema"] = json_value(response_format, "schema", json::object());
334+
} else if (response_type == "json_schema") {
335+
json json_schema = json_value(response_format, "json_schema", json::object());
336+
llama_params["json_schema"] = json_value(json_schema, "schema", json::object());
334337
} else if (!response_type.empty() && response_type != "text") {
335338
throw std::runtime_error("response_format type must be one of \"text\" or \"json_object\", but got: " + response_type);
336339
}

grammars/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ You can use GBNF grammars:
120120

121121
- In [llama-server](../examples/server):
122122
- For any completion endpoints, passed as the `json_schema` body field
123-
- For the `/chat/completions` endpoint, passed inside the `response_format` body field (e.g. `{"type", "json_object", "schema": {"items": {}}}`)
123+
- For the `/chat/completions` endpoint, passed inside the `response_format` body field (e.g. `{"type", "json_object", "schema": {"items": {}}}` or `{ type: "json_schema", json_schema: {"schema": ...} }`)
124124
- In [llama-cli](../examples/main), passed as the `--json` / `-j` flag
125125
- To convert to a grammar ahead of time:
126126
- in CLI, with [examples/json_schema_to_grammar.py](../examples/json_schema_to_grammar.py)

0 commit comments

Comments
 (0)