mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-10-19 22:54:43 +08:00
Add PreviewResponse type to respoonse types
This commit is contained in:
@@ -13,7 +13,7 @@ from ...tools.run_tools import iter_run_tools
|
||||
from ...Provider import ProviderUtils, __providers__
|
||||
from ...providers.base_provider import ProviderModelMixin
|
||||
from ...providers.retry_provider import BaseRetryProvider
|
||||
from ...providers.response import BaseConversation, JsonConversation, FinishReason, Usage, Reasoning
|
||||
from ...providers.response import BaseConversation, JsonConversation, FinishReason, Usage, Reasoning, PreviewResponse
|
||||
from ...providers.response import SynthesizeData, TitleGeneration, RequestLogin, Parameters, ProviderInfo
|
||||
from ... import version, models
|
||||
from ... import ChatCompletion, get_model_and_provider
|
||||
@@ -180,7 +180,7 @@ class Api:
|
||||
elif isinstance(chunk, Exception):
|
||||
logger.exception(chunk)
|
||||
yield self._format_json('message', get_error_message(chunk), error=type(chunk).__name__)
|
||||
elif isinstance(chunk, ImagePreview):
|
||||
elif isinstance(chunk, (PreviewResponse, ImagePreview)):
|
||||
yield self._format_json("preview", chunk.to_string())
|
||||
elif isinstance(chunk, ImageResponse):
|
||||
images = chunk
|
||||
|
@@ -197,6 +197,16 @@ class ImagePreview(ImageResponse):
|
||||
def to_string(self):
|
||||
return super().__str__()
|
||||
|
||||
class PreviewResponse(ResponseType):
|
||||
def __init__(self, data: str):
|
||||
self.data = data
|
||||
|
||||
def __str__(self):
|
||||
return ""
|
||||
|
||||
def to_string(self):
|
||||
return self.data
|
||||
|
||||
class Parameters(ResponseType, JsonMixin):
|
||||
def __str__(self):
|
||||
return ""
|
||||
|
Reference in New Issue
Block a user