summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bing.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-13 05:27:54 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-13 05:27:54 +0100
commitecf110e59a35ad41377b82d8d1f5f58802b66539 (patch)
treec3d9da4d4305c14fe01b3fcd77af161b7fb2a9cb /g4f/Provider/Bing.py
parentAdd count chars to gui, Add retry support to fix rate limit in Bing (diff)
downloadgpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.tar
gpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.tar.gz
gpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.tar.bz2
gpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.tar.lz
gpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.tar.xz
gpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.tar.zst
gpt4free-ecf110e59a35ad41377b82d8d1f5f58802b66539.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Bing.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index ca431355..9a067b0f 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -10,13 +10,13 @@ from datetime import datetime
from aiohttp import ClientSession, ClientTimeout, BaseConnector, WSMsgType
from ..typing import AsyncResult, Messages, ImageType, Cookies
-from ..image import ImageResponse, ImageRequest
+from ..image import ImageRequest
from ..errors import ResponseStatusError
from .base_provider import AsyncGeneratorProvider
from .helper import get_connector, get_random_hex
from .bing.upload_image import upload_image
-from .bing.create_images import create_images
from .bing.conversation import Conversation, create_conversation, delete_conversation
+from .BingCreateImages import BingCreateImages
from .. import debug
class Tones:
@@ -71,7 +71,7 @@ class Bing(AsyncGeneratorProvider):
gpt4_turbo = True if model.startswith("gpt-4-turbo") else False
- return stream_generate(prompt, tone, image, context, cookies, get_connector(connector, proxy, True), web_search, gpt4_turbo, timeout)
+ return stream_generate(prompt, tone, image, context, cookies, get_connector(connector, proxy, True), proxy, web_search, gpt4_turbo, timeout)
def create_context(messages: Messages) -> str:
"""
@@ -307,6 +307,7 @@ async def stream_generate(
context: str = None,
cookies: dict = None,
connector: BaseConnector = None,
+ proxy: str = None,
web_search: bool = False,
gpt4_turbo: bool = False,
timeout: int = 900,
@@ -387,8 +388,9 @@ async def stream_generate(
elif message.get('contentType') == "IMAGE":
prompt = message.get('text')
try:
- image_response = ImageResponse(await create_images(session, prompt), prompt, {"preview": "{image}?w=200&h=200"})
- except:
+ image_client = BingCreateImages(cookies, proxy)
+ image_response = await image_client.create_async(prompt)
+ except Exception as e:
response_txt += f"\nhttps://www.bing.com/images/create?q={parse.quote(prompt)}"
do_read = False
if response_txt.startswith(returned_text):
@@ -415,4 +417,4 @@ async def stream_generate(
await asyncio.sleep(sleep_retry)
break
return
- await delete_conversation(session, headers, conversation)
+ await delete_conversation(session, conversation, headers)