MCPcopy
hub / github.com/mudler/LocalAI / lastSSEData

Function lastSSEData

core/http/middleware/usage.go:278–291  ·  view source on GitHub ↗

lastSSEData returns the payload of the last "data: " line whose content is not "[DONE]".

(b []byte)

Source from the content-addressed store, hash-verified

276
277// lastSSEData returns the payload of the last "data: " line whose content is not "[DONE]".
278func lastSSEData(b []byte) ([]byte, bool) {
279 prefix := []byte("data: ")
280 var last []byte
281 for _, line := range bytes.Split(b, []byte("\n")) {
282 line = bytes.TrimRight(line, "\r")
283 if bytes.HasPrefix(line, prefix) {
284 payload := line[len(prefix):]
285 if !bytes.Equal(payload, []byte("[DONE]")) {
286 last = payload
287 }
288 }
289 }
290 return last, last != nil
291}

Callers 1

tokensFromBodyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected