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

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
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

7 个文件 +19 -6
Modified g4f/Provider/PollinationsImage.py +4 -2
@@ -3,7 +3,7 @@ from __future__ import annotations
3 3 from typing import Optional
4 4
5 5 from .helper import format_media_prompt
6 from ..typing import AsyncResult, Messages
6 from ..typing import AsyncResult, Messages, MediaListType
7 7 from ..constants import STATIC_URL
8 8 from .PollinationsAI import PollinationsAI
9 9
@@ -34,11 +34,12 @@ class PollinationsImage(PollinationsAI):
34 34 cls,
35 35 model: str,
36 36 messages: Messages,
37 media: MediaListType = None,
37 38 proxy: str = None,
38 39 referrer: str = STATIC_URL,
39 40 api_key: str = None,
40 41 prompt: str = None,
41 aspect_ratio: str = "1:1",
42 aspect_ratio: str = None,
42 43 width: int = None,
43 44 height: int = None,
44 45 seed: Optional[int] = None,
@@ -55,6 +56,7 @@ class PollinationsImage(PollinationsAI):
55 56 async for chunk in cls._generate_image(
56 57 model=model,
57 58 prompt=format_media_prompt(messages, prompt),
59 media=media,
58 60 proxy=proxy,
59 61 aspect_ratio=aspect_ratio,
60 62 width=width,
Modified g4f/Provider/local/Local.py +2 -1
@@ -13,7 +13,8 @@ from ...errors import MissingRequirementsError
13 13
14 14 class Local(AbstractProvider, ProviderModelMixin):
15 15 label = "GPT4All"
16 working = True
16 working = has_requirements
17 active_by_default = False
17 18 supports_message_history = True
18 19 supports_system_message = True
19 20 supports_stream = True
Modified g4f/Provider/local/Ollama.py +1 -0
@@ -12,6 +12,7 @@ class Ollama(OpenaiAPI):
12 12 login_url = None
13 13 needs_auth = False
14 14 working = True
15 active_by_default = False
15 16
16 17 @classmethod
17 18 def get_models(cls, api_base: str = None, **kwargs):
Modified g4f/Provider/needs_auth/DeepSeekAPI.py +7 -3
@@ -20,6 +20,8 @@ except ImportError:
20 20 class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
21 21 url = "https://chat.deepseek.com"
22 22 working = has_dsk
23 active_by_default = has_dsk
24 needs_auth = True
23 25 use_nodriver = True
24 26 _access_token = None
25 27
@@ -81,8 +83,10 @@ class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
81 83 is_thinking = 0
82 84 if chunk['content']:
83 85 yield chunk['content']
84 elif 'message_id' in chunk:
86 if 'message_id' in chunk:
85 87 conversation.parent_id = chunk['message_id']
86 88 if chunk['finish_reason']:
87 yield FinishReason(chunk['finish_reason'])
88 yield conversation
89 if 'message_id' in chunk:
90 conversation.parent_id = chunk['message_id']
91 yield conversation
92 yield FinishReason(chunk['finish_reason'])
Modified g4f/gui/server/api.py +1 -0
@@ -93,6 +93,7 @@ class Api:
93 93 "vision": getattr(provider, "default_vision_model", None) is not None,
94 94 "nodriver": getattr(provider, "use_nodriver", False),
95 95 "hf_space": getattr(provider, "hf_space", False),
96 "active_by_default": not provider.needs_auth if provider.active_by_default is None else provider.active_by_default,
96 97 "auth": provider.needs_auth,
97 98 "login_url": getattr(provider, "login_url", None),
98 99 } for provider in Provider.__providers__ if provider.working and safe_get_models(provider)]
Modified g4f/providers/types.py +1 -0
@@ -20,6 +20,7 @@ class BaseProvider(ABC):
20 20
21 21 url: str = None
22 22 working: bool = False
23 active_by_default: bool = None
23 24 needs_auth: bool = False
24 25 supports_stream: bool = False
25 26 supports_message_history: bool = False
Modified g4f/tools/web_search.py +3 -0
@@ -322,6 +322,9 @@ async def do_search(
322 322 Returns:
323 323 tuple[str, Optional[Sources]]: A tuple containing the new prompt with search results and the sources.
324 324 """
325 if not isinstance(prompt, str):
326 return prompt, None
327
325 328 # If the prompt already includes the instructions, do not perform a search.
326 329 if instructions and instructions in prompt:
327 330 return prompt, None