mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-09-17 10:29:29 -04:00
Merge branch 'main' into hugging
This commit is contained in:
commit
a11b5baaa4
@ -23,12 +23,38 @@ class Bing(AsyncGeneratorProvider):
|
|||||||
if len(messages) < 2:
|
if len(messages) < 2:
|
||||||
prompt = messages[0]["content"]
|
prompt = messages[0]["content"]
|
||||||
context = None
|
context = None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
prompt = messages[-1]["content"]
|
prompt = messages[-1]["content"]
|
||||||
context = create_context(messages[:-1])
|
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]]):
|
def create_context(messages: list[dict[str, str]]):
|
||||||
context = ""
|
context = ""
|
||||||
@ -155,32 +181,34 @@ class Defaults:
|
|||||||
'x-forwarded-for': ip_address,
|
'x-forwarded-for': ip_address,
|
||||||
}
|
}
|
||||||
|
|
||||||
optionsSets = [
|
optionsSets = {
|
||||||
'saharasugg',
|
"optionsSets": [
|
||||||
'enablenewsfc',
|
'saharasugg',
|
||||||
'clgalileo',
|
'enablenewsfc',
|
||||||
'gencontentv3',
|
'clgalileo',
|
||||||
"nlu_direct_response_filter",
|
'gencontentv3',
|
||||||
"deepleo",
|
"nlu_direct_response_filter",
|
||||||
"disable_emoji_spoken_text",
|
"deepleo",
|
||||||
"responsible_ai_policy_235",
|
"disable_emoji_spoken_text",
|
||||||
"enablemm",
|
"responsible_ai_policy_235",
|
||||||
"h3precise"
|
"enablemm",
|
||||||
"dtappid",
|
"h3precise"
|
||||||
"cricinfo",
|
"dtappid",
|
||||||
"cricinfov2",
|
"cricinfo",
|
||||||
"dv3sugg",
|
"cricinfov2",
|
||||||
"nojbfedge"
|
"dv3sugg",
|
||||||
]
|
"nojbfedge"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
def format_message(message: dict) -> str:
|
def format_message(msg: dict) -> str:
|
||||||
return json.dumps(message, ensure_ascii=False) + Defaults.delimiter
|
return json.dumps(msg, ensure_ascii=False) + Defaults.delimiter
|
||||||
|
|
||||||
def create_message(conversation: Conversation, prompt: str, context: str=None) -> str:
|
def create_message(conversation: Conversation, prompt: str, context: str=None) -> str:
|
||||||
struct = {
|
struct = {
|
||||||
'arguments': [
|
'arguments': [
|
||||||
{
|
{
|
||||||
'optionsSets': Defaults.optionsSets,
|
**Defaults.optionsSets,
|
||||||
'source': 'cib',
|
'source': 'cib',
|
||||||
'allowedMessageTypes': Defaults.allowedMessageTypes,
|
'allowedMessageTypes': Defaults.allowedMessageTypes,
|
||||||
'sliceIds': Defaults.sliceIds,
|
'sliceIds': Defaults.sliceIds,
|
||||||
@ -260,10 +288,6 @@ async def stream_generate(
|
|||||||
response_txt += inline_txt + '\n'
|
response_txt += inline_txt + '\n'
|
||||||
result_text += inline_txt + '\n'
|
result_text += inline_txt + '\n'
|
||||||
|
|
||||||
if returned_text.endswith(' '):
|
|
||||||
final = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if response_txt.startswith(returned_text):
|
if response_txt.startswith(returned_text):
|
||||||
new = response_txt[len(returned_text):]
|
new = response_txt[len(returned_text):]
|
||||||
if new != "\n":
|
if new != "\n":
|
||||||
@ -276,4 +300,16 @@ async def stream_generate(
|
|||||||
final = True
|
final = True
|
||||||
break
|
break
|
||||||
finally:
|
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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user