From 98d3304108de3e55c18f2af8a66a501541ec658b Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 22 Aug 2023 23:27:34 +0200 Subject: Improve providers with tests --- g4f/Provider/V50.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'g4f/Provider/V50.py') diff --git a/g4f/Provider/V50.py b/g4f/Provider/V50.py index 125dd7c5..765f73bd 100644 --- a/g4f/Provider/V50.py +++ b/g4f/Provider/V50.py @@ -8,7 +8,7 @@ class V50(BaseProvider): supports_gpt_35_turbo = True supports_stream = False needs_auth = False - working = True + working = False @staticmethod def create_completion( @@ -46,7 +46,8 @@ class V50(BaseProvider): } response = requests.post("https://p5.v50.ltd/api/chat-process", json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {}) - yield response.text + if "https://fk1.v50.ltd" not in response.text: + yield response.text @classmethod @property -- cgit v1.2.3 From efd75a11b871d61ac31b0e274acdfb33daba361d Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:37:44 +0200 Subject: ~ | code styling --- g4f/Provider/V50.py | 55 +++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'g4f/Provider/V50.py') diff --git a/g4f/Provider/V50.py b/g4f/Provider/V50.py index 765f73bd..1dc7651d 100644 --- a/g4f/Provider/V50.py +++ b/g4f/Provider/V50.py @@ -1,51 +1,52 @@ import uuid, requests -from ..typing import Any, CreateResult -from .base_provider import BaseProvider +from ..typing import Any, CreateResult +from .base_provider import BaseProvider class V50(BaseProvider): - url = 'https://p5.v50.ltd' - supports_gpt_35_turbo = True - supports_stream = False - needs_auth = False - working = False + url = 'https://p5.v50.ltd' + supports_gpt_35_turbo = True + supports_stream = False + needs_auth = False + working = False @staticmethod def create_completion( model: str, messages: list[dict[str, str]], - stream: bool, - **kwargs: Any, - ) -> CreateResult: + stream: bool, **kwargs: Any) -> CreateResult: + conversation = '' for message in messages: conversation += '%s: %s\n' % (message['role'], message['content']) conversation += 'assistant: ' payload = { - "prompt": conversation, - "options": {}, - "systemMessage": ".", - "temperature": kwargs.get("temperature", 0.4), - "top_p": kwargs.get("top_p", 0.4), - "model": model, - "user": str(uuid.uuid4()) + "prompt" : conversation, + "options" : {}, + "systemMessage" : ".", + "temperature" : kwargs.get("temperature", 0.4), + "top_p" : kwargs.get("top_p", 0.4), + "model" : model, + "user" : str(uuid.uuid4()) } + headers = { - 'authority': 'p5.v50.ltd', - 'accept': 'application/json, text/plain, */*', - 'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7', - 'content-type': 'application/json', - 'origin': 'https://p5.v50.ltd', - 'referer': 'https://p5.v50.ltd/', + 'authority' : 'p5.v50.ltd', + 'accept' : 'application/json, text/plain, */*', + 'accept-language' : 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7', + 'content-type' : 'application/json', + 'origin' : 'https://p5.v50.ltd', + 'referer' : 'https://p5.v50.ltd/', 'sec-ch-ua-platform': '"Windows"', - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36' + 'sec-fetch-dest' : 'empty', + 'sec-fetch-mode' : 'cors', + 'sec-fetch-site' : 'same-origin', + 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36' } response = requests.post("https://p5.v50.ltd/api/chat-process", json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {}) + if "https://fk1.v50.ltd" not in response.text: yield response.text -- cgit v1.2.3 From 901595b10f08972ee3ac5fc08c346dbb561a7d62 Mon Sep 17 00:00:00 2001 From: msi-JunXiang Date: Sun, 3 Sep 2023 16:26:26 +0800 Subject: type hints Use `from __future__ import annotations avoid `dict` and `list` cause "TypeErro: 'type' object is not subscriptable". Refer to the following Stack Overflow discussions for more information: 1. https://stackoverflow.com/questions/75202610/typeerror-type-object-is-not-subscriptable-python 2. https://stackoverflow.com/questions/59101121/type-hint-for-a-dict-gives-typeerror-type-object-is-not-subscriptable --- g4f/Provider/V50.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'g4f/Provider/V50.py') diff --git a/g4f/Provider/V50.py b/g4f/Provider/V50.py index 1dc7651d..4e02d4b7 100644 --- a/g4f/Provider/V50.py +++ b/g4f/Provider/V50.py @@ -1,8 +1,13 @@ -import uuid, requests +from __future__ import annotations -from ..typing import Any, CreateResult +import uuid + +import requests + +from ..typing import Any, CreateResult from .base_provider import BaseProvider + class V50(BaseProvider): url = 'https://p5.v50.ltd' supports_gpt_35_turbo = True -- cgit v1.2.3 From 17c9adf4852a0ca0d1a5cfa448478fa195a9c368 Mon Sep 17 00:00:00 2001 From: hs_junxiang Date: Mon, 4 Sep 2023 13:34:31 +0800 Subject: Join the messages A better approach is to use the `.join()` method of strings, which reduces string concatenation operations and improves performance. Additionally, using formatted strings (f-strings) makes the code cleaner and more readable. --- g4f/Provider/V50.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'g4f/Provider/V50.py') diff --git a/g4f/Provider/V50.py b/g4f/Provider/V50.py index 1dc7651d..ad3fd9e4 100644 --- a/g4f/Provider/V50.py +++ b/g4f/Provider/V50.py @@ -16,11 +16,9 @@ class V50(BaseProvider): messages: list[dict[str, str]], stream: bool, **kwargs: Any) -> CreateResult: - conversation = '' - for message in messages: - conversation += '%s: %s\n' % (message['role'], message['content']) - - conversation += 'assistant: ' + conversation = "\n".join(f"{message['role']}: {message['content']}" for message in messages) + conversation += "\nassistant: " + payload = { "prompt" : conversation, "options" : {}, -- cgit v1.2.3