summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/BingCreateImages.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-11 02:40:30 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-11 02:40:30 +0200
commit009a67239a1df546fd22933a6b28eda03cd02a00 (patch)
tree6428fc06fe339e1c7cb197594dcb7399979a2e19 /g4f/Provider/BingCreateImages.py
parentIncrease conversation title lenght (diff)
downloadgpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.gz
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.bz2
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.lz
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.xz
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.zst
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.zip
Diffstat (limited to 'g4f/Provider/BingCreateImages.py')
-rw-r--r--g4f/Provider/BingCreateImages.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/g4f/Provider/BingCreateImages.py b/g4f/Provider/BingCreateImages.py
index f9c4f3b3..51e06dc5 100644
--- a/g4f/Provider/BingCreateImages.py
+++ b/g4f/Provider/BingCreateImages.py
@@ -7,16 +7,33 @@ from typing import Iterator, Union
from ..cookies import get_cookies
from ..image import ImageResponse
from ..errors import MissingRequirementsError, MissingAuthError
-from ..typing import Cookies
+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
-class BingCreateImages:
- """A class for creating images using Bing."""
+class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
+ url = "https://www.bing.com/images/create"
+ working = True
def __init__(self, cookies: Cookies = None, proxy: str = None) -> None:
self.cookies: Cookies = cookies
self.proxy: str = proxy
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ api_key: str = None,
+ cookies: Cookies = None,
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncResult:
+ if api_key is not None:
+ cookies = {"_U": api_key}
+ session = BingCreateImages(cookies, proxy)
+ 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.