core/text: typed argument tags, a format whose argument tag says JSON or string

RadChatFormat/ChatFormat gain arg_json_value_prefix, a second value prefix written in place of
arg_value_prefix before a JSON value (DeepSeek-V4.1's DSML: string="false" before JSON,
string="true" before text). The tag the reply writes decides how its value is read, for declared
and undeclared names alike, and JSON that does not parse is kept as its text; the grammar writes
the tag each argument's schema calls for and either for an undeclared name. The field sits at the
end of the struct, so an older plugin's shorter struct reads as unset and nothing changes for it.
chat_format_check refuses a typed format without both prefixes, with prefixes not told apart, or
with string-typed other values.

Tests: reading, streaming at every truncation, grammar arms per schema, refusals, ABI tail.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-27 18:16:26 +01:00
1 parent 70639f7ea2
commit fe27edb4da
7 files changed
+289 -28

No files matched your search

+6
View File
@@ -129,6 +129,11 @@ struct ChatFormat {
* they are then read as one delimiter, written back to back. */
std::string arg_name_suffix; /* ">\n" (MiniCPM: empty, the value prefix ends it) */
std::string arg_value_prefix; /* "" (MiniCPM: "\">") */
/* A second value prefix, for a format whose argument tag says the value's type (DSML:
* ` string="false">` before JSON, arg_value_prefix ` string="true">` before a string). The
* prefix the reply writes types its value, whatever the schema says; the grammar writes the
* one the schema calls for. Empty: the schema alone types a value. */
std::string arg_json_value_prefix;
std::string arg_value_suffix; /* "</parameter>\n" */
ChatValue string_value = ChatValue::Cdata; /* a string-typed argument: Raw or Cdata */
@@ -143,6 +148,7 @@ struct ChatFormat {
std::vector<std::string> triggers;
bool has_reasoning() const { return !reasoning_close.empty(); }
bool typed_tags() const { return !arg_json_value_prefix.empty(); }
bool has_tools() const { return !name_prefix.empty(); }
bool object_args() const { return args_form == ChatArgs::Object; }
};