Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f704258fdf | ||
|
|
e3288d0654 | ||
|
|
e0c53f8719 | ||
|
|
0828f0debf | ||
|
|
7282893877 |
@@ -289,4 +289,5 @@ Feature: Upload an audio recording, get a private Swedish transcript, discuss it
|
||||
|
||||
Scenario: A recording in another language never reaches the Swedish-only engine
|
||||
When I choose Other for a recording
|
||||
Then the language is left for the engine to detect and no Swedish-only engine or reconcile is used
|
||||
Then the language is left for the engine to detect and the Swedish-only base engine and the reconcile are not used
|
||||
And the engine that does run is the configured one, which is not tuned for other languages
|
||||
|
||||
@@ -32,15 +32,25 @@ func NewEnsemble(base, alt, fallback Backend, adj reconcile.Adjudicator, opts re
|
||||
return &Ensemble{base: base, alt: alt, fallback: fallback, adj: adj, opts: opts}
|
||||
}
|
||||
|
||||
// Plan implements uploads.Planner: the phases this ensemble reports, so the page can
|
||||
// show them before they run. The fallback is a phase only when one is configured.
|
||||
func (e *Ensemble) Plan() []progress.Planned {
|
||||
plan := []progress.Planned{
|
||||
// Plan implements uploads.Planner: the phases of a Swedish job, the two-engine one. The
|
||||
// fallback is a phase only when one is configured.
|
||||
func (e *Ensemble) Plan() []progress.Planned { return e.PlanFor(domain.LangSwedish) }
|
||||
|
||||
// PlanFor implements uploads.LanguagePlanner. A recording that is not Swedish never runs the
|
||||
// base engine, the comparison or the decisions (transcribeOther), so the page lists only
|
||||
// what can run: the other engine, then the fallback if one is configured.
|
||||
func (e *Ensemble) PlanFor(lang domain.Language) []progress.Planned {
|
||||
var plan []progress.Planned
|
||||
if lang == domain.LangSwedish || lang == "" {
|
||||
plan = []progress.Planned{
|
||||
{Key: "engine_a", Label: "Transcribing with " + e.base.Name()},
|
||||
{Key: "engine_b", Label: "Transcribing with " + e.alt.Name()},
|
||||
{Key: "compare", Label: "Comparing the two transcripts"},
|
||||
{Key: "decide", Label: "Deciding the differences"},
|
||||
}
|
||||
} else {
|
||||
plan = []progress.Planned{{Key: "engine_b", Label: "Transcribing with " + e.alt.Name()}}
|
||||
}
|
||||
if e.fallback != nil {
|
||||
plan = append(plan, progress.Planned{Key: "fallback", Label: "Cloud fallback (" + e.fallback.Name() + ")"})
|
||||
}
|
||||
|
||||
@@ -160,3 +160,25 @@ func TestEnsembleProgress_TheReconcileCountsAreNotedForTheOperator(t *testing.T)
|
||||
assert.Equal(t, 0, n["unsure"])
|
||||
assert.Equal(t, 0, n["errors"])
|
||||
}
|
||||
|
||||
// An auto-language upload never runs the base engine, the comparison or the decisions, so the
|
||||
// page must not list them as coming (tapir#61, PR #62 review).
|
||||
func TestEnsemblePlanFor_AnAutoLanguageListsOnlyThePhasesThatCanRun(t *testing.T) {
|
||||
with := newEnsemble("a", "a", nil, nil, true, &verdictAdj{}).e
|
||||
without := newEnsemble("a", "a", nil, nil, false, &verdictAdj{}).e
|
||||
keys := func(p []progress.Planned) []string {
|
||||
var k []string
|
||||
for _, s := range p {
|
||||
k = append(k, s.Key)
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
assert.Equal(t, []string{"engine_b", "fallback"}, keys(with.PlanFor(domain.LangAuto)))
|
||||
assert.Equal(t, []string{"engine_b"}, keys(without.PlanFor(domain.LangAuto)), "no fallback configured: none promised")
|
||||
assert.Equal(t, with.Plan(), with.PlanFor(domain.LangSwedish), "Swedish is the plan it always was")
|
||||
assert.Contains(t, with.PlanFor(domain.LangAuto)[0].Label, "iguana/kb-whisper")
|
||||
assert.Equal(t, with.Plan(), with.PlanFor(""), "a job queued before the choice existed is Swedish")
|
||||
assert.Equal(t, with.PlanFor(domain.LangAuto), with.PlanFor(domain.Language("xx")),
|
||||
"an unknown language is planned as it is run: not the Swedish phases")
|
||||
}
|
||||
|
||||
@@ -102,3 +102,45 @@ func TestEnsemble_AHungEngineIsASoftFailureAndTheOtherEnginesTextIsUsed(t *testi
|
||||
assert.Contains(t, got.Reconciliation.Reason, "timeout")
|
||||
assert.False(t, errors.Is(err, context.DeadlineExceeded))
|
||||
}
|
||||
|
||||
// WithTimeout sits in front of both local engines in production (cmd/tapir/uploads.go). It
|
||||
// must hand the engine the job's context, not a fresh one: the language and the
|
||||
// cancellation both travel on it (tapir#61).
|
||||
|
||||
func TestWithTimeout_TheEngineStillReceivesTheLanguageOfTheJob(t *testing.T) {
|
||||
for name, tt := range map[string]struct {
|
||||
ctx context.Context
|
||||
wantField bool
|
||||
}{
|
||||
"auto leaves the field out": {domain.WithLanguage(context.Background(), domain.LangAuto), false},
|
||||
"swedish sends sv": {domain.WithLanguage(context.Background(), domain.LangSwedish), true},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
var got seen
|
||||
srv := serve(t, 200, verboseJSON, &got)
|
||||
b := transcribe.WithTimeout(transcribe.NewGateway(srv.URL+"/v1", "k", "iguana/kb-whisper", srv.Client()), time.Minute)
|
||||
|
||||
_, err := b.Transcribe(tt.ctx, wavFile(t, "RIFF-synthetic-pcm"))
|
||||
|
||||
require.NoError(t, err)
|
||||
lang, present := got.fields["language"]
|
||||
assert.Equal(t, tt.wantField, present)
|
||||
if tt.wantField {
|
||||
assert.Equal(t, "sv", lang)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithTimeout_ACancelledJobIsNotRestartedByTheWrapper(t *testing.T) {
|
||||
var got seen
|
||||
srv := serve(t, 200, verboseJSON, &got)
|
||||
b := transcribe.WithTimeout(transcribe.NewGateway(srv.URL+"/v1", "k", "iguana/kb-whisper", srv.Client()), time.Minute)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
_, err := b.Transcribe(ctx, wavFile(t, "RIFF-synthetic-pcm"))
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Empty(t, got.method, "a cancelled job must not send its audio anywhere through the wrapper")
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@ type Transcriber interface {
|
||||
Transcribe(ctx context.Context, wavPath string) (domain.Transcription, error)
|
||||
}
|
||||
|
||||
// LanguagePlanner is a Planner whose phases depend on the language of the job: a recording
|
||||
// that is not Swedish skips the second engine and the reconcile, and the page should not list
|
||||
// them as coming (tapir#61). The worker prefers it over Planner.
|
||||
type LanguagePlanner interface {
|
||||
PlanFor(lang domain.Language) []progress.Planned
|
||||
}
|
||||
|
||||
// Planner is an optional extra on a Transcriber: it declares its own phases (for
|
||||
// example one per engine) so the page can show them. A Transcriber that does not
|
||||
// implement it gets a single "transcribing" phase from the worker. Whatever a Planner
|
||||
@@ -251,8 +258,14 @@ func (w *Worker) Process(ctx context.Context, job Job) {
|
||||
}
|
||||
|
||||
plan := []progress.Planned{{Key: "received", Label: "Received"}, {Key: "audio", Label: "Preparing the audio"}}
|
||||
lang := job.Language
|
||||
if lang == "" {
|
||||
lang = domain.LangSwedish // queued before the choice existed
|
||||
}
|
||||
planner, planned := w.tr.(Planner)
|
||||
if planned {
|
||||
if lp, ok := w.tr.(LanguagePlanner); ok {
|
||||
plan = append(plan, lp.PlanFor(lang)...)
|
||||
} else if planned {
|
||||
plan = append(plan, planner.Plan()...)
|
||||
} else {
|
||||
plan = append(plan, progress.Planned{Key: "transcribe", Label: "Transcribing"})
|
||||
@@ -313,7 +326,7 @@ func (w *Worker) Process(ctx context.Context, job Job) {
|
||||
if !planned {
|
||||
tr.Begin("transcribe", 0)
|
||||
}
|
||||
t, err := w.tr.Transcribe(domain.WithLanguage(progress.With(jobCtx, tr), job.Language), wav)
|
||||
t, err := w.tr.Transcribe(domain.WithLanguage(progress.With(jobCtx, tr), lang), wav)
|
||||
if err != nil {
|
||||
log.Error("upload: transcribe", "kind", errkind.Of(err), "elapsed", time.Since(start).Round(time.Second))
|
||||
abort(domain.UploadErrTranscriptionFailed)
|
||||
|
||||
@@ -213,3 +213,47 @@ func TestWorkerProgress_AStoreFailureLogsItsSQLStateNeverTheValueItQuotes(t *tes
|
||||
assert.Contains(t, out, "upload: store transcript")
|
||||
assert.Contains(t, out, "kind=sql_22P02")
|
||||
}
|
||||
|
||||
// langPlannedTr plans per language, like the Ensemble: an auto job has no base engine.
|
||||
type langPlannedTr struct{ *fakeTranscriber }
|
||||
|
||||
func (langPlannedTr) Plan() []progress.Planned { return plannedTr{}.Plan() }
|
||||
func (langPlannedTr) PlanFor(l domain.Language) []progress.Planned {
|
||||
if l == domain.LangAuto {
|
||||
return []progress.Planned{{Key: "engine_b", Label: "Transcribing with B"}}
|
||||
}
|
||||
return plannedTr{}.Plan()
|
||||
}
|
||||
|
||||
func (p langPlannedTr) Transcribe(ctx context.Context, wav string) (domain.Transcription, error) {
|
||||
r := progress.From(ctx)
|
||||
if domain.LanguageFrom(ctx) != domain.LangAuto {
|
||||
r.Begin("engine_a", 0)
|
||||
r.Done("engine_a")
|
||||
}
|
||||
r.Begin("engine_b", 0)
|
||||
r.Done("engine_b")
|
||||
return p.fakeTranscriber.Transcribe(ctx, wav)
|
||||
}
|
||||
|
||||
func TestWorkerProgress_AJobGetsThePlanOfItsLanguage(t *testing.T) {
|
||||
for name, tt := range map[string]struct {
|
||||
lang domain.Language
|
||||
want []string
|
||||
}{
|
||||
"auto": {domain.LangAuto, []string{"received:done", "audio:done", "engine_b:done", "save:done"}},
|
||||
"swedish": {domain.LangSwedish, []string{"received:done", "audio:done", "engine_a:done", "engine_b:done", "save:done"}},
|
||||
"no language (queued before the choice existed)": {"", []string{"received:done", "audio:done", "engine_a:done", "engine_b:done", "save:done"}},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
r := newWRig(t, time.Minute)
|
||||
w := newProgressWorker(t, r, langPlannedTr{r.tr})
|
||||
job := r.spool(t, "a")
|
||||
job.Language = tt.lang
|
||||
|
||||
w.Process(context.Background(), job)
|
||||
|
||||
assert.Equal(t, tt.want, keysAndStates(r.st.lastSteps()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ templ UploadPage(u domain.UploadedTranscript, chatEnabled bool, now time.Time) {
|
||||
@Layout("Tapir — " + u.Title) {
|
||||
<article class="account">
|
||||
<h1>{ u.Title }</h1>
|
||||
<p class="muted">Language: { languageLabel(u.Language) }</p>
|
||||
@uploadStatus(u, chatEnabled, now)
|
||||
<p><a href="/uploads">All recordings</a></p>
|
||||
</article>
|
||||
@@ -74,7 +75,6 @@ templ uploadStatus(u domain.UploadedTranscript, chatEnabled bool, now time.Time)
|
||||
Transcribed { uploads.FormatDuration(time.Duration(u.AudioSeconds * float64(time.Second))) }
|
||||
of audio by <span class="chip">{ u.Endpoint }</span>.
|
||||
</p>
|
||||
<p>Language: { languageLabel(u.Language) }</p>
|
||||
if provider, cloud := cloudProvider(u.Endpoint); cloud {
|
||||
<p class="cloud-note">
|
||||
This recording's audio left the homelab: it was transcribed by a cloud service ({ provider })
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestUploadPost_ALanguageOutsideTheClosedSetIsRefusedBeforeAnythingIsSpooled
|
||||
rows, err := newStore(t).ListUploads(context.Background(), userID)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, rows, "and must leave no row")
|
||||
assert.Contains(t, body(t, rec), "language")
|
||||
assert.Contains(t, body(t, rec), "Choose a language from the list.")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,8 @@ func TestUploadPage_TheFormOffersSwedishPreselectedAndOtherBeforeTheFilePart(t *
|
||||
assert.Contains(t, b, `<option value="auto"`)
|
||||
}
|
||||
|
||||
func TestUploadStatus_NamesTheLanguageTheRecordingWasTranscribedAs(t *testing.T) {
|
||||
func TestUploadPage_NamesTheLanguageInEveryState(t *testing.T) {
|
||||
for _, status := range []string{"queued", "transcribing", "done", "failed"} {
|
||||
for _, tt := range []struct {
|
||||
language domain.Language
|
||||
want string
|
||||
@@ -135,15 +136,16 @@ func TestUploadStatus_NamesTheLanguageTheRecordingWasTranscribedAs(t *testing.T)
|
||||
{domain.LangSwedish, "Swedish"},
|
||||
{domain.LangAuto, "Other (detected by the engine)"},
|
||||
} {
|
||||
t.Run(string(tt.language), func(t *testing.T) {
|
||||
t.Run(status+"/"+string(tt.language), func(t *testing.T) {
|
||||
app, _ := newUploadApp(t, audioOK, 200<<20)
|
||||
id := seedUpload(t, userID, "m", "done", "Synthetic transcript text.")
|
||||
id := seedUpload(t, userID, "m", status, "Synthetic transcript text.")
|
||||
_, err := rawPool(t).Exec(context.Background(), `UPDATE uploaded_transcripts SET language = $2 WHERE id = $1`, id, string(tt.language))
|
||||
require.NoError(t, err)
|
||||
|
||||
b := body(t, do(t, app, get("/uploads/"+id+"/status")))
|
||||
b := body(t, do(t, app, get("/uploads/"+id)))
|
||||
|
||||
assert.Contains(t, b, "Language: "+tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,20 @@ func UploadPage(u domain.UploadedTranscript, chatEnabled bool, now time.Time) te
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</h1>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</h1><p class=\"muted\">Language: ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(languageLabel(u.Language))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/uploads.templ`, Line: 60, Col: 57}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -230,7 +243,7 @@ func UploadPage(u domain.UploadedTranscript, chatEnabled bool, now time.Time) te
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<p><a href=\"/uploads\">All recordings</a></p></article>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<p><a href=\"/uploads\">All recordings</a></p></article>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -262,14 +275,14 @@ func uploadStatus(u domain.UploadedTranscript, chatEnabled bool, now time.Time)
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var12 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var12 == nil {
|
||||
templ_7745c5c3_Var12 = templ.NopComponent
|
||||
templ_7745c5c3_Var13 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var13 == nil {
|
||||
templ_7745c5c3_Var13 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
switch u.Status {
|
||||
case domain.UploadDone:
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<div class=\"upload-status upload-done\" role=\"status\">")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<div class=\"upload-status upload-done\" role=\"status\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -277,46 +290,33 @@ func uploadStatus(u domain.UploadedTranscript, chatEnabled bool, now time.Time)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<p>Transcribed ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(uploads.FormatDuration(time.Duration(u.AudioSeconds * float64(time.Second))))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/uploads.templ`, Line: 74, Col: 95}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " of audio by <span class=\"chip\">")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<p>Transcribed ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(u.Endpoint)
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(uploads.FormatDuration(time.Duration(u.AudioSeconds * float64(time.Second))))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/uploads.templ`, Line: 75, Col: 48}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/uploads.templ`, Line: 75, Col: 95}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</span>.</p><p>Language: ")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " of audio by <span class=\"chip\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var15 string
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(languageLabel(u.Language))
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(u.Endpoint)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/uploads.templ`, Line: 77, Col: 44}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/uploads.templ`, Line: 76, Col: 48}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</p>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</span>.</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user