handling unescaped json marshaling
This commit is contained in:
parent
06bcfbd629
commit
ee94693b1a
1 changed files with 10 additions and 3 deletions
13
llm/llama.go
13
llm/llama.go
|
@ -544,11 +544,18 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string,
|
||||||
Stop: llm.Stop,
|
Stop: llm.Stop,
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(predReq)
|
// Handling JSON marshaling with special characters unescaped.
|
||||||
if err != nil {
|
buf := &bytes.Buffer{}
|
||||||
return fmt.Errorf("error marshaling data: %v", err)
|
enc := json.NewEncoder(buf)
|
||||||
|
enc.SetEscapeHTML(false)
|
||||||
|
|
||||||
|
if err := enc.Encode(predReq); err != nil {
|
||||||
|
return fmt.Errorf("failed to marshal data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove trailing newline added by Encode.
|
||||||
|
data := buf.Bytes()[:buf.Len()-1]
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewBuffer(data))
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating POST request: %v", err)
|
return fmt.Errorf("error creating POST request: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue