|
29 | 29 |
|
30 | 30 | import zmq
|
31 | 31 | import zmq.asyncio
|
| 32 | +from PIL.Image import Image |
32 | 33 |
|
33 | 34 | # Fix a bug of Python threading
|
34 | 35 | setattr(threading, "_register_atexit", lambda *args, **kwargs: None)
|
@@ -135,9 +136,19 @@ def generate(
|
135 | 136 | sampling_params: Optional[Union[List[Dict], Dict]] = None,
|
136 | 137 | # The token ids for text; one can either specify text or input_ids.
|
137 | 138 | input_ids: Optional[Union[List[List[int]], List[int]]] = None,
|
138 |
| - # The image input. It can be a file name, a url, or base64 encoded string. |
139 |
| - # See also python/sglang/srt/utils.py:load_image. |
140 |
| - image_data: Optional[Union[List[str], str]] = None, |
| 139 | + # The image input. It can be an image instance, file name, URL, or base64 encoded string. |
| 140 | + # Can be formatted as: |
| 141 | + # - Single image for a single request |
| 142 | + # - List of images (one per request in a batch) |
| 143 | + # - List of lists of images (multiple images per request) |
| 144 | + # See also python/sglang/srt/utils.py:load_image for more details. |
| 145 | + image_data: Optional[ |
| 146 | + Union[ |
| 147 | + List[List[Union[Image, str]]], |
| 148 | + List[Union[Image, str]], |
| 149 | + Union[Image, str], |
| 150 | + ] |
| 151 | + ] = None, |
141 | 152 | return_logprob: Optional[Union[List[bool], bool]] = False,
|
142 | 153 | logprob_start_len: Optional[Union[List[int], int]] = None,
|
143 | 154 | top_logprobs_num: Optional[Union[List[int], int]] = None,
|
@@ -190,9 +201,19 @@ async def async_generate(
|
190 | 201 | sampling_params: Optional[Union[List[Dict], Dict]] = None,
|
191 | 202 | # The token ids for text; one can either specify text or input_ids.
|
192 | 203 | input_ids: Optional[Union[List[List[int]], List[int]]] = None,
|
193 |
| - # The image input. It can be a file name, a url, or base64 encoded string. |
194 |
| - # See also python/sglang/srt/utils.py:load_image. |
195 |
| - image_data: Optional[Union[List[str], str]] = None, |
| 204 | + # The image input. It can be an image instance, file name, URL, or base64 encoded string. |
| 205 | + # Can be formatted as: |
| 206 | + # - Single image for a single request |
| 207 | + # - List of images (one per request in a batch) |
| 208 | + # - List of lists of images (multiple images per request) |
| 209 | + # See also python/sglang/srt/utils.py:load_image for more details. |
| 210 | + image_data: Optional[ |
| 211 | + Union[ |
| 212 | + List[List[Union[Image, str]]], |
| 213 | + List[Union[Image, str]], |
| 214 | + Union[Image, str], |
| 215 | + ] |
| 216 | + ] = None, |
196 | 217 | return_logprob: Optional[Union[List[bool], bool]] = False,
|
197 | 218 | logprob_start_len: Optional[Union[List[int], int]] = None,
|
198 | 219 | top_logprobs_num: Optional[Union[List[int], int]] = None,
|
@@ -228,7 +249,13 @@ async def async_generate(
|
228 | 249 | def encode(
|
229 | 250 | self,
|
230 | 251 | prompt: Union[str, List[str], List[Dict], List[List[Dict]]],
|
231 |
| - image_data: Optional[Union[List[str], str]] = None, |
| 252 | + image_data: Optional[ |
| 253 | + Union[ |
| 254 | + List[List[Union[Image, str]]], |
| 255 | + List[Union[Image, str]], |
| 256 | + Union[Image, str], |
| 257 | + ] |
| 258 | + ] = None, |
232 | 259 | ) -> Dict:
|
233 | 260 | """
|
234 | 261 | The arguments of this function is the same as `sglang/srt/managers/io_struct.py::EmbeddingReqInput`.
|
|
0 commit comments