@ -23,12 +23,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 = " "
@ -155,32 +181,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 ( m es sa ge , ensure_ascii = False ) + Defaults . delimiter
def format_message ( m sg: dict ) - > str :
return json . dumps ( m sg, 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 ,
@ -260,10 +288,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 " :
@ -276,4 +300,16 @@ async def stream_generate(
final = True
break
finally :
await delete_conversation ( session , conversation )
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