XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

feat(g4f/Provider/Blackbox.py): enhance async generator with image processing

0a1cfe19
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

1 个文件 +17 -4
Modified g4f/Provider/Blackbox.py +17 -4
@@ -11,9 +11,9 @@ from typing import Optional, AsyncGenerator, Union
11 11
12 12 from aiohttp import ClientSession, ClientResponseError
13 13
14 from ..typing import AsyncResult, Messages
14 from ..typing import AsyncResult, Messages, ImageType
15 15 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
16 from ..image import ImageResponse
16 from ..image import ImageResponse, to_data_uri
17 17
18 18
19 19 class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
@@ -21,7 +21,6 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
21 21 url = "https://www.blackbox.ai"
22 22 api_endpoint = "https://www.blackbox.ai/api/chat"
23 23 working = True
24 supports_gpt_4 = True
25 24 supports_stream = True
26 25 supports_system_message = True
27 26 supports_message_history = True
@@ -171,6 +170,8 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
171 170 model: str,
172 171 messages: Messages,
173 172 proxy: Optional[str] = None,
173 image: ImageType = None,
174 image_name: str = None,
174 175 websearch: bool = False,
175 176 **kwargs
176 177 ) -> AsyncGenerator[Union[str, ImageResponse], None]:
@@ -181,12 +182,23 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
181 182 model (str): Model to use for generating responses.
182 183 messages (Messages): Message history.
183 184 proxy (Optional[str]): Proxy URL, if needed.
185 image (ImageType): Image data to be processed, if any.
186 image_name (str): Name of the image file, if an image is provided.
184 187 websearch (bool): Enables or disables web search mode.
185 188 **kwargs: Additional keyword arguments.
186 189
187 190 Yields:
188 191 Union[str, ImageResponse]: Segments of the generated response or ImageResponse objects.
189 192 """
193
194 if image is not None:
195 messages[-1]['data'] = {
196 'fileText': '',
197 'imageBase64': to_data_uri(image),
198 'title': image_name
199 }
200 messages[-1]['content'] = 'FILE:BB\n$#$\n\n$#$\n' + messages[-1]['content']
201
190 202 model = cls.get_model(model)
191 203
192 204 chat_id = cls.generate_random_string()
@@ -240,7 +252,8 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
240 252 {
241 253 "id": chat_id,
242 254 "content": formatted_prompt,
243 "role": "user"
255 "role": "user",
256 "data": messages[-1].get('data')
244 257 }
245 258 ],
246 259 "id": chat_id,