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

Function tokenClassifyTrace

core/backend/token_classify.go:108–127  ·  view source on GitHub ↗

tokenClassifyTrace assembles the Traces-UI row for one NER call: the input preview, the threshold, and every detected entity (group, byte range, confidence, matched text). Split out from the closure so the Data assembly is unit-testable without a live backend.

(modelConfig config.ModelConfig, text string, threshold float32, entities []TokenEntity, start time.Time, callErr error)

Source from the content-addressed store, hash-verified

106// confidence, matched text). Split out from the closure so the Data assembly
107// is unit-testable without a live backend.
108func tokenClassifyTrace(modelConfig config.ModelConfig, text string, threshold float32, entities []TokenEntity, start time.Time, callErr error) trace.BackendTrace {
109 errStr := ""
110 if callErr != nil {
111 errStr = callErr.Error()
112 }
113 return trace.BackendTrace{
114 Timestamp: start,
115 Duration: time.Since(start),
116 Type: trace.BackendTraceTokenClassify,
117 ModelName: modelConfig.Name,
118 Backend: modelConfig.Backend,
119 Summary: trace.TruncateString(text, 200),
120 Error: errStr,
121 Data: map[string]any{
122 "input_chars": len(text),
123 "threshold": threshold,
124 "entities": entities,
125 },
126 }
127}
128
129// tokenClassifyResponseToEntities converts the wire-format response into
130// the value type consumed by callers. Extracted so the conversion can be

Callers 2

ModelTokenClassifyFunction · 0.85

Calls 2

TruncateStringFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected