Browse Source

Merge pull request #799 from deichbewohner/jsonmarshaling

Fix JSON Marshal Escaping for Special Characters
Michael Yang 1 year ago
parent
commit
f55bdb6f10
1 changed files with 8 additions and 4 deletions
  1. 8 4
      llm/llama.go

+ 8 - 4
llm/llama.go

@@ -541,12 +541,16 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string,
 		Stop:             llm.Stop,
 		Stop:             llm.Stop,
 	}
 	}
 
 
-	data, err := json.Marshal(predReq)
-	if err != nil {
-		return fmt.Errorf("error marshaling data: %v", err)
+	// Handling JSON marshaling with special characters unescaped.
+	buffer := &bytes.Buffer{}
+	enc := json.NewEncoder(buffer)
+	enc.SetEscapeHTML(false)
+
+	if err := enc.Encode(predReq); err != nil {
+		return fmt.Errorf("failed to marshal data: %v", err)
 	}
 	}
 
 
-	req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewBuffer(data))
+	req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, buffer)
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("error creating POST request: %v", err)
 		return fmt.Errorf("error creating POST request: %v", err)
 	}
 	}