(ctx *cliContext.Context)
| 34 | } |
| 35 | |
| 36 | func (t *TranscriptCMD) Run(ctx *cliContext.Context) error { |
| 37 | systemState, err := system.GetSystemState( |
| 38 | system.WithBackendPath(t.BackendsPath), |
| 39 | system.WithModelPath(t.ModelsPath), |
| 40 | ) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | opts := &config.ApplicationConfig{ |
| 45 | SystemState: systemState, |
| 46 | Context: context.Background(), |
| 47 | } |
| 48 | |
| 49 | cl := config.NewModelConfigLoader(t.ModelsPath) |
| 50 | ml := model.NewModelLoader(systemState) |
| 51 | |
| 52 | if err := gallery.RegisterBackends(systemState, ml); err != nil { |
| 53 | xlog.Error("error registering external backends", "error", err) |
| 54 | } |
| 55 | |
| 56 | if err := cl.LoadModelConfigsFromPath(t.ModelsPath); err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | c, exists := cl.GetModelConfig(t.Model) |
| 61 | if !exists { |
| 62 | return fmt.Errorf("model %q not found. Run 'local-ai models list' to see available models, or install one with 'local-ai models install <model>'. See https://localai.io/models/ for more information", t.Model) |
| 63 | } |
| 64 | |
| 65 | c.Threads = &t.Threads |
| 66 | |
| 67 | defer func() { |
| 68 | err := ml.StopAllGRPC() |
| 69 | if err != nil { |
| 70 | xlog.Error("unable to stop all grpc processes", "error", err) |
| 71 | } |
| 72 | }() |
| 73 | |
| 74 | tr, err := backend.ModelTranscription(context.Background(), t.Filename, t.Language, t.Translate, t.Diarize, t.Prompt, ml, c, opts) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | switch t.ResponseFormat { |
| 80 | case schema.TranscriptionResponseFormatLrc, schema.TranscriptionResponseFormatSrt, schema.TranscriptionResponseFormatVtt, schema.TranscriptionResponseFormatText: |
| 81 | fmt.Println(schema.TranscriptionResponse(tr, t.ResponseFormat)) |
| 82 | case schema.TranscriptionResponseFormatJson: |
| 83 | tr.Segments = nil |
| 84 | tr.Words = nil |
| 85 | fallthrough |
| 86 | case schema.TranscriptionResponseFormatJsonVerbose: |
| 87 | trs := schema.TranscriptionResultSeconds{ |
| 88 | Text: tr.Text, |
| 89 | Language: tr.Language, |
| 90 | Duration: tr.Duration, |
| 91 | Words: []schema.TranscriptionWordSeconds{}, |
| 92 | Segments: []schema.TranscriptionSegmentSeconds{}, |
| 93 | } |
nothing calls this directly
no test coverage detected