summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner.lohaus@netformic.com>2023-08-23 02:16:35 +0200
committerHeiner Lohaus <heiner.lohaus@netformic.com>2023-08-23 02:16:35 +0200
commitd1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274 (patch)
tree2a595806659afb7d0d8f3c03e55394227f15ddcf /g4f
parentFix bing provider (diff)
downloadgpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.tar
gpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.tar.gz
gpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.tar.bz2
gpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.tar.lz
gpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.tar.xz
gpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.tar.zst
gpt4free-d1b6921b5fa3d9dbd7f1cce6e4f396744a7a2274.zip
Diffstat (limited to 'g4f')
-rw-r--r--g4f/Provider/Bing.py58
1 files changed, 39 insertions, 19 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index 364e9c1d..b9b9e9a4 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -13,34 +13,54 @@ from .base_provider import BaseProvider
class Bing(BaseProvider):
url = "https://bing.com/chat"
+ working = True
supports_gpt_4 = True
- @staticmethod
+ @classmethod
def create_completion(
+ cls,
model: str,
messages: list[dict[str, str]],
stream: bool,
**kwargs: Any
) -> CreateResult:
- yield from run(create(messages, **kwargs))
-
-def create(
+ if stream:
+ yield from run(cls.create_async_generator(model, messages, **kwargs))
+ else:
+ yield asyncio.run(cls.create_async(model, messages, **kwargs))
+
+ @classmethod
+ async def create_async(
+ cls,
+ model: str,
messages: list[dict[str, str]],
- cookies: dict = {}
- ):
- if len(messages) < 2:
- prompt = messages[0]["content"]
- context = None
-
- else:
- prompt = messages[-1]["content"]
- context = convert(messages[:-1])
-
- if not cookies:
- for cookie in browser_cookie3.load(domain_name='.bing.com'):
- cookies[cookie.name] = cookie.value
-
- return stream_generate(prompt, context, cookies)
+ **kwargs: Any,
+ ) -> str:
+ result = []
+ async for chunk in cls.create_async_generator(model, messages, **kwargs):
+ result.append(chunk)
+ if result:
+ return "".join(result)
+
+ @staticmethod
+ def create_async_generator(
+ model: str,
+ messages: list[dict[str, str]],
+ cookies: dict = {}
+ ) -> AsyncGenerator:
+ if len(messages) < 2:
+ prompt = messages[0]["content"]
+ context = None
+
+ else:
+ prompt = messages[-1]["content"]
+ context = convert(messages[:-1])
+
+ if not cookies:
+ for cookie in browser_cookie3.load(domain_name='.bing.com'):
+ cookies[cookie.name] = cookie.value
+
+ return stream_generate(prompt, context, cookies)
def convert(messages: list[dict[str, str]]):
context = ""