models.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. from __future__ import annotations
  2. from dataclasses import dataclass
  3. from .Provider import RetryProvider, ProviderType
  4. from .Provider import (
  5. Chatgpt4Online,
  6. ChatgptDemoAi,
  7. GeminiProChat,
  8. ChatgptNext,
  9. HuggingChat,
  10. ChatgptDemo,
  11. FreeChatgpt,
  12. GptForLove,
  13. ChatgptAi,
  14. DeepInfra,
  15. ChatBase,
  16. Liaobots,
  17. GeekGpt,
  18. FakeGpt,
  19. FreeGpt,
  20. Llama2,
  21. Vercel,
  22. Phind,
  23. GptGo,
  24. Gpt6,
  25. Bard,
  26. Bing,
  27. You,
  28. H2o,
  29. Pi,
  30. )
  31. @dataclass(unsafe_hash=True)
  32. class Model:
  33. """
  34. Represents a machine learning model configuration.
  35. Attributes:
  36. name (str): Name of the model.
  37. base_provider (str): Default provider for the model.
  38. best_provider (ProviderType): The preferred provider for the model, typically with retry logic.
  39. """
  40. name: str
  41. base_provider: str
  42. best_provider: ProviderType = None
  43. @staticmethod
  44. def __all__() -> list[str]:
  45. """Returns a list of all model names."""
  46. return _all_models
  47. default = Model(
  48. name = "",
  49. base_provider = "",
  50. best_provider = RetryProvider([
  51. Bing,
  52. ChatgptAi, GptGo, GeekGpt,
  53. You,
  54. Chatgpt4Online
  55. ])
  56. )
  57. # GPT-3.5 too, but all providers supports long requests and responses
  58. gpt_35_long = Model(
  59. name = 'gpt-3.5-turbo',
  60. base_provider = 'openai',
  61. best_provider = RetryProvider([
  62. FreeGpt, You,
  63. GeekGpt, FakeGpt,
  64. Chatgpt4Online,
  65. ChatgptDemoAi,
  66. ChatgptNext,
  67. ChatgptDemo,
  68. Gpt6,
  69. ])
  70. )
  71. # GPT-3.5 / GPT-4
  72. gpt_35_turbo = Model(
  73. name = 'gpt-3.5-turbo',
  74. base_provider = 'openai',
  75. best_provider=RetryProvider([
  76. GptGo, You,
  77. GptForLove, ChatBase,
  78. Chatgpt4Online,
  79. ])
  80. )
  81. gpt_4 = Model(
  82. name = 'gpt-4',
  83. base_provider = 'openai',
  84. best_provider = RetryProvider([
  85. Bing, Phind, Liaobots,
  86. ])
  87. )
  88. gpt_4_turbo = Model(
  89. name = 'gpt-4-turbo',
  90. base_provider = 'openai',
  91. best_provider = Bing
  92. )
  93. llama2_7b = Model(
  94. name = "meta-llama/Llama-2-7b-chat-hf",
  95. base_provider = 'huggingface',
  96. best_provider = RetryProvider([Llama2, DeepInfra])
  97. )
  98. llama2_13b = Model(
  99. name = "meta-llama/Llama-2-13b-chat-hf",
  100. base_provider = 'huggingface',
  101. best_provider = RetryProvider([Llama2, DeepInfra])
  102. )
  103. llama2_70b = Model(
  104. name = "meta-llama/Llama-2-70b-chat-hf",
  105. base_provider = "huggingface",
  106. best_provider = RetryProvider([Llama2, DeepInfra, HuggingChat])
  107. )
  108. # Mistal
  109. mixtral_8x7b = Model(
  110. name = "mistralai/Mixtral-8x7B-Instruct-v0.1",
  111. base_provider = "huggingface",
  112. best_provider = RetryProvider([DeepInfra, HuggingChat])
  113. )
  114. mistral_7b = Model(
  115. name = "mistralai/Mistral-7B-Instruct-v0.1",
  116. base_provider = "huggingface",
  117. best_provider = RetryProvider([DeepInfra, HuggingChat])
  118. )
  119. openchat_35 = Model(
  120. name = "openchat/openchat_3.5",
  121. base_provider = "huggingface",
  122. best_provider = RetryProvider([DeepInfra, HuggingChat])
  123. )
  124. # Bard
  125. palm = Model(
  126. name = 'palm',
  127. base_provider = 'google',
  128. best_provider = Bard)
  129. # H2o
  130. falcon_7b = Model(
  131. name = 'h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v3',
  132. base_provider = 'huggingface',
  133. best_provider = H2o)
  134. falcon_40b = Model(
  135. name = 'h2oai/h2ogpt-gm-oasst1-en-2048-falcon-40b-v1',
  136. base_provider = 'huggingface',
  137. best_provider = H2o)
  138. llama_13b = Model(
  139. name = 'h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-13b',
  140. base_provider = 'huggingface',
  141. best_provider = H2o)
  142. # Vercel
  143. claude_instant_v1 = Model(
  144. name = 'claude-instant-v1',
  145. base_provider = 'anthropic',
  146. best_provider = Vercel)
  147. claude_v1 = Model(
  148. name = 'claude-v1',
  149. base_provider = 'anthropic',
  150. best_provider = Vercel)
  151. claude_v2 = Model(
  152. name = 'claude-v2',
  153. base_provider = 'anthropic',
  154. best_provider = RetryProvider([FreeChatgpt, Vercel]))
  155. command_light_nightly = Model(
  156. name = 'command-light-nightly',
  157. base_provider = 'cohere',
  158. best_provider = Vercel)
  159. command_nightly = Model(
  160. name = 'command-nightly',
  161. base_provider = 'cohere',
  162. best_provider = Vercel)
  163. gpt_neox_20b = Model(
  164. name = 'EleutherAI/gpt-neox-20b',
  165. base_provider = 'huggingface',
  166. best_provider = Vercel)
  167. oasst_sft_1_pythia_12b = Model(
  168. name = 'OpenAssistant/oasst-sft-1-pythia-12b',
  169. base_provider = 'huggingface',
  170. best_provider = Vercel)
  171. oasst_sft_4_pythia_12b_epoch_35 = Model(
  172. name = 'OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5',
  173. base_provider = 'huggingface',
  174. best_provider = Vercel)
  175. santacoder = Model(
  176. name = 'bigcode/santacoder',
  177. base_provider = 'huggingface',
  178. best_provider = Vercel)
  179. bloom = Model(
  180. name = 'bigscience/bloom',
  181. base_provider = 'huggingface',
  182. best_provider = Vercel)
  183. flan_t5_xxl = Model(
  184. name = 'google/flan-t5-xxl',
  185. base_provider = 'huggingface',
  186. best_provider = Vercel)
  187. code_davinci_002 = Model(
  188. name = 'code-davinci-002',
  189. base_provider = 'openai',
  190. best_provider = Vercel)
  191. gpt_35_turbo_16k = Model(
  192. name = 'gpt-3.5-turbo-16k',
  193. base_provider = 'openai',
  194. best_provider = gpt_35_long.best_provider)
  195. gpt_35_turbo_16k_0613 = Model(
  196. name = 'gpt-3.5-turbo-16k-0613',
  197. base_provider = 'openai',
  198. best_provider = gpt_35_long.best_provider
  199. )
  200. gpt_35_turbo_0613 = Model(
  201. name = 'gpt-3.5-turbo-0613',
  202. base_provider = 'openai',
  203. best_provider = gpt_35_turbo.best_provider
  204. )
  205. gpt_4_0613 = Model(
  206. name = 'gpt-4-0613',
  207. base_provider = 'openai',
  208. best_provider = gpt_4.best_provider
  209. )
  210. gpt_4_32k = Model(
  211. name = 'gpt-4-32k',
  212. base_provider = 'openai',
  213. best_provider = gpt_4.best_provider
  214. )
  215. gpt_4_32k_0613 = Model(
  216. name = 'gpt-4-32k-0613',
  217. base_provider = 'openai',
  218. best_provider = gpt_4.best_provider
  219. )
  220. gemini_pro = Model(
  221. name = 'gemini-pro',
  222. base_provider = 'google',
  223. best_provider = RetryProvider([FreeChatgpt, GeminiProChat])
  224. )
  225. text_ada_001 = Model(
  226. name = 'text-ada-001',
  227. base_provider = 'openai',
  228. best_provider = Vercel)
  229. text_babbage_001 = Model(
  230. name = 'text-babbage-001',
  231. base_provider = 'openai',
  232. best_provider = Vercel)
  233. text_curie_001 = Model(
  234. name = 'text-curie-001',
  235. base_provider = 'openai',
  236. best_provider = Vercel)
  237. text_davinci_002 = Model(
  238. name = 'text-davinci-002',
  239. base_provider = 'openai',
  240. best_provider = Vercel)
  241. text_davinci_003 = Model(
  242. name = 'text-davinci-003',
  243. base_provider = 'openai',
  244. best_provider = Vercel)
  245. llama13b_v2_chat = Model(
  246. name = 'replicate:a16z-infra/llama13b-v2-chat',
  247. base_provider = 'replicate',
  248. best_provider = Vercel)
  249. llama7b_v2_chat = Model(
  250. name = 'replicate:a16z-infra/llama7b-v2-chat',
  251. base_provider = 'replicate',
  252. best_provider = Vercel)
  253. llama70b_v2_chat = Model(
  254. name = 'replicate/llama70b-v2-chat',
  255. base_provider = 'replicate',
  256. best_provider = Vercel)
  257. pi = Model(
  258. name = 'pi',
  259. base_provider = 'inflection',
  260. best_provider=Pi
  261. )
  262. class ModelUtils:
  263. """
  264. Utility class for mapping string identifiers to Model instances.
  265. Attributes:
  266. convert (dict[str, Model]): Dictionary mapping model string identifiers to Model instances.
  267. """
  268. convert: dict[str, Model] = {
  269. # gpt-3.5
  270. 'gpt-3.5-turbo' : gpt_35_turbo,
  271. 'gpt-3.5-turbo-0613' : gpt_35_turbo_0613,
  272. 'gpt-3.5-turbo-16k' : gpt_35_turbo_16k,
  273. 'gpt-3.5-turbo-16k-0613' : gpt_35_turbo_16k_0613,
  274. 'gpt-3.5-long': gpt_35_long,
  275. # gpt-4
  276. 'gpt-4' : gpt_4,
  277. 'gpt-4-0613' : gpt_4_0613,
  278. 'gpt-4-32k' : gpt_4_32k,
  279. 'gpt-4-32k-0613' : gpt_4_32k_0613,
  280. 'gpt-4-turbo' : gpt_4_turbo,
  281. # Llama 2
  282. 'llama2-7b' : llama2_7b,
  283. 'llama2-13b': llama2_13b,
  284. 'llama2-70b': llama2_70b,
  285. # Mistral
  286. 'mixtral-8x7b': mixtral_8x7b,
  287. 'mistral-7b': mistral_7b,
  288. 'openchat_3.5': openchat_35,
  289. # Gemini Pro
  290. 'gemini-pro': gemini_pro,
  291. # Bard
  292. 'palm2' : palm,
  293. 'palm' : palm,
  294. 'google' : palm,
  295. 'google-bard' : palm,
  296. 'google-palm' : palm,
  297. 'bard' : palm,
  298. # H2o
  299. 'falcon-40b' : falcon_40b,
  300. 'falcon-7b' : falcon_7b,
  301. 'llama-13b' : llama_13b,
  302. # Vercel
  303. #'claude-instant-v1' : claude_instant_v1,
  304. #'claude-v1' : claude_v1,
  305. #'claude-v2' : claude_v2,
  306. 'command-nightly' : command_nightly,
  307. 'gpt-neox-20b' : gpt_neox_20b,
  308. 'santacoder' : santacoder,
  309. 'bloom' : bloom,
  310. 'flan-t5-xxl' : flan_t5_xxl,
  311. 'code-davinci-002' : code_davinci_002,
  312. 'text-ada-001' : text_ada_001,
  313. 'text-babbage-001' : text_babbage_001,
  314. 'text-curie-001' : text_curie_001,
  315. 'text-davinci-002' : text_davinci_002,
  316. 'text-davinci-003' : text_davinci_003,
  317. 'llama70b-v2-chat' : llama70b_v2_chat,
  318. 'llama13b-v2-chat' : llama13b_v2_chat,
  319. 'llama7b-v2-chat' : llama7b_v2_chat,
  320. 'oasst-sft-1-pythia-12b' : oasst_sft_1_pythia_12b,
  321. 'oasst-sft-4-pythia-12b-epoch-3.5' : oasst_sft_4_pythia_12b_epoch_35,
  322. 'command-light-nightly' : command_light_nightly,
  323. 'pi': pi
  324. }
  325. _all_models = list(ModelUtils.convert.keys())