XFEstudio/gpt4free
feat: Add media parameter and update provider configurations
- In `PollinationsImage.py`, added a new parameter `media` of type `MediaListType` to the class method. - Changed the default value of `aspect_ratio` in `PollinationsImage.py` from `"1:1"` to `None`. - Updated the call to `_generate_image` in `PollinationsImage.py` to include the new `media` parameter. - In `Local.py`, changed the `working` attribute from `True` to `has_requirements` and set `active_by_default` to `False`. - In `Ollama.py`, set `active_by_default` to `False`. - In `DeepSeekAPI.py`, set `active_by_default` to `has_dsk` and `needs_auth` to `True`. - Modified the logic in `DeepSeekAPI.py` to yield `conversation` if `message_id` is present in the chunk. - In `api.py`, added a new key `active_by_default` to the provider dictionary, determining its value based on `needs_auth`. - In `types.py`, added a new attribute `active_by_default` to the `BaseProvider` class, initializing it to `None`. - In `web_search.py`, added a type check for `prompt` to ensure it is a string before proceeding with the search logic.
849322b8
代码差异
@@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Optional
from .helper import format_media_prompt
from ..typing import AsyncResult, Messages
from ..typing import AsyncResult, Messages, MediaListType
from ..constants import STATIC_URL
from .PollinationsAI import PollinationsAI
@@ -34,11 +34,12 @@ class PollinationsImage(PollinationsAI):
cls,
model: str,
messages: Messages,
media: MediaListType = None,
proxy: str = None,
referrer: str = STATIC_URL,
api_key: str = None,
prompt: str = None,
aspect_ratio: str = "1:1",
aspect_ratio: str = None,
width: int = None,
height: int = None,
seed: Optional[int] = None,
@@ -55,6 +56,7 @@ class PollinationsImage(PollinationsAI):
async for chunk in cls._generate_image(
model=model,
prompt=format_media_prompt(messages, prompt),
media=media,
proxy=proxy,
aspect_ratio=aspect_ratio,
width=width,
@@ -13,7 +13,8 @@ from ...errors import MissingRequirementsError
class Local(AbstractProvider, ProviderModelMixin):
label = "GPT4All"
working = True
working = has_requirements
active_by_default = False
supports_message_history = True
supports_system_message = True
supports_stream = True
@@ -12,6 +12,7 @@ class Ollama(OpenaiAPI):
login_url = None
needs_auth = False
working = True
active_by_default = False
@classmethod
def get_models(cls, api_base: str = None, **kwargs):
@@ -20,6 +20,8 @@ except ImportError:
class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
url = "https://chat.deepseek.com"
working = has_dsk
active_by_default = has_dsk
needs_auth = True
use_nodriver = True
_access_token = None
@@ -81,8 +83,10 @@ class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
is_thinking = 0
if chunk['content']:
yield chunk['content']
elif 'message_id' in chunk:
if 'message_id' in chunk:
conversation.parent_id = chunk['message_id']
if chunk['finish_reason']:
yield FinishReason(chunk['finish_reason'])
yield conversation
if 'message_id' in chunk:
conversation.parent_id = chunk['message_id']
yield conversation
yield FinishReason(chunk['finish_reason'])
@@ -93,6 +93,7 @@ class Api:
"vision": getattr(provider, "default_vision_model", None) is not None,
"nodriver": getattr(provider, "use_nodriver", False),
"hf_space": getattr(provider, "hf_space", False),
"active_by_default": not provider.needs_auth if provider.active_by_default is None else provider.active_by_default,
"auth": provider.needs_auth,
"login_url": getattr(provider, "login_url", None),
} for provider in Provider.__providers__ if provider.working and safe_get_models(provider)]
@@ -20,6 +20,7 @@ class BaseProvider(ABC):
url: str = None
working: bool = False
active_by_default: bool = None
needs_auth: bool = False
supports_stream: bool = False
supports_message_history: bool = False
@@ -322,6 +322,9 @@ async def do_search(
Returns:
tuple[str, Optional[Sources]]: A tuple containing the new prompt with search results and the sources.
"""
if not isinstance(prompt, str):
return prompt, None
# If the prompt already includes the instructions, do not perform a search.
if instructions and instructions in prompt:
return prompt, None