Browse Source

llama: allocate grammar buffer based on schema length (#10649)

brucemacd/runner-test
frob 1 year ago
committed by GitHub
parent
commit
ecf14a220f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      llama/llama.go

4
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

Loading…
Cancel
Save