66from .environment import CohereEnvironment
77
88
9+ def validate_args (obj : typing .Any , method_name : str , check_fn : typing .Callable [[typing .Any ], typing .Any ]) -> None :
10+ method = getattr (obj , method_name )
11+
12+ def wrapped (* args : typing .Any , ** kwargs : typing .Any ) -> typing .Any :
13+ check_fn (* args , ** kwargs )
14+ return method (* args , ** kwargs )
15+
16+ setattr (obj , method_name , wrapped )
17+
18+
19+ def throw_if_stream_is_true (* args , ** kwargs ) -> None :
20+ if kwargs .get ("stream" ) is True :
21+ raise ValueError (
22+ "Since python sdk cohere==5.0.0, you must now use chat_stream(...) instead of chat(stream=True, ...)"
23+ )
24+
25+
926class Client (BaseCohere ):
1027 def __init__ (
1128 self ,
@@ -27,6 +44,8 @@ def __init__(
2744 httpx_client = httpx_client ,
2845 )
2946
47+ validate_args (self , "chat" , throw_if_stream_is_true )
48+
3049
3150class AsyncClient (AsyncBaseCohere ):
3251 def __init__ (
@@ -48,3 +67,5 @@ def __init__(
4867 timeout = timeout ,
4968 httpx_client = httpx_client ,
5069 )
70+
71+ validate_args (self , "chat" , throw_if_stream_is_true )
0 commit comments