mirror of
https://github.com/xtekky/gpt4free.git
synced 2026-02-03 22:32:05 -08:00
- 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
56 lines
2 KiB
Python
56 lines
2 KiB
Python
from __future__ import annotations
|
|
|
|
from ...cookies import get_cookies
|
|
from ...providers.response import ImageResponse
|
|
from ...errors import MissingAuthError
|
|
from ...typing import AsyncResult, Messages, Cookies
|
|
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
|
|
from .bing.create_images import create_images, create_session
|
|
from ..helper import format_media_prompt
|
|
|
|
class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
|
|
label = "Microsoft Designer in Bing"
|
|
url = "https://www.bing.com/images/create"
|
|
working = True
|
|
needs_auth = True
|
|
image_models = ["dall-e-3"]
|
|
models = image_models
|
|
|
|
def __init__(self, cookies: Cookies = None, proxy: str = None, api_key: str = None) -> None:
|
|
if api_key is not None:
|
|
if cookies is None:
|
|
cookies = {}
|
|
cookies["_U"] = api_key
|
|
self.cookies = cookies
|
|
self.proxy = proxy
|
|
|
|
@classmethod
|
|
async def create_async_generator(
|
|
cls,
|
|
model: str,
|
|
messages: Messages,
|
|
prompt: str = None,
|
|
api_key: str = None,
|
|
cookies: Cookies = None,
|
|
proxy: str = None,
|
|
**kwargs
|
|
) -> AsyncResult:
|
|
session = BingCreateImages(cookies, proxy, api_key)
|
|
yield await session.generate(format_media_prompt(messages, prompt))
|
|
|
|
async def generate(self, prompt: str) -> ImageResponse:
|
|
"""
|
|
Asynchronously creates a markdown formatted string with images based on the prompt.
|
|
|
|
Args:
|
|
prompt (str): Prompt to generate images.
|
|
|
|
Returns:
|
|
str: Markdown formatted string with images.
|
|
"""
|
|
cookies = self.cookies or get_cookies(".bing.com", False)
|
|
if cookies is None or "_U" not in cookies:
|
|
raise MissingAuthError('Missing "_U" cookie')
|
|
async with create_session(cookies, self.proxy) as session:
|
|
images = await create_images(session, prompt)
|
|
return ImageResponse(images, prompt, {"preview": "{image}?w=200&h=200"} if len(images) > 1 else {})
|