diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-05-18 23:13:57 +0200 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-05-18 23:13:57 +0200 |
commit | 9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa (patch) | |
tree | 4a137ca4958a81272e37f952b9330a197038f83f /g4f/Provider/BingCreateImages.py | |
parent | Fix OpenaiChat provider, improve proofofwork (diff) | |
download | gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.tar gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.tar.gz gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.tar.bz2 gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.tar.lz gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.tar.xz gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.tar.zst gpt4free-9ddac1715f7d656ebcf0bc4d0247e9bfd32626fa.zip |
Diffstat (limited to 'g4f/Provider/BingCreateImages.py')
-rw-r--r-- | g4f/Provider/BingCreateImages.py | 40 |
1 files changed, 7 insertions, 33 deletions
diff --git a/g4f/Provider/BingCreateImages.py b/g4f/Provider/BingCreateImages.py index 79dc5665..7a206c8f 100644 --- a/g4f/Provider/BingCreateImages.py +++ b/g4f/Provider/BingCreateImages.py @@ -1,18 +1,14 @@ from __future__ import annotations -import asyncio -import os -from typing import Iterator, Union - from ..cookies import get_cookies from ..image import ImageResponse -from ..errors import MissingRequirementsError, MissingAuthError +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, get_cookies_from_browser +from .bing.create_images import create_images, create_session class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin): - label = "Microsoft Designer" + label = "Microsoft Designer in Bing" parent = "Bing" url = "https://www.bing.com/images/create" working = True @@ -38,30 +34,9 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin): **kwargs ) -> AsyncResult: session = BingCreateImages(cookies, proxy, api_key) - yield await session.create_async(messages[-1]["content"]) - - def create(self, prompt: str) -> Iterator[Union[ImageResponse, str]]: - """ - Generator for creating imagecompletion based on a prompt. - - Args: - prompt (str): Prompt to generate images. - - Yields: - Generator[str, None, None]: The final output as markdown formatted string with images. - """ - cookies = self.cookies or get_cookies(".bing.com", False) - if cookies is None or "_U" not in cookies: - login_url = os.environ.get("G4F_LOGIN_URL") - if login_url: - yield f"Please login: [Bing]({login_url})\n\n" - try: - self.cookies = get_cookies_from_browser(self.proxy) - except MissingRequirementsError as e: - raise MissingAuthError(f'Missing "_U" cookie. {e}') - yield asyncio.run(self.create_async(prompt)) + yield await session.generate(messages[-1]["content"]) - async def create_async(self, prompt: str) -> ImageResponse: + async def generate(self, prompt: str) -> ImageResponse: """ Asynchronously creates a markdown formatted string with images based on the prompt. @@ -74,7 +49,6 @@ class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin): cookies = self.cookies or get_cookies(".bing.com", False) if cookies is None or "_U" not in cookies: raise MissingAuthError('Missing "_U" cookie') - proxy = self.proxy or os.environ.get("G4F_PROXY") - async with create_session(cookies, proxy) as session: - images = await create_images(session, prompt, proxy) + 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 {})
\ No newline at end of file |