mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 10:40:43 -08:00
Update Bing.py
This commit is contained in:
parent
90b2d90498
commit
5d47ba4205
1 changed files with 12 additions and 4 deletions
|
|
@ -60,7 +60,10 @@ class Bing(AsyncGeneratorProvider):
|
||||||
for key, value in default_cookies.items():
|
for key, value in default_cookies.items():
|
||||||
if key not in cookies:
|
if key not in cookies:
|
||||||
cookies[key] = value
|
cookies[key] = value
|
||||||
return stream_generate(prompt, tone, image, context, proxy, cookies, web_search)
|
|
||||||
|
gpt4_turbo = True if model.startswith("gpt-4-turbo") else False
|
||||||
|
|
||||||
|
return stream_generate(prompt, tone, image, context, proxy, cookies, web_search, gpt4_turbo)
|
||||||
|
|
||||||
def create_context(messages: Messages):
|
def create_context(messages: Messages):
|
||||||
return "".join(
|
return "".join(
|
||||||
|
|
@ -377,7 +380,7 @@ def compress_image_to_base64(img, compression_rate) -> str:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def create_message(conversation: Conversation, prompt: str, tone: str, context: str = None, web_search: bool = False) -> str:
|
def create_message(conversation: Conversation, prompt: str, tone: str, context: str = None, web_search: bool = False, gpt4_turbo: bool = False) -> str:
|
||||||
options_sets = Defaults.optionsSets
|
options_sets = Defaults.optionsSets
|
||||||
if tone == Tones.creative:
|
if tone == Tones.creative:
|
||||||
options_sets.append("h3imaginative")
|
options_sets.append("h3imaginative")
|
||||||
|
|
@ -387,8 +390,12 @@ def create_message(conversation: Conversation, prompt: str, tone: str, context:
|
||||||
options_sets.append("galileo")
|
options_sets.append("galileo")
|
||||||
else:
|
else:
|
||||||
options_sets.append("harmonyv3")
|
options_sets.append("harmonyv3")
|
||||||
|
|
||||||
if not web_search:
|
if not web_search:
|
||||||
options_sets.append("nosearchall")
|
options_sets.append("nosearchall")
|
||||||
|
|
||||||
|
if gpt4_turbo:
|
||||||
|
options_sets.append("dlgpt4t")
|
||||||
|
|
||||||
request_id = str(uuid.uuid4())
|
request_id = str(uuid.uuid4())
|
||||||
struct = {
|
struct = {
|
||||||
|
|
@ -444,7 +451,8 @@ async def stream_generate(
|
||||||
context: str = None,
|
context: str = None,
|
||||||
proxy: str = None,
|
proxy: str = None,
|
||||||
cookies: dict = None,
|
cookies: dict = None,
|
||||||
web_search: bool = False
|
web_search: bool = False,
|
||||||
|
gpt4_turbo: bool = False
|
||||||
):
|
):
|
||||||
async with ClientSession(
|
async with ClientSession(
|
||||||
timeout=ClientTimeout(total=900),
|
timeout=ClientTimeout(total=900),
|
||||||
|
|
@ -456,7 +464,7 @@ async def stream_generate(
|
||||||
|
|
||||||
await wss.send_str(format_message({'protocol': 'json', 'version': 1}))
|
await wss.send_str(format_message({'protocol': 'json', 'version': 1}))
|
||||||
await wss.receive(timeout=900)
|
await wss.receive(timeout=900)
|
||||||
await wss.send_str(create_message(conversation, prompt, tone, context, web_search))
|
await wss.send_str(create_message(conversation, prompt, tone, context, web_search, gpt4_turbo))
|
||||||
|
|
||||||
response_txt = ''
|
response_txt = ''
|
||||||
returned_text = ''
|
returned_text = ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue