@@ -130,7 +130,7 @@ def post_stream(
130130 json : Union [BaseModel , Dict ] = None ,
131131 timeout : Optional [int ] = None ,
132132 ):
133- """发起流式POST请求,返回stream_context """
133+ """Initiate streaming POST request, return stream_context """
134134 url = self ._build_url (path )
135135 headers = self ._set_headers ({"Content-Type" : "application/json" })
136136
@@ -140,7 +140,7 @@ def post_stream(
140140 _timeout = timeout if timeout is not None else self .timeout
141141
142142 try :
143- # 返回stream_context,让StreamReader管理上下文
143+ # Return stream_context, let StreamReader manage context
144144 stream_context = self .http_client .stream (
145145 "POST" ,
146146 url ,
@@ -153,13 +153,54 @@ def post_stream(
153153 logger .error (f"Http client stream request failed, path: { path } , err: { e } ." )
154154 raise consts .NetworkError from e
155155
156+ async def arequest (
157+ self ,
158+ path : str ,
159+ method : str ,
160+ response_model : Type [T ],
161+ * ,
162+ params : Optional [Dict [str , str ]] = None ,
163+ form : Optional [Dict [str , str ]] = None ,
164+ json : Optional [Union [BaseModel , Dict ]] = None ,
165+ files : Optional [Dict [str , FileType ]] = None ,
166+ headers : Optional [Dict [str , str ]] = None ,
167+ timeout : Optional [int ] = None ,
168+ ) -> T :
169+ url = self ._build_url (path )
170+ _headers = self ._set_headers (headers )
171+
172+ _timeout = timeout if timeout is not None else self .timeout
173+
174+ if isinstance (json , BaseModel ):
175+ if pydantic .VERSION .startswith ('1' ):
176+ json = json .dict (by_alias = True )
177+ else :
178+ json = json .model_dump (by_alias = True )
179+
180+ try :
181+ response = await self .http_client .arequest (
182+ method ,
183+ url ,
184+ params = params ,
185+ data = form ,
186+ json = json ,
187+ files = files ,
188+ headers = _headers ,
189+ timeout = _timeout
190+ )
191+ except httpx .HTTPError as e :
192+ logger .error (f"Http client request failed, path: { path } , err: { e } ." )
193+ raise consts .NetworkError from e
194+
195+ return parse_response (url , response , response_model )
196+
156197 async def apost_stream (
157198 self ,
158199 path : str ,
159200 json : Union [BaseModel , Dict ] = None ,
160201 timeout : Optional [int ] = None ,
161202 ):
162- """发起异步流式POST请求,返回stream_context """
203+ """Initiate asynchronous streaming POST request, return stream_context """
163204 url = self ._build_url (path )
164205 headers = self ._set_headers ({"Content-Type" : "application/json" })
165206
@@ -169,8 +210,8 @@ async def apost_stream(
169210 _timeout = timeout if timeout is not None else self .timeout
170211
171212 try :
172- # 返回stream_context,让StreamReader管理上下文
173- stream_context = self .http_client .stream (
213+ # Return stream_context, let StreamReader manage context
214+ stream_context = self .http_client .astream (
174215 "POST" ,
175216 url ,
176217 json = json ,
0 commit comments