#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "shim_support.h"
#ifdef __cplusplus
extern "C" {
#endif
struct llama_model;
int32_t common_json_schema_to_grammar_c(
const char * schema_json,
bool force_gbnf,
char * out_buf,
size_t out_len,
size_t * expected_len);
struct chat_shim_templates;
struct chat_shim_templates * chat_shim_templates_init(
const struct llama_model * model,
const char * template_override);
void chat_shim_templates_free(struct chat_shim_templates * tmpls);
int32_t chat_shim_templates_source(
const struct chat_shim_templates * tmpls,
const char * variant,
char * out_buf,
size_t out_len,
size_t * expected_len);
bool chat_shim_templates_was_explicit(const struct chat_shim_templates * tmpls);
bool chat_shim_templates_support_enable_thinking(const struct chat_shim_templates * tmpls);
int32_t chat_shim_templates_get_caps(
const struct chat_shim_templates * tmpls,
char * out_buf,
size_t out_len,
size_t * expected_len);
enum chat_shim_tool_choice {
CHAT_SHIM_TOOL_CHOICE_AUTO = 0,
CHAT_SHIM_TOOL_CHOICE_REQUIRED = 1,
CHAT_SHIM_TOOL_CHOICE_NONE = 2,
};
enum chat_shim_reasoning_format {
CHAT_SHIM_REASONING_NONE = 0,
CHAT_SHIM_REASONING_AUTO = 1,
CHAT_SHIM_REASONING_DEEPSEEK_LEGACY = 2,
CHAT_SHIM_REASONING_DEEPSEEK = 3,
};
struct chat_shim_apply_params {
const char * messages_json;
const char * tools_json;
const char * grammar;
const char * json_schema;
const char * template_kwargs_json;
int32_t tool_choice;
int32_t reasoning_format;
bool add_generation_prompt;
bool enable_thinking;
bool parallel_tool_calls;
bool use_jinja;
bool add_bos;
bool add_eos;
};
struct chat_shim_apply_result {
size_t prompt_off;
size_t grammar_off;
size_t grammar_triggers_off;
size_t preserved_tokens_off;
size_t additional_stops_off;
size_t parser_off;
size_t generation_prompt_off;
size_t thinking_start_tag_off;
size_t thinking_end_tags_off;
int32_t format;
bool grammar_lazy;
bool supports_thinking;
};
int32_t chat_shim_templates_apply(
const struct chat_shim_templates * tmpls,
const struct chat_shim_apply_params * params,
struct chat_shim_apply_result * out_result,
char * out_buf,
size_t out_len,
size_t * expected_len);
int32_t chat_shim_format_name(
int32_t format,
char * out_buf,
size_t out_len,
size_t * expected_len);
struct chat_shim_parse_params {
const char * text;
const char * parser;
const char * generation_prompt;
int32_t format;
int32_t reasoning_format;
bool is_partial;
bool parse_tool_calls;
bool reasoning_in_content;
};
int32_t chat_shim_parse(
const struct chat_shim_parse_params * params,
char * out_buf,
size_t out_len,
size_t * expected_len);
int32_t chat_shim_msgs_parse_oaicompat(
const char * messages_json,
char * out_buf,
size_t out_len,
size_t * expected_len);
int32_t chat_shim_tools_parse_oaicompat(
const char * tools_json,
char * out_buf,
size_t out_len,
size_t * expected_len);
int32_t chat_shim_tool_choice_parse_oaicompat(const char * value, int32_t * out_choice);
#ifdef __cplusplus
}
#endif