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

XFEstudio/gpt4free

Add PreviewResponse type to respoonse types

d4f736eb
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +12 -2
Modified g4f/gui/server/api.py +2 -2
@@ -13,7 +13,7 @@ from ...tools.run_tools import iter_run_tools
13 13 from ...Provider import ProviderUtils, __providers__
14 14 from ...providers.base_provider import ProviderModelMixin
15 15 from ...providers.retry_provider import BaseRetryProvider
16 from ...providers.response import BaseConversation, JsonConversation, FinishReason, Usage, Reasoning
16 from ...providers.response import BaseConversation, JsonConversation, FinishReason, Usage, Reasoning, PreviewResponse
17 17 from ...providers.response import SynthesizeData, TitleGeneration, RequestLogin, Parameters, ProviderInfo
18 18 from ... import version, models
19 19 from ... import ChatCompletion, get_model_and_provider
@@ -180,7 +180,7 @@ class Api:
180 180 elif isinstance(chunk, Exception):
181 181 logger.exception(chunk)
182 182 yield self._format_json('message', get_error_message(chunk), error=type(chunk).__name__)
183 elif isinstance(chunk, ImagePreview):
183 elif isinstance(chunk, (PreviewResponse, ImagePreview)):
184 184 yield self._format_json("preview", chunk.to_string())
185 185 elif isinstance(chunk, ImageResponse):
186 186 images = chunk
Modified g4f/providers/response.py +10 -0
@@ -197,6 +197,16 @@ class ImagePreview(ImageResponse):
197 197 def to_string(self):
198 198 return super().__str__()
199 199
200 class PreviewResponse(ResponseType):
201 def __init__(self, data: str):
202 self.data = data
203
204 def __str__(self):
205 return ""
206
207 def to_string(self):
208 return self.data
209
200 210 class Parameters(ResponseType, JsonMixin):
201 211 def __str__(self):
202 212 return ""