groq / groq-python

The official Python Library for the Groq API
Apache License 2.0
301 stars 20 forks source link

Whisper API failing with TypeError #83

Closed dhruvyad closed 2 weeks ago

dhruvyad commented 1 month ago

This line is throwing a TypeError:

...
  File "/Users/dhruvyad/miniconda3/envs/42/lib/python3.8/site-packages/groq/_models.py", line 374, in is_basemodel
    return is_basemodel_type(type_)
  File "/Users/dhruvyad/miniconda3/envs/42/lib/python3.8/site-packages/groq/_models.py", line 379, in is_basemodel_type
    return issubclass(origin, BaseModel) or issubclass(origin, GenericModel)
  File "/Users/dhruvyad/miniconda3/envs/42/lib/python3.8/abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

when used for Whisper transcription. It can be fixed if you check that origin is a class:

def is_basemodel_type(type_: Type) -> TypeGuard[Type[BaseModel]]:
    origin = get_origin(type_) or type_
    if not isinstance(origin, type):
        return False
    return issubclass(origin, BaseModel) or issubclass(origin, GenericModel)
gradenr commented 1 month ago

Are you using response_format=text? I am looking into this, and I believe you can work around this issue by using json or verbose_json response format types instead of text.

gradenr commented 2 weeks ago

This was fixed in the latest release (v0.9.0).