replicate / replicate-python

Python client for Replicate
https://replicate.com
Apache License 2.0
769 stars 222 forks source link

Error: issubclass() arg 1 must be a class #233

Closed bertello72 closed 9 months ago

bertello72 commented 9 months ago

with replicate version 0.23.0

Running this code:

import replicate
output = replicate.run(
"mistralai/mistral-7b-instruct-v0.1:5fe0a3d7ac2852264a25279d1dfb798acbc4d49711d126646594e212cb821749",
input={
"debug": False,
"top_k": 50,
"top_p": 0.9,
"prompt": "Can you write me a poem about steamed hams?",
"temperature": 0.7,
"max_new_tokens": 500,
"min_new_tokens": -1,
"prompt_template": "{prompt}",
"repetition_penalty": 1.15
}
)
print(output)

I got this error:

TypeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 import replicate
2 output = replicate.run(
3 "mistralai/mistral-7b-instruct-v0.1:5fe0a3d7ac2852264a25279d1dfb798acbc4d49711d126646594e212cb821749",
4 input={
(...)
14 }
15 )
16 print(output)

File ~\anaconda3\lib\site-packages\replicate_init_.py:1
----> 1 from replicate.client import Client
2 from replicate.pagination import async_paginate as _async_paginate
3 from replicate.pagination import paginate as _paginate

File ~\anaconda3\lib\site-packages\replicate\client.py:22
19 from typing_extensions import Unpack
21 from replicate.about import version
---> 22 from replicate.collection import Collections
23 from replicate.deployment import Deployments
24 from replicate.exceptions import ReplicateError

File ~\anaconda3\lib\site-packages\replicate\collection.py:5
1 from typing import Any, Dict, Iterator, List, Optional, Union, overload
3 from typing_extensions import deprecated
----> 5 from replicate.model import Model
6 from replicate.pagination import Page
7 from replicate.resource import Namespace, Resource

File ~\anaconda3\lib\site-packages\replicate\model.py:8
6 from replicate.identifier import ModelVersionIdentifier
7 from replicate.pagination import Page
----> 8 from replicate.prediction import (
9 Prediction,
10 _create_prediction_body,
11 _json_to_prediction,
12 )
13 from replicate.resource import Namespace, Resource
14 from replicate.version import Version, Versions

File ~\anaconda3\lib\site-packages\replicate\prediction.py:27
23 from replicate.client import Client
24 from replicate.stream import ServerSentEvent
---> 27 class Prediction(Resource):
28 """
29 A prediction made by a model hosted on Replicate.
30 """
32 _client: "Client" = pydantic.PrivateAttr()

File ~\anaconda3\lib\site-packages\pydantic\main.py:197, in pydantic.main.ModelMetaclass.new()

File ~\anaconda3\lib\site-packages\pydantic\fields.py:506, in pydantic.fields.ModelField.infer()

File ~\anaconda3\lib\site-packages\pydantic\fields.py:436, in pydantic.fields.ModelField.init()

File ~\anaconda3\lib\site-packages\pydantic\fields.py:552, in pydantic.fields.ModelField.prepare()

File ~\anaconda3\lib\site-packages\pydantic\fields.py:668, in pydantic.fields.ModelField._type_analysis()

File ~\anaconda3\lib\typing.py:852, in _SpecialGenericAlias.subclasscheck(self, cls)
850 return issubclass(cls.origin, self.origin)
851 if not isinstance(cls, _GenericAlias):
--> 852 return issubclass(cls, self.origin)
853 return super().subclasscheck(cls)

TypeError: issubclass() arg 1 must be a class
mattt commented 9 months ago

Hi @bertello72. Based on this issue, this looks like an incompatibility between typing_extensions == 4.6.0 and pydantic < 1.10.8. Try upgrading to pydantic 1.10.8 or higher and let me know if that fixes your problem.

bertello72 commented 9 months ago

It works updating pydantic to 1.10.8 Thank you

Il giorno ven 26 gen 2024 alle ore 20:23 Mattt @.***> ha scritto:

Hi @bertello72 https://github.com/bertello72. Based on this issue https://github.com/pydantic/pydantic/issues/5821, this looks like an incompatibility between typing_extensions == 4.6.0 and pydantic < 1.10.8. Try upgrading to pydantic 1.10.8 or higher and let me know if that fixes your problem.

— Reply to this email directly, view it on GitHub https://github.com/replicate/replicate-python/issues/233#issuecomment-1912574493, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFTUJOPU3ADN4OP6Q3FNRATYQP7CZAVCNFSM6AAAAABCMRR5UWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGU3TINBZGM . You are receiving this because you were mentioned.Message ID: @.***>