From ecf14a220f852528bae860ec09b52590f06e6744 Mon Sep 17 00:00:00 2001 From: frob Date: Sat, 10 May 2025 20:57:30 +0200 Subject: [PATCH] llama: allocate grammar buffer based on schema length (#10649) --- llama/llama.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama/llama.go b/llama/llama.go index 3e157c0ac..063eb7c84 100644 --- a/llama/llama.go +++ b/llama/llama.go @@ -637,8 +637,8 @@ func SchemaToGrammar(schema []byte) []byte { cStr := C.CString(string(schema)) defer C.free(unsafe.Pointer(cStr)) - // Allocate buffer for grammar output with reasonable size - const maxLen = 32768 // 32KB + // Allocate buffer for grammar based on schema length but with upper bound + maxLen := min(1024*1024, len(schema)*4) buf := make([]byte, maxLen) // Call C function to convert schema to grammar