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

Function Detection

core/backend/detection.go:14–71  ·  view source on GitHub ↗
(
	ctx context.Context,
	sourceFile string,
	prompt string,
	points []float32,
	boxes []float32,
	threshold float32,
	loader *model.ModelLoader,
	appConfig *config.ApplicationConfig,
	modelConfig config.ModelConfig,
)

Source from the content-addressed store, hash-verified

12)
13
14func Detection(
15 ctx context.Context,
16 sourceFile string,
17 prompt string,
18 points []float32,
19 boxes []float32,
20 threshold float32,
21 loader *model.ModelLoader,
22 appConfig *config.ApplicationConfig,
23 modelConfig config.ModelConfig,
24) (*proto.DetectResponse, error) {
25 opts := ModelOptions(modelConfig, appConfig)
26 detectionModel, err := loader.Load(opts...)
27 if err != nil {
28 recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
29 return nil, err
30 }
31
32 if detectionModel == nil {
33 return nil, fmt.Errorf("could not load detection model")
34 }
35
36 var startTime time.Time
37 if appConfig.EnableTracing {
38 trace.InitBackendTracingIfEnabled(appConfig.TracingMaxItems, appConfig.TracingMaxBodyBytes)
39 startTime = time.Now()
40 }
41
42 res, err := detectionModel.Detect(ctx, &proto.DetectOptions{
43 Src: sourceFile,
44 Prompt: prompt,
45 Points: points,
46 Boxes: boxes,
47 Threshold: threshold,
48 })
49
50 if appConfig.EnableTracing {
51 errStr := ""
52 if err != nil {
53 errStr = err.Error()
54 }
55
56 trace.RecordBackendTrace(trace.BackendTrace{
57 Timestamp: startTime,
58 Duration: time.Since(startTime),
59 Type: trace.BackendTraceDetection,
60 ModelName: modelConfig.Name,
61 Backend: modelConfig.Backend,
62 Summary: trace.TruncateString(sourceFile, 200),
63 Error: errStr,
64 Data: map[string]any{
65 "source_file": sourceFile,
66 },
67 })
68 }
69
70 return res, err
71}

Callers 1

DetectionEndpointFunction · 0.92

Calls 8

RecordBackendTraceFunction · 0.92
TruncateStringFunction · 0.92
ModelOptionsFunction · 0.85
recordModelLoadFailureFunction · 0.85
LoadMethod · 0.65
DetectMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected