MCPcopy Index your code
hub / github.com/mudler/LocalAI / parseJSONLegacy

Function parseJSONLegacy

pkg/functions/parse.go:381–412  ·  view source on GitHub ↗

parseJSONLegacy is the original decoder-based JSON parsing (kept for compatibility)

(s string)

Source from the content-addressed store, hash-verified

379
380// parseJSONLegacy is the original decoder-based JSON parsing (kept for compatibility)
381func parseJSONLegacy(s string) ([]map[string]any, error) {
382 var objs []map[string]any
383 offset := 0
384
385 for offset < len(s) {
386 var obj map[string]any
387 decoder := json.NewDecoder(strings.NewReader(s[offset:]))
388
389 err := decoder.Decode(&obj)
390 switch {
391 case errors.Is(err, io.EOF):
392 return objs, nil
393 case err == nil:
394 offset += int(decoder.InputOffset())
395 objs = append(objs, obj)
396 default: // handle the error type
397 var syntaxErr *json.SyntaxError
398 var unmarshalTypeErr *json.UnmarshalTypeError
399
400 switch {
401 case errors.As(err, &syntaxErr):
402 offset += int(syntaxErr.Offset)
403 case errors.As(err, &unmarshalTypeErr):
404 offset += int(unmarshalTypeErr.Offset)
405 default:
406 return objs, err
407 }
408 }
409 }
410
411 return objs, nil
412}
413
414// GetXMLFormatPreset returns a preset XML format by name, or nil if not found
415// This is exported for use in chat.go streaming integration

Callers 2

ParseJSONFunction · 0.85
ParseJSONIterativeFunction · 0.85

Calls 2

DecodeMethod · 0.95
IsMethod · 0.45

Tested by

no test coverage detected