| 11171 | |
| 11172 | static void kv_cache_log_cb(void *ud, ds4_kvstore_log_type type, const char *msg) { |
| 11173 | (void)ud; |
| 11174 | ds4_log_type stype = DS4_LOG_KVCACHE; |
| 11175 | if (type == DS4_KVSTORE_LOG_DEFAULT) stype = DS4_LOG_DEFAULT; |
| 11176 | else if (type == DS4_KVSTORE_LOG_WARNING) stype = DS4_LOG_WARNING; |
| 11177 | server_log(stype, "%s", msg); |
| 11178 | } |
| 11179 | |
| 11180 | static bool kv_cache_open(kv_disk_cache *kc, const char *dir, uint64_t budget_mb, |
| 11181 | bool reject_different_quant, kv_cache_options opt) { |
| 11182 | return ds4_kvstore_open(kc, dir, budget_mb, reject_different_quant, opt, |
| 11183 | "ds4-server", kv_cache_log_cb, NULL); |
| 11184 | } |
| 11185 | |
| 11186 | static void kv_cache_close(kv_disk_cache *kc) { |
| 11187 | ds4_kvstore_close(kc); |
| 11188 | } |
| 11189 | |
| 11190 | static char *render_tokens_text(ds4_engine *engine, const ds4_tokens *tokens, size_t *out_len) { |
| 11191 | return ds4_kvstore_render_tokens_text(engine, tokens, out_len); |
| 11192 | } |
| 11193 | |
| 11194 | static bool byte_prefix_match(const char *text, size_t text_len, |
| 11195 | const char *prefix, size_t prefix_len) { |
| 11196 | return ds4_kvstore_byte_prefix_match(text, text_len, prefix, prefix_len); |
| 11197 | } |
| 11198 | |
| 11199 | |
| 11200 | static void tokens_copy_prefix(ds4_tokens *dst, const ds4_tokens *src, int n) { |
| 11201 | ds4_kvstore_tokens_copy_prefix(dst, src, n); |
| 11202 | } |
| 11203 | |
| 11204 | |
| 11205 | static void build_prompt_from_exact_prefix_and_text_suffix( |
| 11206 | ds4_engine *engine, |
| 11207 | const ds4_tokens *exact_prefix, |
| 11208 | const char *suffix_text, |
| 11209 | ds4_tokens *out) |
| 11210 | { |