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

`openai api audio.transcriptions.create` not working when response format is not json

Open zzh1996 opened this issue 1 year ago • 3 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

If you specify --response-format to a format other than json (like srt or vtt), the openai api audio.transcriptions.create command will fail with error

To Reproduce

  1. Install openai python library version v1.6.1
  2. Prepare an audio file, such as a recording saying "hello"
  3. Run OPENAI_API_KEY=<YOUR_API_KEY> openai api audio.transcriptions.create -f 1.m4a --response-format vtt
  4. You can see the error message
Traceback (most recent call last):
  File "/usr/local/bin/openai", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/cli/_cli.py", line 129, in main
    _main()
  File "/usr/local/lib/python3.11/site-packages/openai/cli/_cli.py", line 209, in _main
    parsed.func(
  File "/usr/local/lib/python3.11/site-packages/openai/cli/_api/audio.py", line 78, in transcribe
    print_model(model)
  File "/usr/local/lib/python3.11/site-packages/openai/cli/_utils.py", line 36, in print_model
    sys.stdout.write(model_json(model, indent=2) + "\n")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_compat.py", line 125, in model_json
    return model.model_dump_json(indent=indent)
           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'model_dump_json'

I can also reproduce this using python:3.12 Docker image.

Code snippets

No response

OS

macOS

Python version

Python 3.11.6

Library version

v1.6.1

zzh1996 avatar Jan 01 '24 21:01 zzh1996

Thanks for reporting! We would appreciate a PR from the community fixing this within the _cli folder, if anyone is able to!

Otherwise, we'll try to get to it when we can.

rattrayalex avatar Jan 02 '24 17:01 rattrayalex

@rattrayalex I would like to work on this, could you please assign this to me

nagavenkateshgavini avatar Feb 29 '24 07:02 nagavenkateshgavini

Go for it!

rattrayalex avatar Feb 29 '24 21:02 rattrayalex

@rattrayalex, could you see my solution?

aurishhammadhafeez avatar Jul 20 '24 18:07 aurishhammadhafeez

Thanks @aurishhammadhafeez, I've merged your PR so this will be fixed in the next release, v1.36.2.

RobertCraigie avatar Jul 22 '24 10:07 RobertCraigie