XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update Bing.py

5d47ba42
nullstreak <139914347+nullstreak@users.noreply.github.com>
提交于

代码差异

1 个文件 +12 -4
Modified g4f/Provider/Bing.py +12 -4
@@ -60,7 +60,10 @@ class Bing(AsyncGeneratorProvider):
60 60 for key, value in default_cookies.items():
61 61 if key not in cookies:
62 62 cookies[key] = value
63 return stream_generate(prompt, tone, image, context, proxy, cookies, web_search)
63
64 gpt4_turbo = True if model.startswith("gpt-4-turbo") else False
65
66 return stream_generate(prompt, tone, image, context, proxy, cookies, web_search, gpt4_turbo)
64 67
65 68 def create_context(messages: Messages):
66 69 return "".join(
@@ -377,7 +380,7 @@ def compress_image_to_base64(img, compression_rate) -> str:
377 380 except Exception as e:
378 381 raise e
379 382
380 def create_message(conversation: Conversation, prompt: str, tone: str, context: str = None, web_search: bool = False) -> str:
383 def create_message(conversation: Conversation, prompt: str, tone: str, context: str = None, web_search: bool = False, gpt4_turbo: bool = False) -> str:
381 384 options_sets = Defaults.optionsSets
382 385 if tone == Tones.creative:
383 386 options_sets.append("h3imaginative")
@@ -387,8 +390,12 @@ def create_message(conversation: Conversation, prompt: str, tone: str, context:
387 390 options_sets.append("galileo")
388 391 else:
389 392 options_sets.append("harmonyv3")
393
390 394 if not web_search:
391 395 options_sets.append("nosearchall")
396
397 if gpt4_turbo:
398 options_sets.append("dlgpt4t")
392 399
393 400 request_id = str(uuid.uuid4())
394 401 struct = {
@@ -444,7 +451,8 @@ async def stream_generate(
444 451 context: str = None,
445 452 proxy: str = None,
446 453 cookies: dict = None,
447 web_search: bool = False
454 web_search: bool = False,
455 gpt4_turbo: bool = False
448 456 ):
449 457 async with ClientSession(
450 458 timeout=ClientTimeout(total=900),
@@ -456,7 +464,7 @@ async def stream_generate(
456 464
457 465 await wss.send_str(format_message({'protocol': 'json', 'version': 1}))
458 466 await wss.receive(timeout=900)
459 await wss.send_str(create_message(conversation, prompt, tone, context, web_search))
467 await wss.send_str(create_message(conversation, prompt, tone, context, web_search, gpt4_turbo))
460 468
461 469 response_txt = ''
462 470 returned_text = ''