Use Voxtral audio transcription endpoint
All checks were successful
CI / test (push) Successful in 14s
Build and Deploy / build-and-deploy (push) Successful in 30s

This commit is contained in:
Grendgi
2026-06-09 15:51:50 +03:00
parent 817eb8ff71
commit e6c2b46cf6
2 changed files with 123 additions and 1 deletions

View File

@@ -1,7 +1,10 @@
package transcription
import (
"encoding/json"
"math"
"net/http"
"net/http/httptest"
"testing"
"time"
)
@@ -66,6 +69,49 @@ func TestAudioDataURLUsesVLLMAudioURLFormat(t *testing.T) {
}
}
func TestVoxtralUsesAudioTranscriptionsEndpoint(t *testing.T) {
audioSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("fake audio"))
}))
defer audioSrv.Close()
var gotPath, gotModel string
providerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotPath = r.URL.Path
if err := r.ParseMultipartForm(16 << 20); err != nil {
t.Fatalf("ParseMultipartForm: %v", err)
}
gotModel = r.FormValue("model")
if _, _, err := r.FormFile("file"); err != nil {
t.Fatalf("FormFile: %v", err)
}
_ = json.NewEncoder(w).Encode(map[string]string{"text": "Алло, тест."})
}))
defer providerSrv.Close()
client := NewWithOptions(Options{
Providers: []string{"voxtral-small"},
VoxtralBaseURL: providerSrv.URL,
VoxtralModel: "mistralai/Voxtral-Small-24B-2507",
})
if client == nil {
t.Fatal("client is nil")
}
got, err := client.Transcribe(t.Context(), Input{AudioURL: audioSrv.URL, Filename: "call.mp3"})
if err != nil {
t.Fatalf("Transcribe: %v", err)
}
if gotPath != "/v1/audio/transcriptions" {
t.Fatalf("path = %q, want /v1/audio/transcriptions", gotPath)
}
if gotModel != "mistralai/Voxtral-Small-24B-2507" {
t.Fatalf("model = %q", gotModel)
}
if len(got.Segments) != 1 || got.Segments[0].Text != "Алло, тест." {
t.Fatalf("segments = %#v", got.Segments)
}
}
func near(got, want float64) bool {
return math.Abs(got-want) < 0.000001
}