@@ -1012,6 +1012,9 @@ async def request_completion(prompt,
10121012 headers ['Authorization' ] = f'Bearer { user_api_key } '
10131013
10141014 async with aiohttp .ClientSession (timeout = DEFAULT_TIMEOUT_SECONDS ) as session :
1015+ if disconnect_after_millis is not None :
1016+ await asyncio .sleep (disconnect_after_millis / 1000.0 )
1017+ return 0
10151018 async with session .post (f'{ base_url } /completion' ,
10161019 json = {
10171020 "input_prefix" : prompt_prefix ,
@@ -1025,10 +1028,6 @@ async def request_completion(prompt,
10251028 "n_probs" : 2 ,
10261029 },
10271030 headers = headers ) as response :
1028- if disconnect_after_millis is not None :
1029- await asyncio .sleep (disconnect_after_millis / 1000.0 )
1030- return 0
1031-
10321031 if expect_api_error is None or not expect_api_error :
10331032 assert response .status == 200
10341033 assert response .headers ['Access-Control-Allow-Origin' ] == origin
@@ -1088,13 +1087,12 @@ async def oai_chat_completions(user_prompt,
10881087 origin = 'llama.cpp'
10891088 headers = {'Authorization' : f'Bearer { user_api_key } ' , 'Origin' : origin }
10901089 async with aiohttp .ClientSession (timeout = DEFAULT_TIMEOUT_SECONDS ) as session :
1090+ if disconnect_after_millis is not None :
1091+ await asyncio .sleep (disconnect_after_millis / 1000.0 )
1092+ return 0
10911093 async with session .post (f'{ base_url } { base_path } ' ,
10921094 json = payload ,
10931095 headers = headers ) as response :
1094- if disconnect_after_millis is not None :
1095- await asyncio .sleep (disconnect_after_millis / 1000.0 )
1096- return 0
1097-
10981096 if enable_streaming :
10991097 assert response .status == 200
11001098 assert response .headers ['Access-Control-Allow-Origin' ] == origin
0 commit comments