返回提交历史
Modified
g4f/Provider/PollinationsAI.py
+1
-2
Modified
g4f/Provider/template/OpenaiTemplate.py
+2
-2
Modified
g4f/__init__.py
+0
-1
Modified
g4f/providers/base_provider.py
+2
-9
Modified
g4f/requests/__init__.py
+4
-0
XFEstudio/gpt4free
Fix streaming
ffa05f5c
代码差异
5 个文件
+9
-14
@@ -65,7 +65,6 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
65
65
url = "https://pollinations.ai"
66
66
login_url = "https://auth.pollinations.ai"
67
67
active_by_default = True
68
69
68
working = True
70
69
supports_system_message = True
71
70
supports_message_history = True
@@ -451,9 +450,9 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
451
450
extra_body["audio"] = {"voice": cls.default_voice}
452
451
if extra_body.get("audio", {}).get("format") is None:
453
452
extra_body["audio"]["format"] = "mp3"
453
stream = False
454
454
if "modalities" not in extra_body:
455
455
extra_body["modalities"] = ["text", "audio"]
456
stream = False
457
456
data = filter_none(
458
457
messages=list(render_messages(messages, media)),
459
458
model=model,
@@ -5,7 +5,7 @@ import requests
5
5
from ..helper import filter_none, format_media_prompt
6
6
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
7
7
from ...typing import Union, AsyncResult, Messages, MediaListType
8
from ...requests import StreamSession, StreamResponse, raise_for_status
8
from ...requests import StreamSession, StreamResponse, raise_for_status, see_stream
9
9
from ...image import use_aspect_ratio
10
10
from ...image.copy_images import save_response_media
11
11
from ...providers.response import FinishReason, ToolCalls, Usage, ImageResponse, ProviderInfo, AudioResponse, Reasoning
@@ -181,7 +181,7 @@ async def read_response(response: StreamResponse, stream: bool, prompt: str, pro
181
181
reasoning = False
182
182
first = True
183
183
model_returned = False
184
async for data in response.sse():
184
async for data in see_stream(response):
185
185
OpenaiTemplate.raise_error(data)
186
186
model = data.get("model")
187
187
if not model_returned and model:
@@ -8,7 +8,6 @@ from . import debug, version
8
8
from .models import Model
9
9
from .client import Client, AsyncClient
10
10
from .typing import Messages, CreateResult, AsyncResult, ImageType
11
from .errors import StreamNotSupportedError
12
11
from .cookies import get_cookies, set_cookies
13
12
from .providers.types import ProviderType
14
13
from .providers.helper import concat_chunks, async_concat_chunks
@@ -31,7 +31,7 @@ SAFE_PARAMETERS = [
31
31
"frequency_penalty", "presence_penalty",
32
32
"max_tokens", "stop",
33
33
"api_key", "api_base", "seed", "width", "height",
34
"max_retries", "web_search",
34
"max_retries", "web_search", "cache",
35
35
"guidance_scale", "num_inference_steps", "randomize_seed",
36
36
"safe", "enhance", "private", "aspect_ratio", "n", "transparent"
37
37
]
@@ -72,7 +72,6 @@ class AbstractProvider(BaseProvider):
72
72
cls,
73
73
model: str,
74
74
messages: Messages,
75
stream: bool,
76
75
**kwargs
77
76
) -> CreateResult:
78
77
"""
@@ -238,7 +237,6 @@ class AsyncProvider(AbstractProvider):
238
237
cls,
239
238
model: str,
240
239
messages: Messages,
241
stream: bool = False,
242
240
**kwargs
243
241
) -> CreateResult:
244
242
"""
@@ -248,7 +246,6 @@ class AsyncProvider(AbstractProvider):
248
246
cls (type): The class on which this method is called.
249
247
model (str): The model to use for creation.
250
248
messages (Messages): The messages to process.
251
stream (bool): Indicates whether to stream the results. Defaults to False.
252
249
loop (AbstractEventLoop, optional): The event loop to use. Defaults to None.
253
250
**kwargs: Additional keyword arguments.
254
251
@@ -292,7 +289,6 @@ class AsyncGeneratorProvider(AbstractProvider):
292
289
cls,
293
290
model: str,
294
291
messages: Messages,
295
stream: bool = None,
296
292
timeout: int = None,
297
293
**kwargs
298
294
) -> CreateResult:
@@ -303,7 +299,6 @@ class AsyncGeneratorProvider(AbstractProvider):
303
299
cls (type): The class on which this method is called.
304
300
model (str): The model to use for creation.
305
301
messages (Messages): The messages to process.
306
stream (bool): Indicates whether to stream the results. Defaults to True.
307
302
loop (AbstractEventLoop, optional): The event loop to use. Defaults to None.
308
303
**kwargs: Additional keyword arguments.
309
304
@@ -311,8 +306,7 @@ class AsyncGeneratorProvider(AbstractProvider):
311
306
CreateResult: The result of the streaming completion creation.
312
307
"""
313
308
return to_sync_generator(
314
cls.create_async_generator(model, messages, stream=stream, **kwargs),
315
stream=stream is not False,
309
cls.create_async_generator(model, messages, **kwargs),
316
310
timeout=timeout
317
311
)
318
312
@@ -329,7 +323,6 @@ class AsyncGeneratorProvider(AbstractProvider):
329
323
Args:
330
324
model (str): The model to use for creation.
331
325
messages (Messages): The messages to process.
332
stream (bool): Indicates whether to stream the results. Defaults to True.
333
326
**kwargs: Additional keyword arguments.
334
327
335
328
Raises:
@@ -216,6 +216,10 @@ async def get_nodriver(
216
216
return browser, on_stop
217
217
218
218
async def see_stream(iter_lines: Iterator[bytes]) -> AsyncIterator[dict]:
219
if hasattr(iter_lines, "content"):
220
iter_lines = iter_lines.content
221
elif hasattr(iter_lines, "iter_lines"):
222
iter_lines = iter_lines.iter_lines()
219
223
async for line in iter_lines:
220
224
if line.startswith(b"data: "):
221
225
if line[6:].startswith(b"[DONE]"):