diff options
author | xtekky <98614666+xtekky@users.noreply.github.com> | 2023-05-28 02:39:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-28 02:39:03 +0200 |
commit | 1c227b8ea03752f7b393ac01950d4182784c878d (patch) | |
tree | b900cd12fd92d0335f80e8a4f6c769b7aea03024 | |
parent | Update requirements.txt (diff) | |
parent | Merge branch 'main' into main (diff) | |
download | gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.tar gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.tar.gz gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.tar.bz2 gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.tar.lz gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.tar.xz gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.tar.zst gpt4free-1c227b8ea03752f7b393ac01950d4182784c878d.zip |
Diffstat (limited to '')
-rw-r--r-- | gpt4free/__init__.py | 35 | ||||
-rw-r--r-- | gpt4free/aicolors/__init__.py | 30 | ||||
-rw-r--r-- | gpt4free/aicolors/typings/__init__.py | 9 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | testing/aicolors_test.py | 6 |
5 files changed, 68 insertions, 14 deletions
diff --git a/gpt4free/__init__.py b/gpt4free/__init__.py index 2dc6f5f3..bcc03a3b 100644 --- a/gpt4free/__init__.py +++ b/gpt4free/__init__.py @@ -5,18 +5,20 @@ from gpt4free import quora from gpt4free import theb from gpt4free import usesless from gpt4free import you +from gpt4free import aicolors from gpt4free import deepai class Provider(Enum): """An enum representing different providers.""" - You = 'you' - Poe = 'poe' - ForeFront = 'fore_front' - Theb = 'theb' - UseLess = 'useless' - DeepAI = 'deepai' + You = "you" + Poe = "poe" + ForeFront = "fore_front" + Theb = "theb" + UseLess = "useless" + AiColors = "ai_colors" + DeepAI = "deepai" class Completion: @@ -42,10 +44,16 @@ class Completion: return Completion.__theb_service(prompt, **kwargs) elif provider == Provider.UseLess: return Completion.__useless_service(prompt, **kwargs) + elif provider == Provider.AiColors: + return Completion.__ai_colors_service(prompt, **kwargs) elif provider == Provider.DeepAI: return Completion.__deepai_service(prompt, **kwargs) else: - raise Exception('Provider not exist, Please try again') + raise Exception("Provider not exist, Please try again") + + @staticmethod + def __ai_colors_service(prompt: str): + return aicolors.Completion.create(prompt=prompt) @staticmethod def __useless_service(prompt: str, **kwargs) -> str: @@ -65,11 +73,12 @@ class Completion: @staticmethod def __theb_service(prompt: str, **kwargs): - return ''.join(theb.Completion.create(prompt=prompt)) - + return "".join(theb.Completion.create(prompt=prompt)) + @staticmethod def __deepai_service(prompt: str, **kwargs): - return ''.join(deepai.Completion.create(prompt=prompt)) + return "".join(deepai.Completion.create(prompt=prompt)) + class ChatCompletion: """This class is used to execute a chat completion for a specified provider""" @@ -87,8 +96,8 @@ class ChatCompletion: if provider == Provider.DeepAI: return ChatCompletion.__deepai_service(messages, **kwargs) else: - raise Exception('Provider not exist, Please try again') - + raise Exception("Provider not exist, Please try again") + @staticmethod def __deepai_service(messages: list, **kwargs): - return ''.join(deepai.ChatCompletion.create(messages=messages))
\ No newline at end of file + return "".join(deepai.ChatCompletion.create(messages=messages)) diff --git a/gpt4free/aicolors/__init__.py b/gpt4free/aicolors/__init__.py new file mode 100644 index 00000000..f3afa265 --- /dev/null +++ b/gpt4free/aicolors/__init__.py @@ -0,0 +1,30 @@ +import fake_useragent +import requests +import json +from typings import AiColorsResponse + + +class Completion: + @staticmethod + def create( + query: str = "", + ) -> AiColorsResponse: + headers = { + "authority": "jsuifmbqefnxytqwmaoy.functions.supabase.co", + "accept": "*/*", + "accept-language": "en-US,en;q=0.5", + "cache-control": "no-cache", + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "user-agent": fake_useragent.UserAgent().random, + } + + json_data = {"query": query} + + url = "https://jsuifmbqefnxytqwmaoy.functions.supabase.co/chatgpt" + request = requests.post(url, headers=headers, json=json_data, timeout=30) + data = request.json().get("text").get("content") + json_data = json.loads(data.replace("\n ", "")) + + return AiColorsResponse(**json_data) diff --git a/gpt4free/aicolors/typings/__init__.py b/gpt4free/aicolors/typings/__init__.py new file mode 100644 index 00000000..8c4f29d1 --- /dev/null +++ b/gpt4free/aicolors/typings/__init__.py @@ -0,0 +1,9 @@ +from dataclasses import dataclass + + +@dataclass +class AiColorsResponse: + background: str + primary: str + accent: str + text: str diff --git a/requirements.txt b/requirements.txt index 0bcc4425..9f12b362 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,4 @@ Levenshtein retrying mailgw_temporary_email pycryptodome -random-password-generator +random-password-generator
\ No newline at end of file diff --git a/testing/aicolors_test.py b/testing/aicolors_test.py new file mode 100644 index 00000000..853f7e45 --- /dev/null +++ b/testing/aicolors_test.py @@ -0,0 +1,6 @@ +from gpt4free import aicolors + +prompt = "Light green color" +req = aicolors.Completion.create(prompt=prompt) + +print(req) |