gpt4free/g4f/models.py

648 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,
2024-07-08 20:41:19 +00:00
Bing,
Blackbox,
ChatGot,
2024-07-08 20:41:19 +00:00
Chatgpt4o,
Chatgpt4Online,
2024-07-08 20:41:19 +00:00
ChatgptFree,
DDG,
DeepInfra,
DeepInfraImage,
FreeChatgpt,
FreeGpt,
Gemini,
GeminiPro,
GeminiProChat,
GigaChat,
HuggingChat,
HuggingFace,
Koala,
Liaobots,
MetaAI,
OpenaiChat,
PerplexityLabs,
Pi,
Pizzagpt,
Reka,
Replicate,
ReplicateHome,
Vercel,
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_35_turbo_16k = Model(
name = 'gpt-3.5-turbo-16k',
base_provider = 'openai',
best_provider = gpt_35_long.best_provider
)
gpt_35_turbo_16k_0613 = Model(
name = 'gpt-3.5-turbo-16k-0613',
base_provider = 'openai',
best_provider = gpt_35_long.best_provider
)
gpt_35_turbo_0613 = Model(
name = 'gpt-3.5-turbo-0613',
base_provider = 'openai',
best_provider = gpt_35_turbo.best_provider
)
# 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([
Bing, Liaobots, Chatgpt4Online
2023-10-10 13:11:17 +00:00
])
)
2023-09-17 21:23:54 +00:00
2024-07-08 20:41:19 +00:00
gpt_4_0613 = Model(
name = 'gpt-4-0613',
2024-05-14 22:45:13 +00:00
base_provider = 'openai',
2024-07-08 20:41:19 +00:00
best_provider = gpt_4.best_provider
)
gpt_4_32k = Model(
name = 'gpt-4-32k',
base_provider = 'openai',
best_provider = gpt_4.best_provider
)
gpt_4_32k_0613 = Model(
name = 'gpt-4-32k-0613',
base_provider = 'openai',
best_provider = gpt_4.best_provider
2024-05-14 22:45:13 +00:00
)
2023-12-21 00:03:28 +00:00
gpt_4_turbo = Model(
name = 'gpt-4-turbo',
base_provider = 'openai',
best_provider = Bing
)
2024-07-08 20:41:19 +00:00
gpt_4o = Model(
name = 'gpt-4o',
base_provider = 'openai',
best_provider = IterListProvider([
You, Liaobots, Chatgpt4o, AI365VIP, OpenaiChat
])
)
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
)
llama3_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])
)
llama3_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, DDG, ReplicateHome])
)
llama_3_1_70b_Instruct = Model(
name = "meta-llama/Meta-Llama-3.1-70B-Instruct",
base_provider = "meta",
best_provider = IterListProvider([HuggingChat, HuggingFace])
)
llama_3_1_405b_Instruct_FP8 = Model(
name = "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8",
base_provider = "meta",
best_provider = IterListProvider([HuggingChat, HuggingFace])
2024-01-23 04:02:14 +00:00
)
codellama_34b_instruct = Model(
name = "codellama/CodeLlama-34b-Instruct-hf",
2024-02-23 16:21:10 +00:00
base_provider = "meta",
2024-04-12 03:18:08 +00:00
best_provider = HuggingChat
)
2023-10-26 19:32:49 +00:00
2024-02-04 18:50:32 +00:00
codellama_70b_instruct = Model(
name = "codellama/CodeLlama-70b-Instruct-hf",
2024-02-23 16:21:10 +00:00
base_provider = "meta",
2024-07-08 20:41:19 +00:00
best_provider = IterListProvider([DeepInfra])
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 ###
Yi_1_5_34B_Chat = Model(
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',
best_provider = IterListProvider([GeminiPro, You, ChatGot, GeminiProChat, Liaobots])
)
gemini_flash = Model(
name = 'gemini-flash',
base_provider = 'Google',
best_provider = IterListProvider([Liaobots])
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
)
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 ###
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 ###
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 ###
############
2024-07-08 20:41:19 +00:00
### OpenAI ###
### GPT-3.5 / GPT-4 ###
2023-10-01 02:27:21 +00:00
# gpt-3.5
'gpt-3.5-turbo' : gpt_35_turbo,
2023-10-06 18:53:17 +00:00
'gpt-3.5-turbo-0613' : gpt_35_turbo_0613,
2023-10-01 02:27:21 +00:00
'gpt-3.5-turbo-16k' : gpt_35_turbo_16k,
'gpt-3.5-turbo-16k-0613' : gpt_35_turbo_16k_0613,
2023-12-06 10:54:50 +00:00
'gpt-3.5-long': gpt_35_long,
2024-05-19 03:09:55 +00:00
2023-10-01 02:27:21 +00:00
# gpt-4
2024-05-14 22:45:13 +00:00
'gpt-4o' : gpt_4o,
'gpt-4o-mini' : gpt_4o_mini,
2023-10-01 02:27:21 +00:00
'gpt-4' : gpt_4,
'gpt-4-0613' : gpt_4_0613,
'gpt-4-32k' : gpt_4_32k,
'gpt-4-32k-0613' : gpt_4_32k_0613,
2023-12-21 00:03:28 +00:00
'gpt-4-turbo' : gpt_4_turbo,
2024-07-08 20:41:19 +00:00
### Meta ###
2024-05-19 03:09:55 +00:00
"meta-ai": meta,
2024-07-08 20:41:19 +00:00
2024-05-19 03:09:55 +00:00
'llama3-8b': llama3_8b_instruct, # alias
2024-04-24 23:06:11 +00:00
'llama3-70b': llama3_70b_instruct, # alias
'llama3-8b-instruct' : llama3_8b_instruct,
'llama3-70b-instruct': llama3_70b_instruct,
'llama-3.1-70b-Instruct': llama_3_1_70b_Instruct,
'llama-3.1-405B-Instruct-FP8': llama_3_1_405b_Instruct_FP8,
2024-05-19 03:09:55 +00:00
2024-01-23 04:02:14 +00:00
'codellama-34b-instruct': codellama_34b_instruct,
2024-02-04 18:50:32 +00:00
'codellama-70b-instruct': codellama_70b_instruct,
2024-03-13 22:29:49 +00:00
2024-07-08 20:41:19 +00:00
### Mistral (Opensource) ###
2023-12-13 12:15:27 +00:00
'mixtral-8x7b': mixtral_8x7b,
2024-04-12 03:18:08 +00:00
'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-05-19 03:09:55 +00:00
2024-07-08 20:41:19 +00:00
### 01-ai ###
'Yi-1.5-34B-Chat': Yi_1_5_34B_Chat,
2024-07-08 20:41:19 +00:00
### Microsoft ###
'Phi-3-mini-4k-instruct': Phi_3_mini_4k_instruct,
2024-07-08 20:41:19 +00:00
### Google ###
# gemini
'gemini': gemini,
'gemini-pro': gemini_pro,
'gemini-flash': gemini_flash,
2024-07-08 20:41:19 +00:00
# gemma
'gemma-2b-it': gemma_2b_it,
2024-07-08 20:41:19 +00:00
'gemma-2-9b-it': gemma_2_9b_it,
'gemma-2-27b-it': gemma_2_27b_it,
2024-05-19 03:09:55 +00:00
2024-07-08 20:41:19 +00:00
### Anthropic ###
'claude-2': claude_2,
'claude-2.0': claude_2_0,
'claude-2.1': claude_2_1,
'claude-3-opus': claude_3_opus,
'claude-3-sonnet': claude_3_sonnet,
'claude-3-5-sonnet': claude_3_5_sonnet,
2024-05-19 03:09:55 +00:00
'claude-3-haiku': claude_3_haiku,
2024-07-08 20:41:19 +00:00
### Reka AI ###
2024-04-24 23:06:11 +00:00
'reka': reka_core,
2024-05-19 03:09:55 +00:00
2024-07-08 20:41:19 +00:00
### NVIDIA ###
'nemotron-4-340b-instruct': nemotron_4_340b_instruct,
### Blackbox ###
'blackbox': blackbox,
2024-07-08 20:41:19 +00:00
### CohereForAI ###
2024-04-13 02:09:11 +00:00
'command-r+': command_r_plus,
2024-07-08 20:41:19 +00:00
### Databricks ###
2024-04-13 01:46:20 +00:00
'dbrx-instruct': dbrx_instruct,
2024-07-08 20:41:19 +00:00
### GigaChat ###
2024-05-19 03:09:55 +00:00
'gigachat': gigachat,
2024-07-08 20:41:19 +00:00
### iFlytek ###
'SparkDesk-v1.1': SparkDesk_v1_1,
### DeepSeek ###
'deepseek-coder': deepseek_coder,
'deepseek-chat': deepseek_chat,
### ### Qwen ### ###
'Qwen2-7B-Instruct': Qwen2_7B_Instruct,
### Zhipu AI ###
'glm4-9B-chat': glm4_9B_chat,
'chatglm3-6B': chatglm3_6B,
### 01-ai ###
'Yi-1.5-9B-Chat': Yi_1_5_9B_Chat,
2024-07-08 20:41:19 +00:00
# Other
'pi': pi,
#############
### Image ###
#############
2024-07-08 20:41:19 +00:00
### Stability AI ###
2024-07-08 20:41:19 +00:00
'sdxl': sdxl,
'stable-diffusion-3': stable_diffusion_3,
### ByteDance ###
'sdxl-lightning-4step': sdxl_lightning_4step,
2024-07-08 20:41:19 +00:00
### ByteDance ###
'sdxl-lightning-4step': sdxl_lightning_4step,
### Playground ###
'playground-v2.5-1024px-aesthetic': 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())