summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bing.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/Bing.py')
-rw-r--r--g4f/Provider/Bing.py40
1 files changed, 14 insertions, 26 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index c31ba5a7..cec82108 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -1,9 +1,17 @@
-import asyncio, aiohttp, json, os, random
+from __future__ import annotations
-from aiohttp import ClientSession
-from ..typing import Any, AsyncGenerator, CreateResult, Union
+import asyncio
+import json
+import os
+import random
+
+import aiohttp
+from aiohttp import ClientSession
+
+from ..typing import Any, AsyncGenerator, CreateResult, Union
from .base_provider import AsyncGeneratorProvider, get_cookies
+
class Bing(AsyncGeneratorProvider):
url = "https://bing.com/chat"
needs_auth = True
@@ -26,41 +34,21 @@ class Bing(AsyncGeneratorProvider):
prompt = messages[-1]["content"]
context = create_context(messages[:-1])
- if cookies:
+ 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 = {
- 'MUID' : '',
- 'BCP' : '',
- 'MUIDB' : '',
- 'USRLOC' : '',
- 'SRCHD' : 'AF=hpcodx',
- 'MMCASM' : '',
- '_UR' : '',
- 'ANON' : '',
- 'NAP' : '',
- 'ABDEF' : '',
+ 'SRCHD' : cookies["SRCHD"],
'PPLState' : '1',
'KievRPSSecAuth': '',
- '_U' : '',
'SUID' : '',
- '_EDGE_S' : '',
- 'WLS' : '',
- '_HPVN' : '',
- '_SS' : '',
- '_clck' : '',
'SRCHUSR' : '',
- '_RwBf' : '',
'SRCHHPGUSR' : '',
- 'ipv6' : '',
}
return stream_generate(prompt, context, cookies_dict)
def create_context(messages: list[dict[str, str]]):
- context = ""
-
- for message in messages:
- context += "[%s](#message)\n%s\n\n" % (message["role"], message["content"])
+ context = "".join(f"[{message['role']}](#message)\n{message['content']}\n\n" for message in messages)
return context