openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

The return type hint of `client.audio.transcriptions.create()` is incorrect.

Open gbaian10 opened this issue 1 year ago • 0 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [X] This is an issue with the Python library

Describe the bug

The return type hint of client.audio.transcriptions.create() is Transcription, and this type has a text attribute.

However, when the response_format is equal to text, srt, or vtt, its return value is str. In this case, calling the text attribute will result in an error.

To Reproduce

import openai
from dotenv import load_dotenv

load_dotenv()

file_path = "example.wav"

client = openai.OpenAI()
with open(file_path, "rb") as file:
    transcript = client.audio.transcriptions.create(
        model="whisper-1", file=file, response_format="srt"
    )

    print(transcript)
    print(type(transcript))
    print(transcript.text)
    print(type(transcript.text))

OS

Windows 10

Python version

Python v3.12.4

Library version

openai v1.40.3

gbaian10 avatar Aug 10 '24 14:08 gbaian10