diff options
-rw-r--r-- | g4f/Provider/Bing.py | 21 | ||||
-rw-r--r-- | g4f/Provider/FakeGpt.py | 2 | ||||
-rw-r--r-- | g4f/debug.py | 4 | ||||
-rw-r--r-- | g4f/gui/server/backend.py | 2 |
4 files changed, 19 insertions, 10 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py index af6c5132..f1255553 100644 --- a/g4f/Provider/Bing.py +++ b/g4f/Provider/Bing.py @@ -10,6 +10,7 @@ import base64 import numpy as np import uuid import urllib.parse +import time from PIL import Image from aiohttp import ClientSession, ClientTimeout from ..typing import AsyncResult, Messages @@ -26,7 +27,7 @@ default_cookies = { 'KievRPSSecAuth': '', 'SUID' : '', 'SRCHUSR' : '', - 'SRCHHPGUSR' : '', + 'SRCHHPGUSR' : f'HV={int(time.time())}', } class Bing(AsyncGeneratorProvider): @@ -43,6 +44,7 @@ class Bing(AsyncGeneratorProvider): cookies: dict = None, tone: str = Tones.creative, image: str = None, + web_search: bool = False, **kwargs ) -> AsyncResult: if len(messages) < 2: @@ -52,9 +54,13 @@ class Bing(AsyncGeneratorProvider): prompt = messages[-1]["content"] context = create_context(messages[:-1]) - if not cookies or "SRCHD" not in cookies: + if not cookies: cookies = default_cookies - return stream_generate(prompt, tone, image, context, proxy, cookies) + else: + for key, value in default_cookies.items(): + if key not in cookies: + cookies[key] = value + return stream_generate(prompt, tone, image, context, proxy, cookies, web_search) def create_context(messages: Messages): return "".join( @@ -371,7 +377,7 @@ def compress_image_to_base64(img, compression_rate) -> str: except Exception as e: raise e -def create_message(conversation: Conversation, prompt: str, tone: str, context: str=None) -> str: +def create_message(conversation: Conversation, prompt: str, tone: str, context: str = None, web_search: bool = False) -> str: options_sets = Defaults.optionsSets if tone == Tones.creative: options_sets.append("h3imaginative") @@ -381,6 +387,8 @@ def create_message(conversation: Conversation, prompt: str, tone: str, context: options_sets.append("galileo") else: options_sets.append("harmonyv3") + if not web_search: + options_sets.append("nosearchall") request_id = str(uuid.uuid4()) struct = { @@ -435,7 +443,8 @@ async def stream_generate( image: str = None, context: str = None, proxy: str = None, - cookies: dict = None + cookies: dict = None, + web_search: bool = False ): async with ClientSession( timeout=ClientTimeout(total=900), @@ -447,7 +456,7 @@ async def stream_generate( await wss.send_str(format_message({'protocol': 'json', 'version': 1})) await wss.receive(timeout=900) - await wss.send_str(create_message(conversation, prompt, tone, context)) + await wss.send_str(create_message(conversation, prompt, tone, context, web_search)) response_txt = '' returned_text = '' diff --git a/g4f/Provider/FakeGpt.py b/g4f/Provider/FakeGpt.py index 2720845f..a88f3682 100644 --- a/g4f/Provider/FakeGpt.py +++ b/g4f/Provider/FakeGpt.py @@ -36,7 +36,7 @@ class FakeGpt(AsyncGeneratorProvider): async with session.get(f"{cls.url}/api/loads", params={"t": int(time.time())}, proxy=proxy) as response: response.raise_for_status() list = (await response.json())["loads"] - token_ids = [t["token_id"] for t in list if t["count"] == 0] + token_ids = [t["token_id"] for t in list] data = { "token_key": random.choice(token_ids), "session_password": get_random_string() diff --git a/g4f/debug.py b/g4f/debug.py index 1ee1506f..67664e5b 100644 --- a/g4f/debug.py +++ b/g4f/debug.py @@ -25,14 +25,14 @@ def get_version() -> str: pass raise VersionNotFoundError("Version not found") -def get_lastet_version() -> str: +def get_latest_version() -> str: response = get("https://pypi.org/pypi/g4f/json").json() return response["info"]["version"] def check_pypi_version() -> None: try: version = get_version() - latest_version = get_lastet_version() + latest_version = get_latest_version() if version != latest_version: print(f'New pypi version: {latest_version} (current: {version}) | pip install -U g4f') except Exception as e: diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py index e4669699..105edb43 100644 --- a/g4f/gui/server/backend.py +++ b/g4f/gui/server/backend.py @@ -54,7 +54,7 @@ class Backend_Api: def version(self): return { "version": debug.get_version(), - "lastet_version": debug.get_lastet_version(), + "lastet_version": debug.get_latest_version(), } def _gen_title(self): |