@ -1,16 +1,11 @@
import asyncio
import asyncio , json , os , random , aiohttp
import json
import os
import random
import aiohttp
import asyncio
from aiohttp import ClientSession
from aiohttp import ClientSession
from . . typing import Any , AsyncGenerator , CreateResult , Union
from . . typing import Any , AsyncGenerator , CreateResult , Union
from . base_provider import BaseProvider
from . base_provider import AsyncGeneratorProvider, get_cookies
class Bing ( Base Provider) :
class Bing ( AsyncGenerator Provider) :
url = " https://bing.com/chat "
url = " https://bing.com/chat "
supports_gpt_4 = True
supports_gpt_4 = True
working = True
working = True
@ -20,53 +15,50 @@ class Bing(BaseProvider):
def create_completion (
def create_completion (
model : str ,
model : str ,
messages : list [ dict [ str , str ] ] ,
messages : list [ dict [ str , str ] ] ,
stream : bool ,
cookies : dict = None ,
* * kwargs : Any
* * kwargs
) - > CreateResult :
) - > AsyncGenerator :
yield from run ( create ( messages , * * kwargs ) )
if len ( messages ) < 2 :
def create (
prompt = messages [ 0 ] [ " content " ]
messages : list [ dict [ str , str ] ] ,
context = None
cookies : dict = { }
) :
else :
if len ( messages ) < 2 :
prompt = messages [ - 1 ] [ " content " ]
prompt = messages [ 0 ] [ " content " ]
context = create_context ( messages [ : - 1 ] )
context = None
if cookies is None :
#TODO: Will implement proper cookie retrieval later and use a try-except mechanism in 'stream_generate' instead of defaulting the cookie value like this
else :
#cookies = get_cookies(".bing.com")
prompt = messages [ - 1 ] [ " content " ]
cookies =
context = convert ( messages [ : - 1 ] )
{
' MUID ' : ' ' ,
if not cookies :
' BCP ' : ' ' ,
cookies = {
' MUIDB ' : ' ' ,
' MUID ' : ' ' ,
' USRLOC ' : ' ' ,
' BCP ' : ' ' ,
' SRCHD ' : ' AF=hpcodx ' ,
' MUIDB ' : ' ' ,
' MMCASM ' : ' ' ,
' USRLOC ' : ' ' ,
' _UR ' : ' ' ,
' SRCHD ' : ' AF=hpcodx ' ,
' ANON ' : ' ' ,
' MMCASM ' : ' ' ,
' NAP ' : ' ' ,
' _UR ' : ' ' ,
' ABDEF ' : ' ' ,
' ANON ' : ' ' ,
' PPLState ' : ' 1 ' ,
' NAP ' : ' ' ,
' KievRPSSecAuth ' : ' ' ,
' ABDEF ' : ' ' ,
' _U ' : ' ' ,
' PPLState ' : ' 1 ' ,
' SUID ' : ' ' ,
' KievRPSSecAuth ' : ' ' ,
' _EDGE_S ' : ' ' ,
' _U ' : ' ' ,
' WLS ' : ' ' ,
' SUID ' : ' ' ,
' _HPVN ' : ' ' ,
' _EDGE_S ' : ' ' ,
' _SS ' : ' ' ,
' WLS ' : ' ' ,
' _clck ' : ' ' ,
' _HPVN ' : ' ' ,
' SRCHUSR ' : ' ' ,
' _SS ' : ' ' ,
' _RwBf ' : ' ' ,
' _clck ' : ' ' ,
' SRCHHPGUSR ' : ' ' ,
' SRCHUSR ' : ' ' ,
' ipv6 ' : ' ' ,
' _RwBf ' : ' ' ,
}
' SRCHHPGUSR ' : ' ' ,
' ipv6 ' : ' ' ,
}
return stream_generate ( prompt , context , cookies )
return stream_generate ( prompt , context , cookies )
def c onver t( messages : list [ dict [ str , str ] ] ) :
def c reate_contex t( messages : list [ dict [ str , str ] ] ) :
context = " "
context = " "
for message in messages :
for message in messages :