mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-05 00:01:00 +00:00
Merge pull request #610 from ggindinson/main
Added support for AiColors
This commit is contained in:
commit
1c227b8ea0
@ -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))
|
||||
return "".join(deepai.ChatCompletion.create(messages=messages))
|
||||
|
30
gpt4free/aicolors/__init__.py
Normal file
30
gpt4free/aicolors/__init__.py
Normal 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)
|
9
gpt4free/aicolors/typings/__init__.py
Normal file
9
gpt4free/aicolors/typings/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class AiColorsResponse:
|
||||
background: str
|
||||
primary: str
|
||||
accent: str
|
||||
text: str
|
6
testing/aicolors_test.py
Normal file
6
testing/aicolors_test.py
Normal file
@ -0,0 +1,6 @@
|
||||
from gpt4free import aicolors
|
||||
|
||||
prompt = "Light green color"
|
||||
req = aicolors.Completion.create(prompt=prompt)
|
||||
|
||||
print(req)
|
Loading…
Reference in New Issue
Block a user