@@ -153,6 +153,47 @@ 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 ,
@@ -170,7 +211,7 @@ async def apost_stream(
170211
171212 try :
172213 # 返回stream_context,让StreamReader管理上下文
173- stream_context = self .http_client .stream (
214+ stream_context = self .http_client .astream (
174215 "POST" ,
175216 url ,
176217 json = json ,
0 commit comments