gpt4free/g4f/models.py

606 lines
14 KiB
Python
Raw Normal View History

2023-10-01 02:27:21 +00:00
from __future__ import annotations
2023-09-17 21:23:54 +00:00
from dataclasses import dataclass
2024-05-19 03:09:55 +00:00
from .Provider import IterListProvider, ProviderType
from .Provider import (
2024-07-09 08:18:26 +00:00
AI365VIP,
Allyfy,
Bing,
Blackbox,
ChatGot,
Chatgpt4o,
Chatgpt4Online,
ChatgptFree,
DDG,
DeepInfra,
DeepInfraImage,
FreeChatgpt,
FreeGpt,
Gemini,
GeminiPro,
GeminiProChat,
GigaChat,
HuggingChat,
HuggingFace,
Koala,
Liaobots,
2024-07-29 18:48:38 +00:00
LiteIcoding,
Marsyoo,
MetaAI,
OpenaiChat,
PerplexityLabs,
Pi,
Pizzagpt,
Reka,
Replicate,
ReplicateHome,
You,
)
2023-09-17 21:23:54 +00:00
@dataclass(unsafe_hash=True)
2023-09-17 21:23:54 +00:00
class Model:
"""
Represents a machine learning model configuration.
Attributes:
name (str): Name of the model.
base_provider (str): Default provider for the model.
best_provider (ProviderType): The preferred provider for the model, typically with retry logic.
"""
2023-09-17 21:23:54 +00:00
name: str
base_provider: str
best_provider: ProviderType = None
2024-04-05 19:00:35 +00:00
2023-10-19 14:14:48 +00:00
@staticmethod
def __all__() -> list[str]:
"""Returns a list of all model names."""
2023-10-19 14:14:48 +00:00
return _all_models
2023-09-17 21:23:54 +00:00
default = Model(
2023-10-01 02:27:21 +00:00
name = "",
base_provider = "",
2024-05-19 03:09:55 +00:00
best_provider = IterListProvider([
Bing,
You,
2024-05-19 03:09:55 +00:00
OpenaiChat,
2024-07-08 20:41:19 +00:00
FreeChatgpt,
AI365VIP,
Chatgpt4o,
DDG,
ChatgptFree,
Koala,
Pizzagpt,
])
)
# GPT-3.5 too, but all providers supports long requests and responses
gpt_35_long = Model(
name = 'gpt-3.5-turbo',
base_provider = 'openai',
2024-05-19 03:09:55 +00:00
best_provider = IterListProvider([
2024-04-05 19:00:35 +00:00
FreeGpt,
You,
2024-05-19 03:09:55 +00:00
Koala,
2024-07-08 20:41:19 +00:00
ChatgptFree,
FreeChatgpt,
DDG,
AI365VIP,
Pizzagpt,
Allyfy,
2023-09-21 18:10:59 +00:00
])
)
2023-09-17 21:23:54 +00:00
2024-07-08 20:41:19 +00:00
############
### Text ###
############
### OpenAI ###
### GPT-3.5 / GPT-4 ###
# gpt-3.5
2023-09-17 21:23:54 +00:00
gpt_35_turbo = Model(
2023-10-01 02:27:21 +00:00
name = 'gpt-3.5-turbo',
base_provider = 'openai',
2024-05-19 03:09:55 +00:00
best_provider = IterListProvider([
FreeGpt,
You,
Koala,
2024-07-08 20:41:19 +00:00
ChatgptFree,
FreeChatgpt,
DDG,
AI365VIP,
Pizzagpt,
Allyfy,
])
2023-09-17 21:23:54 +00:00
)
2024-07-08 20:41:19 +00:00
# gpt-4
2023-09-17 21:23:54 +00:00
gpt_4 = Model(
2023-10-01 02:27:21 +00:00
name = 'gpt-4',
base_provider = 'openai',
2024-05-19 03:09:55 +00:00
best_provider = IterListProvider([
2024-07-27 13:20:20 +00:00
Bing, Chatgpt4Online
2023-10-10 13:11:17 +00:00
])
)
2023-09-17 21:23:54 +00:00
2023-12-21 00:03:28 +00:00
gpt_4_turbo = Model(
name = 'gpt-4-turbo',
base_provider = 'openai',
2024-07-28 10:34:28 +00:00
best_provider = IterListProvider([
2024-07-29 18:48:38 +00:00
Bing, Liaobots, LiteIcoding
2024-07-28 10:34:28 +00:00
])
2023-12-21 00:03:28 +00:00
)
2024-07-08 20:41:19 +00:00
gpt_4o = Model(
name = 'gpt-4o',
base_provider = 'openai',
best_provider = IterListProvider([
2024-07-29 18:48:38 +00:00
You, Liaobots, Chatgpt4o, AI365VIP, OpenaiChat, Marsyoo, LiteIcoding
])
)
gpt_4o_mini = Model(
name = 'gpt-4o-mini',
base_provider = 'openai',
best_provider = IterListProvider([
Liaobots, OpenaiChat, You,
2024-07-08 20:41:19 +00:00
])
)
### GigaChat ###
2024-03-13 22:29:49 +00:00
gigachat = Model(
name = 'GigaChat:latest',
base_provider = 'gigachat',
best_provider = GigaChat
)
2024-07-08 20:41:19 +00:00
### Meta ###
2024-05-19 03:09:55 +00:00
meta = Model(
name = "meta",
2024-02-23 16:21:10 +00:00
base_provider = "meta",
2024-05-19 03:09:55 +00:00
best_provider = MetaAI
)
llama_3_8b_instruct = Model(
2024-04-22 18:02:17 +00:00
name = "meta-llama/Meta-Llama-3-8B-Instruct",
base_provider = "meta",
2024-05-19 03:09:55 +00:00
best_provider = IterListProvider([DeepInfra, PerplexityLabs, Replicate])
)
llama_3_70b_instruct = Model(
2024-04-22 18:02:17 +00:00
name = "meta-llama/Meta-Llama-3-70B-Instruct",
base_provider = "meta",
best_provider = IterListProvider([DeepInfra, PerplexityLabs, Replicate])
)
2024-07-29 18:48:38 +00:00
llama_3_70b_instruct = Model(
name = "meta/meta-llama-3-70b-instruct",
base_provider = "meta",
best_provider = IterListProvider([ReplicateHome])
)
llama_3_70b_chat_hf = Model(
name = "meta-llama/Llama-3-70b-chat-hf",
base_provider = "meta",
best_provider = IterListProvider([DDG])
2024-01-23 04:02:14 +00:00
)
2024-07-29 18:48:38 +00:00
llama_3_1_70b_instruct = Model(
name = "meta-llama/Meta-Llama-3.1-70B-Instruct",
2024-02-23 16:21:10 +00:00
base_provider = "meta",
best_provider = IterListProvider([HuggingChat, HuggingFace])
)
2023-10-26 19:32:49 +00:00
2024-07-29 18:48:38 +00:00
llama_3_1_405b_instruct_FP8 = Model(
name = "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8",
2024-02-23 16:21:10 +00:00
base_provider = "meta",
best_provider = IterListProvider([HuggingChat, HuggingFace])
2024-02-04 18:50:32 +00:00
)
2024-07-08 20:41:19 +00:00
### Mistral ###
2023-12-13 12:15:27 +00:00
mixtral_8x7b = Model(
name = "mistralai/Mixtral-8x7B-Instruct-v0.1",
base_provider = "huggingface",
best_provider = IterListProvider([DeepInfra, HuggingFace, PerplexityLabs, HuggingChat, DDG, ReplicateHome])
2024-04-12 03:18:08 +00:00
)
mistral_7b_v02 = Model(
name = "mistralai/Mistral-7B-Instruct-v0.2",
base_provider = "huggingface",
best_provider = IterListProvider([DeepInfra, HuggingFace, HuggingChat])
2024-07-08 20:41:19 +00:00
)
### NousResearch ###
Nous_Hermes_2_Mixtral_8x7B_DPO = Model(
name = "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
base_provider = "NousResearch",
best_provider = IterListProvider([HuggingFace, HuggingChat])
)
### 01-ai ###
2024-07-29 18:48:38 +00:00
Yi_1_5_34B_chat = Model(
2024-07-08 20:41:19 +00:00
name = "01-ai/Yi-1.5-34B-Chat",
base_provider = "01-ai",
best_provider = IterListProvider([HuggingFace, HuggingChat])
)
### Microsoft ###
Phi_3_mini_4k_instruct = Model(
name = "microsoft/Phi-3-mini-4k-instruct",
base_provider = "Microsoft",
best_provider = IterListProvider([HuggingFace, HuggingChat])
)
2023-12-13 12:15:27 +00:00
2024-07-08 20:41:19 +00:00
### Google ###
# gemini
2024-05-19 03:09:55 +00:00
gemini = Model(
name = 'gemini',
2024-07-08 20:41:19 +00:00
base_provider = 'Google',
best_provider = Gemini
2024-01-23 04:02:14 +00:00
)
2023-09-17 21:23:54 +00:00
2024-07-08 20:41:19 +00:00
gemini_pro = Model(
name = 'gemini-pro',
base_provider = 'Google',
2024-07-29 18:48:38 +00:00
best_provider = IterListProvider([GeminiPro, You, ChatGot, GeminiProChat, Liaobots, LiteIcoding])
)
gemini_flash = Model(
name = 'gemini-flash',
base_provider = 'Google',
best_provider = IterListProvider([Liaobots])
2024-07-08 20:41:19 +00:00
)
2024-07-29 18:48:38 +00:00
gemini_1_5 = Model(
name = 'gemini-1.5',
base_provider = 'Google',
best_provider = IterListProvider([LiteIcoding])
)
2024-07-08 20:41:19 +00:00
# gemma
gemma_2b_it = Model(
name = 'gemma-2b-it',
base_provider = 'Google',
best_provider = IterListProvider([ReplicateHome])
)
2024-07-08 20:41:19 +00:00
gemma_2_9b_it = Model(
name = 'gemma-2-9b-it',
base_provider = 'Google',
best_provider = IterListProvider([PerplexityLabs])
)
gemma_2_27b_it = Model(
name = 'gemma-2-27b-it',
base_provider = 'Google',
best_provider = IterListProvider([PerplexityLabs])
)
### Anthropic ###
claude_2 = Model(
name = 'claude-2',
base_provider = 'Anthropic',
best_provider = IterListProvider([You])
)
claude_2_0 = Model(
name = 'claude-2.0',
base_provider = 'Anthropic',
best_provider = IterListProvider([Liaobots])
)
claude_2_1 = Model(
name = 'claude-2.1',
base_provider = 'Anthropic',
best_provider = IterListProvider([Liaobots])
2024-01-23 04:02:14 +00:00
)
2023-09-17 21:23:54 +00:00
claude_3_opus = Model(
name = 'claude-3-opus',
base_provider = 'Anthropic',
best_provider = IterListProvider([You, Liaobots])
)
claude_3_sonnet = Model(
name = 'claude-3-sonnet',
base_provider = 'Anthropic',
best_provider = IterListProvider([You, Liaobots])
)
claude_3_5_sonnet = Model(
name = 'claude-3-5-sonnet',
base_provider = 'Anthropic',
best_provider = IterListProvider([Liaobots])
)
2024-05-19 03:09:55 +00:00
claude_3_haiku = Model(
name = 'claude-3-haiku',
base_provider = 'Anthropic',
best_provider = IterListProvider([DDG, AI365VIP, Liaobots])
2024-05-19 03:09:55 +00:00
)
2024-07-29 18:48:38 +00:00
claude_3 = Model(
name = 'claude-3',
base_provider = 'Anthropic',
best_provider = IterListProvider([LiteIcoding])
)
claude_3_5 = Model(
name = 'claude-3.5',
base_provider = 'Anthropic',
best_provider = IterListProvider([LiteIcoding])
)
2023-09-20 03:00:19 +00:00
2024-07-08 20:41:19 +00:00
### Reka AI ###
reka_core = Model(
name = 'reka-core',
base_provider = 'Reka AI',
best_provider = Reka
2023-10-10 13:11:17 +00:00
)
2023-09-22 19:36:44 +00:00
2023-09-17 21:23:54 +00:00
2024-07-08 20:41:19 +00:00
### NVIDIA ###
nemotron_4_340b_instruct = Model(
name = 'nemotron-4-340b-instruct',
base_provider = 'NVIDIA',
best_provider = IterListProvider([PerplexityLabs])
2023-10-07 17:10:26 +00:00
)
2024-07-08 20:41:19 +00:00
### Blackbox ###
blackbox = Model(
name = 'blackbox',
base_provider = 'Blackbox',
best_provider = Blackbox
2023-10-07 17:10:26 +00:00
)
2024-07-08 20:41:19 +00:00
### Databricks ###
dbrx_instruct = Model(
name = 'databricks/dbrx-instruct',
base_provider = 'Databricks',
best_provider = IterListProvider([DeepInfra])
2023-10-07 17:10:26 +00:00
)
2023-09-17 21:23:54 +00:00
2024-07-08 20:41:19 +00:00
### CohereForAI ###
command_r_plus = Model(
name = 'CohereForAI/c4ai-command-r-plus',
base_provider = 'CohereForAI',
best_provider = IterListProvider([HuggingChat])
)
2024-07-08 20:41:19 +00:00
### iFlytek ###
SparkDesk_v1_1 = Model(
name = 'SparkDesk-v1.1',
base_provider = 'iFlytek',
best_provider = IterListProvider([FreeChatgpt])
)
### DeepSeek ###
deepseek_coder = Model(
name = 'deepseek-coder',
base_provider = 'DeepSeek',
best_provider = IterListProvider([FreeChatgpt])
)
deepseek_chat = Model(
name = 'deepseek-chat',
base_provider = 'DeepSeek',
best_provider = IterListProvider([FreeChatgpt])
)
### Qwen ###
2024-07-29 18:48:38 +00:00
Qwen2_7B_instruct = Model(
name = 'Qwen2-7B-Instruct',
base_provider = 'Qwen',
best_provider = IterListProvider([FreeChatgpt])
)
### Zhipu AI ###
glm4_9B_chat = Model(
name = 'glm4-9B-chat',
base_provider = 'Zhipu AI',
best_provider = IterListProvider([FreeChatgpt])
)
chatglm3_6B = Model(
name = 'chatglm3-6B',
base_provider = 'Zhipu AI',
best_provider = IterListProvider([FreeChatgpt])
)
### 01-ai ###
2024-07-29 18:48:38 +00:00
Yi_1_5_9B_chat = Model(
name = 'Yi-1.5-9B-Chat',
base_provider = '01-ai',
best_provider = IterListProvider([FreeChatgpt])
)
2024-07-08 20:41:19 +00:00
### Other ###
pi = Model(
name = 'pi',
base_provider = 'inflection',
best_provider = Pi
)
2023-09-17 21:23:54 +00:00
2024-04-13 02:09:11 +00:00
2024-07-08 20:41:19 +00:00
#############
### Image ###
#############
2024-04-13 01:46:20 +00:00
2024-07-08 20:41:19 +00:00
### Stability AI ###
sdxl = Model(
name = 'stability-ai/sdxl',
base_provider = 'Stability AI',
best_provider = IterListProvider([DeepInfraImage])
)
stable_diffusion_3 = Model(
name = 'stability-ai/stable-diffusion-3',
base_provider = 'Stability AI',
best_provider = IterListProvider([ReplicateHome])
)
sdxl_lightning_4step = Model(
name = 'bytedance/sdxl-lightning-4step',
base_provider = 'Stability AI',
best_provider = IterListProvider([ReplicateHome])
2024-07-08 20:41:19 +00:00
)
playground_v2_5_1024px_aesthetic = Model(
name = 'playgroundai/playground-v2.5-1024px-aesthetic',
base_provider = 'Stability AI',
2024-07-08 20:41:19 +00:00
best_provider = IterListProvider([ReplicateHome])
2024-04-24 23:06:11 +00:00
)
2023-09-17 21:23:54 +00:00
class ModelUtils:
"""
Utility class for mapping string identifiers to Model instances.
Attributes:
convert (dict[str, Model]): Dictionary mapping model string identifiers to Model instances.
"""
2023-09-17 21:23:54 +00:00
convert: dict[str, Model] = {
2024-07-08 20:41:19 +00:00
############
### Text ###
############
### OpenAI ###
### GPT-3.5 / GPT-4 ###
# gpt-3.5
'gpt-3.5-turbo': gpt_35_turbo,
'gpt-3.5-long': gpt_35_long,
# gpt-4
'gpt-4o' : gpt_4o,
'gpt-4o-mini' : gpt_4o_mini,
'gpt-4' : gpt_4,
'gpt-4-turbo' : gpt_4_turbo,
2024-07-08 20:41:19 +00:00
### Meta ###
"meta-ai": meta,
2024-07-08 20:41:19 +00:00
2024-07-29 18:48:38 +00:00
'llama-3-8b-instruct': llama_3_8b_instruct,
'llama-3-70b-instruct': llama_3_70b_instruct,
'llama-3-70b-chat': llama_3_70b_chat_hf,
2024-07-29 18:48:38 +00:00
'llama-3-70b-instruct': llama_3_70b_instruct,
'llama-3.1-70b-instruct': llama_3_1_70b_instruct,
'llama-3.1-405b-instruct': llama_3_1_405b_instruct_FP8,
2024-07-08 20:41:19 +00:00
### Mistral (Opensource) ###
'mixtral-8x7b': mixtral_8x7b,
'mistral-7b-v02': mistral_7b_v02,
2024-07-08 20:41:19 +00:00
### NousResearch ###
'Nous-Hermes-2-Mixtral-8x7B-DPO': Nous_Hermes_2_Mixtral_8x7B_DPO,
2024-07-08 20:41:19 +00:00
### 01-ai ###
2024-07-29 18:48:38 +00:00
'Yi-1.5-34b-chat': Yi_1_5_34B_chat,
### Microsoft ###
2024-07-29 18:48:38 +00:00
'Phi-3-mini-4k-instruct': Phi_3_mini_4k_instruct,
### Google ###
# gemini
'gemini': gemini,
'gemini-pro': gemini_pro,
2024-07-29 18:48:38 +00:00
'gemini-pro': gemini_1_5,
'gemini-flash': gemini_flash,
# gemma
'gemma-2b': gemma_2b_it,
'gemma-2-9b': gemma_2_9b_it,
'gemma-2-27b': gemma_2_27b_it,
### Anthropic ###
'claude-2': claude_2,
'claude-2.0': claude_2_0,
'claude-2.1': claude_2_1,
2024-07-29 18:48:38 +00:00
'claude-3-opus': claude_3_opus,
'claude-3-sonnet': claude_3_sonnet,
'claude-3-5-sonnet': claude_3_5_sonnet,
'claude-3-haiku': claude_3_haiku,
2024-07-29 18:48:38 +00:00
'claude-3-opus': claude_3,
'claude-3-5-sonnet': claude_3_5,
### Reka AI ###
'reka': reka_core,
### NVIDIA ###
2024-07-29 18:48:38 +00:00
'nemotron-4-340b-instruct': nemotron_4_340b_instruct,
### Blackbox ###
'blackbox': blackbox,
### CohereForAI ###
'command-r+': command_r_plus,
### Databricks ###
'dbrx-instruct': dbrx_instruct,
### GigaChat ###
'gigachat': gigachat,
### iFlytek ###
'SparkDesk-v1.1': SparkDesk_v1_1,
### DeepSeek ###
'deepseek-coder': deepseek_coder,
'deepseek-chat': deepseek_chat,
### Qwen ###
2024-07-29 18:48:38 +00:00
'Qwen2-7b-instruct': Qwen2_7B_instruct,
### Zhipu AI ###
2024-07-29 18:48:38 +00:00
'glm4-9b-chat': glm4_9B_chat,
'chatglm3-6b': chatglm3_6B,
2024-07-08 20:41:19 +00:00
### 01-ai ###
2024-07-29 18:48:38 +00:00
'Yi-1.5-9b-chat': Yi_1_5_9B_chat,
2024-07-08 20:41:19 +00:00
# Other
'pi': pi,
2024-07-08 20:41:19 +00:00
#############
### Image ###
#############
### Stability AI ###
'sdxl': sdxl,
'stable-diffusion-3': stable_diffusion_3,
2024-07-08 20:41:19 +00:00
### ByteDance ###
'sdxl-lightning': sdxl_lightning_4step,
### Playground ###
'playground-v2.5': playground_v2_5_1024px_aesthetic,
2023-10-01 02:27:21 +00:00
}
2023-10-19 14:14:48 +00:00
2024-02-04 18:50:32 +00:00
_all_models = list(ModelUtils.convert.keys())