Use vLLM audio URL payloads
This commit is contained in:
@@ -122,12 +122,11 @@ type audioLLMChatMessage struct {
|
|||||||
type audioLLMContentPart struct {
|
type audioLLMContentPart struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Text string `json:"text,omitempty"`
|
Text string `json:"text,omitempty"`
|
||||||
InputAudio *audioLLMAudio `json:"input_audio,omitempty"`
|
AudioURL *audioLLMURLRef `json:"audio_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type audioLLMAudio struct {
|
type audioLLMURLRef struct {
|
||||||
Data string `json:"data"`
|
URL string `json:"url"`
|
||||||
Format string `json:"format,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type audioLLMChatResponse struct {
|
type audioLLMChatResponse struct {
|
||||||
@@ -567,11 +566,8 @@ func (c *Client) transcribeAudioLLM(ctx context.Context, provider ProviderConfig
|
|||||||
Content: []audioLLMContentPart{
|
Content: []audioLLMContentPart{
|
||||||
{Type: "text", Text: prompt},
|
{Type: "text", Text: prompt},
|
||||||
{
|
{
|
||||||
Type: "input_audio",
|
Type: "audio_url",
|
||||||
InputAudio: &audioLLMAudio{
|
AudioURL: &audioLLMURLRef{URL: audioDataURL(audio, filename)},
|
||||||
Data: base64.StdEncoding.EncodeToString(audio),
|
|
||||||
Format: audioFormat(filename),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -634,6 +630,10 @@ func audioFormat(filename string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func audioDataURL(audio []byte, filename string) string {
|
||||||
|
return "data:audio/" + audioFormat(filename) + ";base64," + base64.StdEncoding.EncodeToString(audio)
|
||||||
|
}
|
||||||
|
|
||||||
func firstNonEmpty(values ...string) string {
|
func firstNonEmpty(values ...string) string {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
if strings.TrimSpace(value) != "" {
|
if strings.TrimSpace(value) != "" {
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ func TestNewWithOptionsBuildsComparisonProviders(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAudioDataURLUsesVLLMAudioURLFormat(t *testing.T) {
|
||||||
|
got := audioDataURL([]byte("abc"), "call.wav")
|
||||||
|
want := "data:audio/wav;base64,YWJj"
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("audio data url = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func near(got, want float64) bool {
|
func near(got, want float64) bool {
|
||||||
return math.Abs(got-want) < 0.000001
|
return math.Abs(got-want) < 0.000001
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user