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

XFEstudio/gpt4free

fix: replace format_image_prompt with format_media_prompt across multiple files

- Updated imports to use format_media_prompt in g4f/Provider/ARTA.py, PollinationsAI.py, PollinationsImage.py, Websim.py, audio/OpenAIFM.py, hf_space/BlackForestLabs_Flux1Dev.py, hf_space/DeepseekAI_JanusPro7b.py, hf_space/G4F.py, hf_space/Microsoft_Phi_4_Multimodal.py, hf_space/StabilityAI_SD35Large.py, needs_auth/BingCreateImages.py, needs_auth/BlackboxPro.py, needs_auth/DeepInfra.py, needs_auth/Gemini.py, needs_auth/MicrosoftDesigner.py, needs_auth/OpenaiChat.py, needs_auth/hf/HuggingChat.py, needs_auth/hf/HuggingFaceInference.py, needs_auth/hf/HuggingFaceMedia.py, not_working/AllenAI.py, template/OpenaiTemplate.py, api.py, and gui/server/api.py - Replaced calls to format_image_prompt with format_media_prompt in relevant locations - Changed media prompt handling in various providers to ensure consistent usage of format_media_prompt - Modified the __aenter__ and __aexit__ methods of requests/aiohttp.py to properly manage ClientSession lifecycle

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

代码差异

23 个文件 +66 -59
Modified g4f/Provider/ARTA.py +2 -2
@@ -13,7 +13,7 @@ from ..providers.response import ImageResponse, Reasoning
13 13 from ..errors import ResponseError, ModelNotFoundError
14 14 from ..cookies import get_cookies_dir
15 15 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
16 from .helper import format_image_prompt
16 from .helper import format_media_prompt
17 17 from .. import debug
18 18
19 19 class ARTA(AsyncGeneratorProvider, ProviderModelMixin):
@@ -177,7 +177,7 @@ class ARTA(AsyncGeneratorProvider, ProviderModelMixin):
177 177 **kwargs
178 178 ) -> AsyncResult:
179 179 model = cls.get_model(model)
180 prompt = format_image_prompt(messages, prompt)
180 prompt = format_media_prompt(messages, prompt)
181 181
182 182 # Generate a random seed if not provided
183 183 if seed is None:
Modified g4f/Provider/PollinationsAI.py +4 -3
@@ -9,7 +9,7 @@ from urllib.parse import quote_plus
9 9 from typing import Optional
10 10 from aiohttp import ClientSession
11 11
12 from .helper import filter_none, format_image_prompt
12 from .helper import filter_none, format_media_prompt
13 13 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
14 14 from ..typing import AsyncResult, Messages, MediaListType
15 15 from ..image import is_data_an_audio
@@ -132,6 +132,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
132 132 ### Image Models ###
133 133 "sdxl-turbo": "turbo",
134 134 "gpt-image": "gptimage",
135 "dall-e-3": "gptimage",
135 136 "flux-pro": "flux",
136 137 "flux-dev": "flux",
137 138 "flux-schnell": "flux"
@@ -292,7 +293,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
292 293 if model in cls.image_models:
293 294 async for chunk in cls._generate_image(
294 295 model=model,
295 prompt=format_image_prompt(messages, prompt),
296 prompt=format_media_prompt(messages, prompt),
296 297 proxy=proxy,
297 298 aspect_ratio=aspect_ratio,
298 299 width=width,
@@ -524,7 +525,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
524 525 debug.error("Error generating title and followups")
525 526 debug.error(e)
526 527 elif response.headers["content-type"].startswith("application/json"):
527 prompt = format_image_prompt(messages)
528 prompt = format_media_prompt(messages)
528 529 result = await response.json()
529 530 if result.get("model"):
530 531 yield ProviderInfo(**cls.get_dict(), model=result.get("model"))
Modified g4f/Provider/PollinationsImage.py +2 -2
@@ -2,7 +2,7 @@ from __future__ import annotations
2 2
3 3 from typing import Optional
4 4
5 from .helper import format_image_prompt
5 from .helper import format_media_prompt
6 6 from ..typing import AsyncResult, Messages
7 7 from ..constants import STATIC_URL
8 8 from .PollinationsAI import PollinationsAI
@@ -54,7 +54,7 @@ class PollinationsImage(PollinationsAI):
54 54 cls.get_models()
55 55 async for chunk in cls._generate_image(
56 56 model=model,
57 prompt=format_image_prompt(messages, prompt),
57 prompt=format_media_prompt(messages, prompt),
58 58 proxy=proxy,
59 59 aspect_ratio=aspect_ratio,
60 60 width=width,
Modified g4f/Provider/Websim.py +2 -2
@@ -11,7 +11,7 @@ from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
11 11 from ..requests.raise_for_status import raise_for_status
12 12 from ..errors import ResponseStatusError
13 13 from ..providers.response import ImageResponse
14 from .helper import format_prompt, format_image_prompt
14 from .helper import format_prompt, format_media_prompt
15 15
16 16
17 17 class Websim(AsyncGeneratorProvider, ProviderModelMixin):
@@ -110,7 +110,7 @@ class Websim(AsyncGeneratorProvider, ProviderModelMixin):
110 110 proxy: str = None,
111 111 **kwargs
112 112 ) -> AsyncResult:
113 used_prompt = format_image_prompt(messages, prompt)
113 used_prompt = format_media_prompt(messages, prompt)
114 114
115 115 async with ClientSession(headers=headers) as session:
116 116 data = {
Modified g4f/Provider/audio/OpenAIFM.py +14 -14
@@ -4,7 +4,7 @@ from aiohttp import ClientSession
4 4
5 5 from ...typing import AsyncResult, Messages
6 6 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
7 from ..helper import get_last_user_message, get_system_prompt
7 from ..helper import format_media_prompt, get_system_prompt
8 8 from ...image.copy_images import save_response_media
9 9 from ...requests.raise_for_status import raise_for_status
10 10 from ...requests.aiohttp import get_connector
@@ -15,14 +15,13 @@ class OpenAIFM(AsyncGeneratorProvider, ProviderModelMixin):
15 15 url = "https://www.openai.fm"
16 16 api_endpoint = "https://www.openai.fm/api/generate"
17 17 working = True
18
19 default_model = 'gpt-4o-mini-tts'
20 default_audio_model = default_model
21 default_voice = 'coral'
22 voices = ['alloy', 'ash', 'ballad', default_voice, 'echo', 'fable', 'onyx', 'nova', 'sage', 'shimmer', 'verse']
23 audio_models = {default_audio_model: voices}
18
19 default_model = 'coral'
20 voices = ['alloy', 'ash', 'ballad', default_model, 'echo', 'fable', 'onyx', 'nova', 'sage', 'shimmer', 'verse']
21 audio_models = {"gpt-4o-mini-tts": voices}
22 model_aliases = {"gpt-4o-mini-tts": default_model}
24 23 models = voices
25
24
26 25 friendly = """Affect/personality: A cheerful guide
27 26
28 27 Tone: Friendly, clear, and reassuring, creating a calm atmosphere and making the listener feel confident and comfortable.
@@ -99,16 +98,17 @@ Emotion: Restrained enthusiasm for discoveries and findings, conveying intellect
99 98 audio: dict = {},
100 99 **kwargs
101 100 ) -> AsyncResult:
102 # Retrieve parameters from the audio dictionary
103 voice = audio.get("voice", kwargs.get("voice", cls.default_voice))
104 instructions = audio.get("instructions", kwargs.get("instructions", get_system_prompt(messages) or cls.friendly))
101 model = cls.get_model(model)
102 voice = audio.get("voice", kwargs.get("voice", model))
103 default_instructions = get_system_prompt(messages) or cls.friendly
104 instructions = audio.get("instructions", kwargs.get("instructions", default_instructions))
105 105 headers = {
106 106 **DEFAULT_HEADERS,
107 107 "referer": f"{cls.url}/"
108 108 }
109 text = get_last_user_message(messages, prompt)
109 prompt = format_media_prompt(messages, prompt)
110 110 params = {
111 "input": text,
111 "input": prompt,
112 112 "prompt": instructions,
113 113 "voice": voice
114 114 }
@@ -118,5 +118,5 @@ Emotion: Restrained enthusiasm for discoveries and findings, conveying intellect
118 118 params=params
119 119 ) as response:
120 120 await raise_for_status(response)
121 async for chunk in save_response_media(response, text, [model, voice]):
121 async for chunk in save_response_media(response, prompt, [model, voice]):
122 122 yield chunk
Modified g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py +2 -2
@@ -9,7 +9,7 @@ from ...requests import StreamSession
9 9 from ...image import use_aspect_ratio
10 10 from ...errors import ResponseError
11 11 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
12 from ..helper import format_image_prompt
12 from ..helper import format_media_prompt
13 13 from .DeepseekAI_JanusPro7b import get_zerogpu_token
14 14 from .raise_for_status import raise_for_status
15 15
@@ -70,7 +70,7 @@ class BlackForestLabs_Flux1Dev(AsyncGeneratorProvider, ProviderModelMixin):
70 70 **kwargs
71 71 ) -> AsyncResult:
72 72 async with StreamSession(impersonate="chrome", proxy=proxy) as session:
73 prompt = format_image_prompt(messages, prompt)
73 prompt = format_media_prompt(messages, prompt)
74 74 data = use_aspect_ratio({"width": width, "height": height}, aspect_ratio)
75 75 data = [prompt, seed, randomize_seed, data.get("width"), data.get("height"), guidance_scale, num_inference_steps]
76 76 conversation = JsonConversation(zerogpu_token=api_key, zerogpu_uuid=zerogpu_uuid, session_hash=uuid.uuid4().hex)
Modified g4f/Provider/hf_space/DeepseekAI_JanusPro7b.py +2 -2
@@ -9,7 +9,7 @@ import urllib.parse
9 9
10 10 from ...typing import AsyncResult, Messages, Cookies, MediaListType
11 11 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
12 from ..helper import format_prompt, format_image_prompt
12 from ..helper import format_prompt, format_media_prompt
13 13 from ...providers.response import JsonConversation, ImageResponse, Reasoning
14 14 from ...requests.aiohttp import StreamSession, StreamResponse, FormData
15 15 from ...requests.raise_for_status import raise_for_status
@@ -85,7 +85,7 @@ class DeepseekAI_JanusPro7b(AsyncGeneratorProvider, ProviderModelMixin):
85 85 if model == cls.default_image_model or prompt is not None:
86 86 method = "image"
87 87 prompt = format_prompt(messages) if prompt is None and conversation is None else prompt
88 prompt = format_image_prompt(messages, prompt)
88 prompt = format_media_prompt(messages, prompt)
89 89 if seed is None:
90 90 seed = random.randint(1000, 999999)
91 91
Modified g4f/Provider/hf_space/G4F.py +2 -2
@@ -7,7 +7,7 @@ import asyncio
7 7
8 8 from ...typing import AsyncResult, Messages
9 9 from ...providers.response import ImageResponse, Reasoning, JsonConversation
10 from ..helper import format_image_prompt, get_random_string
10 from ..helper import format_media_prompt, get_random_string
11 11 from .DeepseekAI_JanusPro7b import DeepseekAI_JanusPro7b, get_zerogpu_token
12 12 from .BlackForestLabs_Flux1Dev import BlackForestLabs_Flux1Dev
13 13 from .raise_for_status import raise_for_status
@@ -80,7 +80,7 @@ class G4F(DeepseekAI_JanusPro7b):
80 80 width = max(32, width - (width % 8))
81 81 height = max(32, height - (height % 8))
82 82 if prompt is None:
83 prompt = format_image_prompt(messages)
83 prompt = format_media_prompt(messages)
84 84 if seed is None:
85 85 seed = random.randint(9999, 2**32 - 1)
86 86
Modified g4f/Provider/hf_space/Microsoft_Phi_4_Multimodal.py +2 -2
@@ -5,7 +5,7 @@ import uuid
5 5
6 6 from ...typing import AsyncResult, Messages, Cookies, MediaListType
7 7 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
8 from ..helper import format_prompt, format_image_prompt
8 from ..helper import format_prompt, format_media_prompt
9 9 from ...providers.response import JsonConversation
10 10 from ...requests.aiohttp import StreamSession, StreamResponse, FormData
11 11 from ...requests.raise_for_status import raise_for_status
@@ -104,7 +104,7 @@ class Microsoft_Phi_4_Multimodal(AsyncGeneratorProvider, ProviderModelMixin):
104 104 **kwargs
105 105 ) -> AsyncResult:
106 106 prompt = format_prompt(messages) if prompt is None and conversation is None else prompt
107 prompt = format_image_prompt(messages, prompt)
107 prompt = format_media_prompt(messages, prompt)
108 108
109 109 session_hash = uuid.uuid4().hex if conversation is None else getattr(conversation, "session_hash", uuid.uuid4().hex)
110 110 async with StreamSession(proxy=proxy, impersonate="chrome") as session:
Modified g4f/Provider/hf_space/StabilityAI_SD35Large.py +2 -2
@@ -8,7 +8,7 @@ from ...providers.response import ImageResponse, ImagePreview
8 8 from ...image import use_aspect_ratio
9 9 from ...errors import ResponseError
10 10 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
11 from ..helper import format_image_prompt
11 from ..helper import format_media_prompt
12 12
13 13 class StabilityAI_SD35Large(AsyncGeneratorProvider, ProviderModelMixin):
14 14 label = "StabilityAI SD-3.5-Large"
@@ -46,7 +46,7 @@ class StabilityAI_SD35Large(AsyncGeneratorProvider, ProviderModelMixin):
46 46 if api_key is not None:
47 47 headers["Authorization"] = f"Bearer {api_key}"
48 48 async with ClientSession(headers=headers) as session:
49 prompt = format_image_prompt(messages, prompt)
49 prompt = format_media_prompt(messages, prompt)
50 50 data = use_aspect_ratio({"width": width, "height": height}, aspect_ratio)
51 51 data = {
52 52 "data": [prompt, negative_prompt, seed, randomize_seed, data.get("width"), data.get("height"), guidance_scale, num_inference_steps]
Modified g4f/Provider/needs_auth/BingCreateImages.py +2 -2
@@ -6,7 +6,7 @@ from ...errors import MissingAuthError
6 6 from ...typing import AsyncResult, Messages, Cookies
7 7 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
8 8 from .bing.create_images import create_images, create_session
9 from ..helper import format_image_prompt
9 from ..helper import format_media_prompt
10 10
11 11 class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
12 12 label = "Microsoft Designer in Bing"
@@ -36,7 +36,7 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
36 36 **kwargs
37 37 ) -> AsyncResult:
38 38 session = BingCreateImages(cookies, proxy, api_key)
39 yield await session.generate(format_image_prompt(messages, prompt))
39 yield await session.generate(format_media_prompt(messages, prompt))
40 40
41 41 async def generate(self, prompt: str) -> ImageResponse:
42 42 """
Modified g4f/Provider/needs_auth/BlackboxPro.py +2 -2
@@ -16,7 +16,7 @@ from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
16 16 from ..openai.har_file import get_har_files
17 17 from ...image import to_data_uri
18 18 from ...cookies import get_cookies_dir
19 from ..helper import format_image_prompt, render_messages
19 from ..helper import format_media_prompt, render_messages
20 20 from ...providers.response import JsonConversation, ImageResponse
21 21 from ...tools.media import merge_media
22 22 from ...errors import RateLimitError, NoValidHarFileError
@@ -1343,7 +1343,7 @@ class BlackboxPro(AsyncGeneratorProvider, ProviderModelMixin):
1343 1343 image_url_match = re.search(r'!\[.*?\]\((.*?)\)', full_response_text)
1344 1344 if image_url_match:
1345 1345 image_url = image_url_match.group(1)
1346 yield ImageResponse(urls=[image_url], alt=format_image_prompt(messages, prompt))
1346 yield ImageResponse(urls=[image_url], alt=format_media_prompt(messages, prompt))
1347 1347 return
1348 1348
1349 1349 # Handle conversation history once, in one place
Modified g4f/Provider/needs_auth/DeepInfra.py +2 -2
Modified g4f/Provider/needs_auth/Gemini.py +2 -2
Modified g4f/Provider/needs_auth/MicrosoftDesigner.py +2 -2
Modified g4f/Provider/needs_auth/OpenaiChat.py +2 -2
Modified g4f/Provider/needs_auth/hf/HuggingChat.py +2 -2
Modified g4f/Provider/needs_auth/hf/HuggingFaceInference.py +3 -3
Modified g4f/Provider/needs_auth/hf/HuggingFaceMedia.py +2 -2
Modified g4f/Provider/not_working/AllenAI.py +1 -1
Modified g4f/Provider/template/OpenaiTemplate.py +2 -2
Modified g4f/gui/server/api.py +2 -2
Modified g4f/requests/aiohttp.py +8 -2