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

Could not parse multipart form in transcribe #217

Open
stevegpope opened this issue Jul 16, 2023 · 1 comment
Open

Could not parse multipart form in transcribe #217

stevegpope opened this issue Jul 16, 2023 · 1 comment

Comments

@stevegpope
Copy link

Description

I get this exception from time to time when calling the transcription API. It happens on my real device and on virtual devices.
I found some additional information about it here: https://community.openai.com/t/calling-whisper-api-using-curl-request-keeps-giving-error/81510

Caused by io.ktor.client.plugins.ClientRequestException: Client request(POST https://api.openai.com/v1/audio/transcriptions) invalid: 400 . Text: "{
"error": {
"message": "Could not parse multipart form",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
"
at io.ktor.client.plugins.DefaultResponseValidationKt$addDefaultResponseValidation$1$1.invokeSuspend(DefaultResponseValidation.kt:54)
at io.ktor.client.plugins.DefaultResponseValidationKt$addDefaultResponseValidation$1$1.invoke(:8)
at io.ktor.client.plugins.DefaultResponseValidationKt$addDefaultResponseValidation$1$1.invoke(:4)
at io.ktor.client.plugins.HttpCallValidator.validateResponse(HttpCallValidator.kt:51)
at io.ktor.client.plugins.HttpCallValidator.access$validateResponse(HttpCallValidator.kt:43)
at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invokeSuspend(HttpCallValidator.kt:152)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Steps to Reproduce

  1. POST to https://api.openai.com/v1/audio/transcriptions with a valid mp3 file
  2. most of time it succeeds, sometimes not

Environment

  • openai-kotlin version: com.aallam.openai:openai-client-bom:3.3.0
  • Kotlin version: kotlin = "1.8.20"
  • OS: Android

Additional Info

My code to transcribe in kotlin:

`
public suspend fun transcribeText(mp3Path: String): String {
val path = mp3Path.toPath()
val audioSource = FileSource(path = path, fileSystem = FileSystem.SYSTEM)

    val request = TranscriptionRequest(
        audio = audioSource,
        model = ModelId("whisper-1"),
    )

    var result = openAI.transcription(request)
    return result.text
}

`

@wilinz
Copy link

wilinz commented Jul 30, 2023

I have come across this issue before, where the problem lies in the unsupported form boundary string for the Content-Type header (e.g., okhttp's default boundary string is not supported). To resolve this, you need to change the boundary string to a different value. I haven't extensively studied how to change this value specifically in ktor, but that should be the general solution.

Here's an example of the Content-Type header with a form boundary string:

// WebAppBoundar is the form boundary string
Content-Type: multipart/form-data; boundary=WebAppBoundar

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