Merge pull request #610 from ggindinson/main

Added support for AiColors
This commit is contained in:
xtekky 2023-05-28 01:39:03 +01:00 committed by GitHub
commit 1c227b8ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 14 deletions

View File

@ -5,18 +5,20 @@ from gpt4free import quora
from gpt4free import theb from gpt4free import theb
from gpt4free import usesless from gpt4free import usesless
from gpt4free import you from gpt4free import you
from gpt4free import aicolors
from gpt4free import deepai from gpt4free import deepai
class Provider(Enum): class Provider(Enum):
"""An enum representing different providers.""" """An enum representing different providers."""
You = 'you' You = "you"
Poe = 'poe' Poe = "poe"
ForeFront = 'fore_front' ForeFront = "fore_front"
Theb = 'theb' Theb = "theb"
UseLess = 'useless' UseLess = "useless"
DeepAI = 'deepai' AiColors = "ai_colors"
DeepAI = "deepai"
class Completion: class Completion:
@ -42,10 +44,16 @@ class Completion:
return Completion.__theb_service(prompt, **kwargs) return Completion.__theb_service(prompt, **kwargs)
elif provider == Provider.UseLess: elif provider == Provider.UseLess:
return Completion.__useless_service(prompt, **kwargs) return Completion.__useless_service(prompt, **kwargs)
elif provider == Provider.AiColors:
return Completion.__ai_colors_service(prompt, **kwargs)
elif provider == Provider.DeepAI: elif provider == Provider.DeepAI:
return Completion.__deepai_service(prompt, **kwargs) return Completion.__deepai_service(prompt, **kwargs)
else: 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 @staticmethod
def __useless_service(prompt: str, **kwargs) -> str: def __useless_service(prompt: str, **kwargs) -> str:
@ -65,11 +73,12 @@ class Completion:
@staticmethod @staticmethod
def __theb_service(prompt: str, **kwargs): def __theb_service(prompt: str, **kwargs):
return ''.join(theb.Completion.create(prompt=prompt)) return "".join(theb.Completion.create(prompt=prompt))
@staticmethod @staticmethod
def __deepai_service(prompt: str, **kwargs): def __deepai_service(prompt: str, **kwargs):
return ''.join(deepai.Completion.create(prompt=prompt)) return "".join(deepai.Completion.create(prompt=prompt))
class ChatCompletion: class ChatCompletion:
"""This class is used to execute a chat completion for a specified provider""" """This class is used to execute a chat completion for a specified provider"""
@ -87,8 +96,8 @@ class ChatCompletion:
if provider == Provider.DeepAI: if provider == Provider.DeepAI:
return ChatCompletion.__deepai_service(messages, **kwargs) return ChatCompletion.__deepai_service(messages, **kwargs)
else: else:
raise Exception('Provider not exist, Please try again') raise Exception("Provider not exist, Please try again")
@staticmethod @staticmethod
def __deepai_service(messages: list, **kwargs): def __deepai_service(messages: list, **kwargs):
return ''.join(deepai.ChatCompletion.create(messages=messages)) return "".join(deepai.ChatCompletion.create(messages=messages))

View File

@ -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)

View File

@ -0,0 +1,9 @@
from dataclasses import dataclass
@dataclass
class AiColorsResponse:
background: str
primary: str
accent: str
text: str

View File

@ -16,4 +16,4 @@ Levenshtein
retrying retrying
mailgw_temporary_email mailgw_temporary_email
pycryptodome pycryptodome
random-password-generator random-password-generator

6
testing/aicolors_test.py Normal file
View File

@ -0,0 +1,6 @@
from gpt4free import aicolors
prompt = "Light green color"
req = aicolors.Completion.create(prompt=prompt)
print(req)