models.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. from __future__ import annotations
  2. from dataclasses import dataclass
  3. from .Provider import RetryProvider, ProviderType
  4. from .Provider import (
  5. Chatgpt4Online,
  6. PerplexityLabs,
  7. ChatgptDemoAi,
  8. GeminiProChat,
  9. ChatgptNext,
  10. HuggingChat,
  11. ChatgptDemo,
  12. FreeChatgpt,
  13. GptForLove,
  14. ChatgptAi,
  15. DeepInfra,
  16. ChatBase,
  17. Liaobots,
  18. FreeGpt,
  19. Llama2,
  20. Vercel,
  21. Gemini,
  22. GptGo,
  23. Gpt6,
  24. Bing,
  25. You,
  26. Pi,
  27. )
  28. @dataclass(unsafe_hash=True)
  29. class Model:
  30. """
  31. Represents a machine learning model configuration.
  32. Attributes:
  33. name (str): Name of the model.
  34. base_provider (str): Default provider for the model.
  35. best_provider (ProviderType): The preferred provider for the model, typically with retry logic.
  36. """
  37. name: str
  38. base_provider: str
  39. best_provider: ProviderType = None
  40. @staticmethod
  41. def __all__() -> list[str]:
  42. """Returns a list of all model names."""
  43. return _all_models
  44. default = Model(
  45. name = "",
  46. base_provider = "",
  47. best_provider = RetryProvider([
  48. Bing,
  49. ChatgptAi, GptGo,
  50. You,
  51. Chatgpt4Online
  52. ])
  53. )
  54. # GPT-3.5 too, but all providers supports long requests and responses
  55. gpt_35_long = Model(
  56. name = 'gpt-3.5-turbo',
  57. base_provider = 'openai',
  58. best_provider = RetryProvider([
  59. FreeGpt, You,
  60. Chatgpt4Online,
  61. ChatgptDemoAi,
  62. ChatgptNext,
  63. ChatgptDemo,
  64. Gpt6,
  65. ])
  66. )
  67. # GPT-3.5 / GPT-4
  68. gpt_35_turbo = Model(
  69. name = 'gpt-3.5-turbo',
  70. base_provider = 'openai',
  71. best_provider = RetryProvider([
  72. GptGo, You,
  73. GptForLove, ChatBase,
  74. Chatgpt4Online,
  75. ])
  76. )
  77. gpt_4 = Model(
  78. name = 'gpt-4',
  79. base_provider = 'openai',
  80. best_provider = RetryProvider([
  81. Bing, Liaobots,
  82. ])
  83. )
  84. gpt_4_turbo = Model(
  85. name = 'gpt-4-turbo',
  86. base_provider = 'openai',
  87. best_provider = Bing
  88. )
  89. llama2_7b = Model(
  90. name = "meta-llama/Llama-2-7b-chat-hf",
  91. base_provider = 'meta',
  92. best_provider = RetryProvider([Llama2, DeepInfra])
  93. )
  94. llama2_13b = Model(
  95. name = "meta-llama/Llama-2-13b-chat-hf",
  96. base_provider = 'meta',
  97. best_provider = RetryProvider([Llama2, DeepInfra])
  98. )
  99. llama2_70b = Model(
  100. name = "meta-llama/Llama-2-70b-chat-hf",
  101. base_provider = "meta",
  102. best_provider = RetryProvider([Llama2, DeepInfra, HuggingChat, PerplexityLabs])
  103. )
  104. codellama_34b_instruct = Model(
  105. name = "codellama/CodeLlama-34b-Instruct-hf",
  106. base_provider = "meta",
  107. best_provider = RetryProvider([HuggingChat, PerplexityLabs, DeepInfra])
  108. )
  109. codellama_70b_instruct = Model(
  110. name = "codellama/CodeLlama-70b-Instruct-hf",
  111. base_provider = "meta",
  112. best_provider = DeepInfra
  113. )
  114. # Mistral
  115. mixtral_8x7b = Model(
  116. name = "mistralai/Mixtral-8x7B-Instruct-v0.1",
  117. base_provider = "huggingface",
  118. best_provider = RetryProvider([DeepInfra, HuggingChat, PerplexityLabs])
  119. )
  120. mistral_7b = Model(
  121. name = "mistralai/Mistral-7B-Instruct-v0.1",
  122. base_provider = "huggingface",
  123. best_provider = RetryProvider([DeepInfra, HuggingChat, PerplexityLabs])
  124. )
  125. # Misc models
  126. dolphin_mixtral_8x7b = Model(
  127. name = "cognitivecomputations/dolphin-2.6-mixtral-8x7b",
  128. base_provider = "huggingface",
  129. best_provider = DeepInfra
  130. )
  131. lzlv_70b = Model(
  132. name = "lizpreciatior/lzlv_70b_fp16_hf",
  133. base_provider = "huggingface",
  134. best_provider = DeepInfra
  135. )
  136. airoboros_70b = Model(
  137. name = "deepinfra/airoboros-70b",
  138. base_provider = "huggingface",
  139. best_provider = DeepInfra
  140. )
  141. airoboros_l2_70b = Model(
  142. name = "jondurbin/airoboros-l2-70b-gpt4-1.4.1",
  143. base_provider = "huggingface",
  144. best_provider = DeepInfra
  145. )
  146. openchat_35 = Model(
  147. name = "openchat/openchat_3.5",
  148. base_provider = "huggingface",
  149. best_provider = RetryProvider([DeepInfra, HuggingChat])
  150. )
  151. # Bard
  152. gemini = bard = palm = Model(
  153. name = 'gemini',
  154. base_provider = 'google',
  155. best_provider = Gemini
  156. )
  157. claude_v2 = Model(
  158. name = 'claude-v2',
  159. base_provider = 'anthropic',
  160. best_provider = RetryProvider([FreeChatgpt, Vercel])
  161. )
  162. gpt_35_turbo_16k = Model(
  163. name = 'gpt-3.5-turbo-16k',
  164. base_provider = 'openai',
  165. best_provider = gpt_35_long.best_provider
  166. )
  167. gpt_35_turbo_16k_0613 = Model(
  168. name = 'gpt-3.5-turbo-16k-0613',
  169. base_provider = 'openai',
  170. best_provider = gpt_35_long.best_provider
  171. )
  172. gpt_35_turbo_0613 = Model(
  173. name = 'gpt-3.5-turbo-0613',
  174. base_provider = 'openai',
  175. best_provider = gpt_35_turbo.best_provider
  176. )
  177. gpt_4_0613 = Model(
  178. name = 'gpt-4-0613',
  179. base_provider = 'openai',
  180. best_provider = gpt_4.best_provider
  181. )
  182. gpt_4_32k = Model(
  183. name = 'gpt-4-32k',
  184. base_provider = 'openai',
  185. best_provider = gpt_4.best_provider
  186. )
  187. gpt_4_32k_0613 = Model(
  188. name = 'gpt-4-32k-0613',
  189. base_provider = 'openai',
  190. best_provider = gpt_4.best_provider
  191. )
  192. gemini_pro = Model(
  193. name = 'gemini-pro',
  194. base_provider = 'google',
  195. best_provider = RetryProvider([FreeChatgpt, GeminiProChat])
  196. )
  197. pi = Model(
  198. name = 'pi',
  199. base_provider = 'inflection',
  200. best_provider = Pi
  201. )
  202. class ModelUtils:
  203. """
  204. Utility class for mapping string identifiers to Model instances.
  205. Attributes:
  206. convert (dict[str, Model]): Dictionary mapping model string identifiers to Model instances.
  207. """
  208. convert: dict[str, Model] = {
  209. # gpt-3.5
  210. 'gpt-3.5-turbo' : gpt_35_turbo,
  211. 'gpt-3.5-turbo-0613' : gpt_35_turbo_0613,
  212. 'gpt-3.5-turbo-16k' : gpt_35_turbo_16k,
  213. 'gpt-3.5-turbo-16k-0613' : gpt_35_turbo_16k_0613,
  214. 'gpt-3.5-long': gpt_35_long,
  215. # gpt-4
  216. 'gpt-4' : gpt_4,
  217. 'gpt-4-0613' : gpt_4_0613,
  218. 'gpt-4-32k' : gpt_4_32k,
  219. 'gpt-4-32k-0613' : gpt_4_32k_0613,
  220. 'gpt-4-turbo' : gpt_4_turbo,
  221. # Llama 2
  222. 'llama2-7b' : llama2_7b,
  223. 'llama2-13b': llama2_13b,
  224. 'llama2-70b': llama2_70b,
  225. 'codellama-34b-instruct': codellama_34b_instruct,
  226. 'codellama-70b-instruct': codellama_70b_instruct,
  227. 'mixtral-8x7b': mixtral_8x7b,
  228. 'mistral-7b': mistral_7b,
  229. 'dolphin-mixtral-8x7b': dolphin_mixtral_8x7b,
  230. 'lzlv-70b': lzlv_70b,
  231. 'airoboros-70b': airoboros_70b,
  232. 'airoboros-l2-70b': airoboros_l2_70b,
  233. 'openchat_3.5': openchat_35,
  234. 'gemini': gemini,
  235. 'gemini-pro': gemini_pro,
  236. 'claude-v2': claude_v2,
  237. 'pi': pi
  238. }
  239. _all_models = list(ModelUtils.convert.keys())