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

Unclear error messages for failure errors (x < 200 and x >= 400), 413 in this case #777

Open
arshamalh opened this issue Jun 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@arshamalh
Copy link

Describe the bug
Trying to transcribe an mp3 file which happens to be larger than expected, using the snippet below:

config := openai.DefaultConfig("<token>")
client := openai.NewClientWithConfig(config)
req := openai.AudioRequest{
	Model:    openai.Whisper1,
	FilePath: "music.mp3",
}
resp, err := client.CreateTranscription(context.TODO(), req)
if err != nil {
	fmt.Printf("Transcription error: %v\n", err)
	return
}
fmt.Println(resp.Text)

the code returns this error:

error, status code: 413, message: invalid character '<' looking for beginning of value

OK, what is it all about? Is 413 an HTTP status code? where did '<' come from?

So I started to investigate, yep, 413 is an HTTP status code, but the error comes after it message: invalid character '<' looking for beginning of value, has nothing about the 413, and comes from json package which expects a json response.

it's a little bit confusing.
logging the error inside handleErrorResp method ([email protected]/client.go:259):

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>

Expected behavior
I expected handleErrorResp returns a clear error like Request Entity Too Large before it tries to unmarshal an HTML, leading to a wrong second error.

Environment (please complete the following information):

  • go-openai version: v1.26.0
  • Go version: v1.21.0
  • OpenAI API version: v1
  • OS: macOS

Additional context
I don't exactly remember but I think I had the same issue with rate limit related errors earlier.

@arshamalh arshamalh added the bug Something isn't working label Jun 25, 2024
@arshamalh
Copy link
Author

I'm willing to open a PR if the issue sounds reasonable.

@arshamalh
Copy link
Author

arshamalh commented Jun 25, 2024

Changing the AudioRequest to:

req := openai.AudioRequest{
	Model:    openai.Whisper1,
	FilePath: "hashhashhash",
}

the file is a valid audio, but it's OGG that OpenAI doesn't support, the error I get is still from json package:

error, status code: 500, message: invalid character 'e' looking for beginning of value

but I expect to get something at least like the one server is returning:

error decoding MP3 file, make sure you send a valid MP3 file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant