#python-openai library - Whisper API request

16 messages · Page 1 of 1 (latest)

lapis jackal
#

Is it possible to pass parameters like "Prompt:" in this request format?
transcription_object = openai.Audio.transcribe("whisper-1", audio_file)

I want to use prompt so my audio segments can be properly concatenated by Whisper. (As describer in openai docs). But I'm curious is this python-openai lib request can also pass parameters?

Please let me know. I couldn't find much info

woeful valve
#

You cannot pass a prompt to whisper API

nova talon
woeful valve
#

Oops!! I totally missed that, was that there before? I swear that wasn't a param earlier 😅

nova talon
#

Pretty sure it's been there since they released the api a_skull , I'm guessing it might just be a named param for the function?

woeful valve
#

yeah I guess so

#

I guess I'm just blind 💀

#

I'm very curious if using the prompt can cause the API to do concatenation and manipulate the transcribed text data

#

that's super cool, gotta play around with this for sure

silver apex
#

I'm having the same issue. I can't figure out how to correctly pass the optional parameters to the openai.Audio.transcribe function.

transcript = openai.Audio.transcribe("whisper-1", audio_file, params={"language": "ro"})
# (1) results in:           data: {'model': 'whisper-1', 'params': {'language': 'ro'}}
# (2) would work with:      data: {'model': 'whisper-1', 'language': 'ro'}

I logged the data object that is created inside the transcribe function. The first comment shows the actual result, which is ignored. I hardcoded the data object to make it use the second object, which applies the language correctly. I assume that the same would work for prompts, but I haven't tried that.
For this, I followed the transcribe function, there I followed the cls._prepare_request function and adjusted it. This is the resulting _prepare_request in openai > api_resources > audio.py, lines 15-43:

@classmethod
def _prepare_request(
    cls,
    file,
    filename,
    model,
    api_key=None,
    api_base=None,
    api_type=None,
    api_version=None,
    organization=None,
    **params,
):
    requestor = api_requestor.APIRequestor(
        api_key,
        api_base=api_base or openai.api_base,
        api_type=api_type,
        api_version=api_version,
        organization=organization,
    )
    files: List[Any] = []
    data = {
        "model": model,
        "language": "ro", # <-- add my optional parameter here
        **params,
    }
    print(f"data: {data}") # <-- log the data
    files.append(("file", (filename, file, "application/octet-stream")))
    return requestor, files, data
#

I would love a cleaner solution, though :D

nova talon
#

I'm pretty sure it's just that. That uses what I meant by named params

#

the function takes paramName=paramValue as a parameter

silver apex
#

Thanks, couldn't figure out how to use them :D