Use Voxtral audio transcription endpoint
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user