summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bing.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-08-28 22:07:20 +0200
committerGitHub <noreply@github.com>2023-08-28 22:07:20 +0200
commitab2bc031aa678c84f7f0381483d27aa24a2a33f2 (patch)
treed6c4c14f4e6a3a81660ddb75272bc5da81cacecc /g4f/Provider/Bing.py
parent~ | code styling (diff)
parentMerge branch 'main' into patch-1 (diff)
downloadgpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.tar
gpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.tar.gz
gpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.tar.bz2
gpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.tar.lz
gpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.tar.xz
gpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.tar.zst
gpt4free-ab2bc031aa678c84f7f0381483d27aa24a2a33f2.zip
Diffstat (limited to 'g4f/Provider/Bing.py')
-rw-r--r--g4f/Provider/Bing.py80
1 files changed, 52 insertions, 28 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index fe4f9a58..88394f70 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -20,12 +20,38 @@ class Bing(AsyncGeneratorProvider):
if len(messages) < 2:
prompt = messages[0]["content"]
context = None
-
else:
prompt = messages[-1]["content"]
context = create_context(messages[:-1])
-
- return stream_generate(prompt, context, cookies)
+
+ if 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': '',
+ '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 = ""
@@ -152,32 +178,34 @@ class Defaults:
'x-forwarded-for': ip_address,
}
- optionsSets = [
- 'saharasugg',
- 'enablenewsfc',
- 'clgalileo',
- 'gencontentv3',
- "nlu_direct_response_filter",
- "deepleo",
- "disable_emoji_spoken_text",
- "responsible_ai_policy_235",
- "enablemm",
- "h3precise"
- "dtappid",
- "cricinfo",
- "cricinfov2",
- "dv3sugg",
- "nojbfedge"
- ]
+ optionsSets = {
+ "optionsSets": [
+ 'saharasugg',
+ 'enablenewsfc',
+ 'clgalileo',
+ 'gencontentv3',
+ "nlu_direct_response_filter",
+ "deepleo",
+ "disable_emoji_spoken_text",
+ "responsible_ai_policy_235",
+ "enablemm",
+ "h3precise"
+ "dtappid",
+ "cricinfo",
+ "cricinfov2",
+ "dv3sugg",
+ "nojbfedge"
+ ]
+ }
-def format_message(message: dict) -> str:
- return json.dumps(message, ensure_ascii=False) + Defaults.delimiter
+def format_message(msg: dict) -> str:
+ return json.dumps(msg, ensure_ascii=False) + Defaults.delimiter
def create_message(conversation: Conversation, prompt: str, context: str=None) -> str:
struct = {
'arguments': [
{
- 'optionsSets': Defaults.optionsSets,
+ **Defaults.optionsSets,
'source': 'cib',
'allowedMessageTypes': Defaults.allowedMessageTypes,
'sliceIds': Defaults.sliceIds,
@@ -257,10 +285,6 @@ async def stream_generate(
response_txt += inline_txt + '\n'
result_text += inline_txt + '\n'
- if returned_text.endswith(' '):
- final = True
- break
-
if response_txt.startswith(returned_text):
new = response_txt[len(returned_text):]
if new != "\n":
@@ -284,4 +308,4 @@ def run(generator: AsyncGenerator[Union[Any, str], Any]):
yield loop.run_until_complete(gen.__anext__())
except StopAsyncIteration:
- break
+ break \ No newline at end of file