29#include <llama/llama.h>
31#include <peg-parser.h>
91 common_reasoning_format reasoning_format,
bool is_partial =
false,
92 const std::string& generation_prompt =
"",
93 const std::string& parser_data =
"") =
delete;
156 const std::string& output,
157 common_chat_format format,
158 bool is_partial =
false,
159 const std::string& generation_prompt =
"",
160 const common_peg_arena& parser = {}
166 common_chat_parser_params syntax;
167 syntax.format = format;
169 syntax.parser = parser;
172 common_chat_msg msg = common_chat_parse(common_chat_input(output), is_partial, syntax);
175 result.content = msg.content;
176 result.reasoning_content = msg.reasoning_content;
178 for (
const auto& tc : msg.tool_calls) {
179 result.tool_calls.push_back({tc.name, tc.arguments, tc.id});
182 }
catch (
const std::exception& e) {
183 LLOYAL_LOG_DEBUG(
"[chat_out::parse] Parse failed: %s, returning raw output", e.what());
184 result.content = output;
208 const llama_model* model,
209 const std::string& output,
210 bool is_partial =
false
216 common_chat_templates_ptr tmpls = common_chat_templates_init(model,
"");
223 common_chat_templates_inputs inputs;
224 inputs.messages = {{.role =
"user", .
content =
""}};
225 inputs.add_generation_prompt =
true;
226 inputs.use_jinja =
true;
228 common_chat_params params = common_chat_templates_apply(tmpls.get(), inputs);
231 return parse(output, params.format, is_partial, params.generation_prompt, params.parser);
233 }
catch (
const std::exception& e) {
#define LLOYAL_LOG_DEBUG(...)
liblloyal - Common definitions and logging
Chat output parsing (tool calls, reasoning, content)
ParseResult parse(const std::string &output, common_chat_format format, common_reasoning_format reasoning_format, bool is_partial=false, const std::string &generation_prompt="", const std::string &parser_data="")=delete
The shape before the engine pin moved took a reasoning format third.
Result from parsing model output.
std::vector< ToolCall > tool_calls
Extracted tool calls (empty array if none)
std::string content
Main response text (visible to user)
std::string reasoning_content
Extracted thinking/reasoning blocks (empty if none)