summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bing.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-09-07 19:45:04 +0200
committerGitHub <noreply@github.com>2023-09-07 19:45:04 +0200
commit7ca1a59d95b52f94f674e8f981eab910b2f03518 (patch)
treeca506c3c152f3906a5b727a4cc6ebba1fd59d335 /g4f/Provider/Bing.py
parent~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff)
parentFix imports in Bing (diff)
downloadgpt4free-0.0.2.7.tar
gpt4free-0.0.2.7.tar.gz
gpt4free-0.0.2.7.tar.bz2
gpt4free-0.0.2.7.tar.lz
gpt4free-0.0.2.7.tar.xz
gpt4free-0.0.2.7.tar.zst
gpt4free-0.0.2.7.zip
Diffstat (limited to 'g4f/Provider/Bing.py')
-rw-r--r--g4f/Provider/Bing.py38
1 files changed, 9 insertions, 29 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index cec82108..05be27e7 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -1,23 +1,17 @@
from __future__ import annotations
-import asyncio
+import random
import json
import os
-import random
-
-import aiohttp
-from aiohttp import ClientSession
-
-from ..typing import Any, AsyncGenerator, CreateResult, Union
+from aiohttp import ClientSession, ClientTimeout
+from ..typing import AsyncGenerator
from .base_provider import AsyncGeneratorProvider, get_cookies
class Bing(AsyncGeneratorProvider):
url = "https://bing.com/chat"
- needs_auth = True
working = True
supports_gpt_4 = True
- supports_stream = True
@staticmethod
def create_async_generator(
@@ -34,18 +28,16 @@ class Bing(AsyncGeneratorProvider):
prompt = messages[-1]["content"]
context = create_context(messages[:-1])
- if cookies and "SRCHD" in cookies:
- #TODO: Will implement proper cookie retrieval later and use a try-except mechanism in 'stream_generate' instead of defaulting the cookie value like this
- cookies_dict = {
- 'SRCHD' : cookies["SRCHD"],
+ if not cookies or "SRCHD" not in cookies:
+ cookies = {
+ 'SRCHD' : 'AF=NOFORM',
'PPLState' : '1',
'KievRPSSecAuth': '',
'SUID' : '',
'SRCHUSR' : '',
'SRCHHPGUSR' : '',
}
-
- return stream_generate(prompt, context, cookies_dict)
+ return stream_generate(prompt, context, cookies)
def create_context(messages: list[dict[str, str]]):
context = "".join(f"[{message['role']}](#message)\n{message['content']}\n\n" for message in messages)
@@ -236,7 +228,7 @@ async def stream_generate(
cookies: dict=None
):
async with ClientSession(
- timeout=aiohttp.ClientTimeout(total=900),
+ timeout=ClientTimeout(total=900),
cookies=cookies,
headers=Defaults.headers,
) as session:
@@ -288,16 +280,4 @@ async def stream_generate(
final = True
break
finally:
- await delete_conversation(session, conversation)
-
-def run(generator: AsyncGenerator[Union[Any, str], Any]):
- loop = asyncio.get_event_loop()
- gen = generator.__aiter__()
-
- while True:
- try:
- yield loop.run_until_complete(gen.__anext__())
-
- except StopAsyncIteration:
- break
-
+ await delete_conversation(session, conversation) \ No newline at end of file