11import base64
22import json
33import time
4+ from collections .abc import AsyncGenerator
45from pathlib import Path
5- from typing import Any , AsyncGenerator , Dict , List , Literal , Optional , Union
6+ from typing import Any , Literal , Optional , Union
67
78import httpx
89from loguru import logger
@@ -111,7 +112,7 @@ def model(self) -> Optional[str]:
111112 return self ._model
112113
113114 @property
114- def info (self ) -> Dict [str , Any ]:
115+ def info (self ) -> dict [str , Any ]:
115116 """
116117 :return: The information about the backend.
117118 """
@@ -157,7 +158,7 @@ async def prepare_multiprocessing(self):
157158 await self ._async_client .aclose ()
158159 self ._async_client = None
159160
160- async def available_models (self ) -> List [str ]:
161+ async def available_models (self ) -> list [str ]:
161162 """
162163 Get the available models for the target server using the OpenAI models endpoint:
163164 /v1/models
@@ -176,7 +177,7 @@ async def available_models(self) -> List[str]:
176177
177178 async def text_completions ( # type: ignore[override]
178179 self ,
179- prompt : Union [str , List [str ]],
180+ prompt : Union [str , list [str ]],
180181 request_id : Optional [str ] = None ,
181182 prompt_token_count : Optional [int ] = None ,
182183 output_token_count : Optional [int ] = None ,
@@ -232,7 +233,7 @@ async def chat_completions( # type: ignore[override]
232233 self ,
233234 content : Union [
234235 str ,
235- List [Union [str , Dict [str , Union [str , Dict [str , str ]]], Path , Image .Image ]],
236+ list [Union [str , dict [str , Union [str , dict [str , str ]]], Path , Image .Image ]],
236237 Any ,
237238 ],
238239 request_id : Optional [str ] = None ,
@@ -318,7 +319,7 @@ def _get_async_client(self) -> httpx.AsyncClient:
318319
319320 return client
320321
321- def _headers (self ) -> Dict [str , str ]:
322+ def _headers (self ) -> dict [str , str ]:
322323 headers = {
323324 "Content-Type" : "application/json" ,
324325 }
@@ -335,8 +336,8 @@ def _headers(self) -> Dict[str, str]:
335336 return headers
336337
337338 def _completions_payload (
338- self , orig_kwargs : Optional [Dict ], max_output_tokens : Optional [int ], ** kwargs
339- ) -> Dict :
339+ self , orig_kwargs : Optional [dict ], max_output_tokens : Optional [int ], ** kwargs
340+ ) -> dict :
340341 payload = orig_kwargs or {}
341342 payload .update (kwargs )
342343 payload ["model" ] = self .model
@@ -366,10 +367,10 @@ def _completions_payload(
366367 def _create_chat_messages (
367368 content : Union [
368369 str ,
369- List [Union [str , Dict [str , Union [str , Dict [str , str ]]], Path , Image .Image ]],
370+ list [Union [str , dict [str , Union [str , dict [str , str ]]], Path , Image .Image ]],
370371 Any ,
371372 ],
372- ) -> List [ Dict ]:
373+ ) -> list [ dict ]:
373374 if isinstance (content , str ):
374375 return [
375376 {
@@ -382,7 +383,7 @@ def _create_chat_messages(
382383 resolved_content = []
383384
384385 for item in content :
385- if isinstance (item , Dict ):
386+ if isinstance (item , dict ):
386387 resolved_content .append (item )
387388 elif isinstance (item , str ):
388389 resolved_content .append ({"type" : "text" , "text" : item })
@@ -430,8 +431,8 @@ async def _iterative_completions_request(
430431 request_id : Optional [str ],
431432 request_prompt_tokens : Optional [int ],
432433 request_output_tokens : Optional [int ],
433- headers : Dict ,
434- payload : Dict ,
434+ headers : dict ,
435+ payload : dict ,
435436 ) -> AsyncGenerator [Union [StreamingTextResponse , ResponseSummary ], None ]:
436437 if type_ == "text_completions" :
437438 target = f"{ self .target } { TEXT_COMPLETIONS_PATH } "
@@ -551,7 +552,7 @@ async def _iterative_completions_request(
551552
552553 @staticmethod
553554 def _extract_completions_delta_content (
554- type_ : Literal ["text_completions" , "chat_completions" ], data : Dict
555+ type_ : Literal ["text_completions" , "chat_completions" ], data : dict
555556 ) -> Optional [str ]:
556557 if "choices" not in data or not data ["choices" ]:
557558 return None
@@ -566,8 +567,8 @@ def _extract_completions_delta_content(
566567
567568 @staticmethod
568569 def _extract_completions_usage (
569- data : Dict ,
570- ) -> Optional [Dict [Literal ["prompt" , "output" ], int ]]:
570+ data : dict ,
571+ ) -> Optional [dict [Literal ["prompt" , "output" ], int ]]:
571572 if "usage" not in data or not data ["usage" ]:
572573 return None
573574
0 commit comments