Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcription Fails for Files Without Extension in Multipart Encoder #91

Closed
rezmoth opened this issue Oct 23, 2024 · 2 comments
Closed

Comments

@rezmoth
Copy link

rezmoth commented Oct 23, 2024

Be reader of type io.Reader

transcription, err := client.Audio.Transcriptions.New(ctx, openai.AudioTranscriptionNewParams{
	Model: openai.F(openai.AudioModelWhisper1),
	File:  openai.F[io.Reader](reader),
})

The above call fails with:

POST "https://api.openai.com/v1/audio/transcriptions": 400 Bad Request {
  "error": {
    "message": "Unrecognized file format. Supported formats: ['flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm']",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

Edit:
Seems like filename in

filename := "anonymous_file"
requires a valid extension otherwise the call fails

Fix in PR #92 seems to fix it

@jacobzim-stl
Copy link
Collaborator

Thanks! I'll take a look

@jacobzim-stl
Copy link
Collaborator

The issue here is that the backend needs the file extension for decoding. If you need to process an anonymous file reader from, os.Stdin for instance, you'll have to manually add a filename to the reader.

package main

import (
	"context"
	"io"
	"os"

	"github.com/openai/openai-go"
)

type TranscriptionsReader struct {
	*os.File
}

func (TranscriptionsReader) Name() string {
	return "anonymous.mp3"
}

func main() {
	client := openai.NewClient()
	ctx := context.Background()

	var x TranscriptionsReader = TranscriptionsReader{os.Stdin}
	transcription, err := client.Audio.Transcriptions.New(ctx, openai.AudioTranscriptionNewParams{
		Model: openai.F(openai.AudioModelWhisper1),
		File:  openai.F[io.Reader](x),
	})

	if err != nil {
		panic(err)
	}

	println(transcription.Text)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants