models.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. from __future__ import annotations
  2. from dataclasses import dataclass
  3. from .Provider import IterListProvider, ProviderType
  4. from .Provider import (
  5. AIChatFree,
  6. Airforce,
  7. AIUncensored,
  8. Bing,
  9. Blackbox,
  10. ChatGpt,
  11. Chatgpt4Online,
  12. ChatGptEs,
  13. Cloudflare,
  14. DarkAI,
  15. DDG,
  16. DeepInfraChat,
  17. Free2GPT,
  18. FreeNetfly,
  19. GigaChat,
  20. Gemini,
  21. GeminiPro,
  22. HuggingChat,
  23. HuggingFace,
  24. Liaobots,
  25. MagickPen,
  26. Mhystical,
  27. MetaAI,
  28. OpenaiChat,
  29. PerplexityLabs,
  30. Pi,
  31. Pizzagpt,
  32. Reka,
  33. ReplicateHome,
  34. RubiksAI,
  35. TeachAnything,
  36. Upstage,
  37. )
  38. @dataclass(unsafe_hash=True)
  39. class Model:
  40. """
  41. Represents a machine learning model configuration.
  42. Attributes:
  43. name (str): Name of the model.
  44. base_provider (str): Default provider for the model.
  45. best_provider (ProviderType): The preferred provider for the model, typically with retry logic.
  46. """
  47. name: str
  48. base_provider: str
  49. best_provider: ProviderType = None
  50. @staticmethod
  51. def __all__() -> list[str]:
  52. """Returns a list of all model names."""
  53. return _all_models
  54. ### Default ###
  55. default = Model(
  56. name = "",
  57. base_provider = "",
  58. best_provider = IterListProvider([
  59. DDG,
  60. Pizzagpt,
  61. ReplicateHome,
  62. Upstage,
  63. Blackbox,
  64. Free2GPT,
  65. MagickPen,
  66. DeepInfraChat,
  67. Airforce,
  68. ChatGptEs,
  69. Cloudflare,
  70. AIUncensored,
  71. DarkAI,
  72. Mhystical,
  73. ])
  74. )
  75. ############
  76. ### Text ###
  77. ############
  78. ### OpenAI ###
  79. # gpt-3.5
  80. gpt_35_turbo = Model(
  81. name = 'gpt-3.5-turbo',
  82. base_provider = 'OpenAI',
  83. best_provider = IterListProvider([Airforce])
  84. )
  85. # gpt-4
  86. gpt_4o = Model(
  87. name = 'gpt-4o',
  88. base_provider = 'OpenAI',
  89. best_provider = IterListProvider([Blackbox, ChatGptEs, DarkAI, ChatGpt, Airforce, Liaobots, OpenaiChat])
  90. )
  91. gpt_4o_mini = Model(
  92. name = 'gpt-4o-mini',
  93. base_provider = 'OpenAI',
  94. best_provider = IterListProvider([DDG, ChatGptEs, FreeNetfly, Pizzagpt, ChatGpt, Airforce, RubiksAI, MagickPen, Liaobots, OpenaiChat])
  95. )
  96. gpt_4_turbo = Model(
  97. name = 'gpt-4-turbo',
  98. base_provider = 'OpenAI',
  99. best_provider = IterListProvider([Liaobots, Bing])
  100. )
  101. gpt_4 = Model(
  102. name = 'gpt-4',
  103. base_provider = 'OpenAI',
  104. best_provider = IterListProvider([Chatgpt4Online, Bing, OpenaiChat, DDG, Liaobots, Airforce])
  105. )
  106. ### GigaChat ###
  107. gigachat = Model(
  108. name = 'GigaChat:latest',
  109. base_provider = 'gigachat',
  110. best_provider = GigaChat
  111. )
  112. ### Meta ###
  113. meta = Model(
  114. name = "meta-ai",
  115. base_provider = "Meta",
  116. best_provider = MetaAI
  117. )
  118. # llama 2
  119. llama_2_7b = Model(
  120. name = "llama-2-7b",
  121. base_provider = "Meta Llama",
  122. best_provider = Cloudflare
  123. )
  124. # llama 3
  125. llama_3_8b = Model(
  126. name = "llama-3-8b",
  127. base_provider = "Meta Llama",
  128. best_provider = Cloudflare
  129. )
  130. # llama 3.1
  131. llama_3_1_8b = Model(
  132. name = "llama-3.1-8b",
  133. base_provider = "Meta Llama",
  134. best_provider = IterListProvider([Blackbox, DeepInfraChat, Cloudflare, Airforce, PerplexityLabs])
  135. )
  136. llama_3_1_70b = Model(
  137. name = "llama-3.1-70b",
  138. base_provider = "Meta Llama",
  139. best_provider = IterListProvider([DDG, DeepInfraChat, Blackbox, TeachAnything, DarkAI, Airforce, RubiksAI, HuggingChat, HuggingFace, PerplexityLabs])
  140. )
  141. llama_3_1_405b = Model(
  142. name = "llama-3.1-405b",
  143. base_provider = "Meta Llama",
  144. best_provider = IterListProvider([Blackbox, DarkAI])
  145. )
  146. # llama 3.2
  147. llama_3_2_1b = Model(
  148. name = "llama-3.2-1b",
  149. base_provider = "Meta Llama",
  150. best_provider = IterListProvider([Cloudflare])
  151. )
  152. llama_3_2_11b = Model(
  153. name = "llama-3.2-11b",
  154. base_provider = "Meta Llama",
  155. best_provider = IterListProvider([HuggingChat, HuggingFace])
  156. )
  157. mixtral_8x7b = Model(
  158. name = "mixtral-8x7b",
  159. base_provider = "Mistral",
  160. best_provider = DDG
  161. )
  162. mistral_nemo = Model(
  163. name = "mistral-nemo",
  164. base_provider = "Mistral",
  165. best_provider = IterListProvider([HuggingChat, HuggingFace])
  166. )
  167. hermes_3 = Model(
  168. name = "hermes-3",
  169. base_provider = "NousResearch",
  170. best_provider = IterListProvider([HuggingChat, HuggingFace])
  171. )
  172. ### Microsoft ###
  173. phi_2 = Model(
  174. name = "phi-2",
  175. base_provider = "Microsoft",
  176. best_provider = IterListProvider([Airforce])
  177. )
  178. phi_3_5_mini = Model(
  179. name = "phi-3.5-mini",
  180. base_provider = "Microsoft",
  181. best_provider = IterListProvider([HuggingChat, HuggingFace])
  182. )
  183. ### Google DeepMind ###
  184. # gemini
  185. gemini_pro = Model(
  186. name = 'gemini-pro',
  187. base_provider = 'Google DeepMind',
  188. best_provider = IterListProvider([Blackbox, AIChatFree, GeminiPro, Liaobots])
  189. )
  190. gemini_flash = Model(
  191. name = 'gemini-flash',
  192. base_provider = 'Google DeepMind',
  193. best_provider = IterListProvider([Blackbox, Liaobots])
  194. )
  195. gemini = Model(
  196. name = 'gemini',
  197. base_provider = 'Google DeepMind',
  198. best_provider = Gemini
  199. )
  200. # gemma
  201. gemma_2b = Model(
  202. name = 'gemma-2b',
  203. base_provider = 'Google',
  204. best_provider = ReplicateHome
  205. )
  206. ### Anthropic ###
  207. claude_2_1 = Model(
  208. name = 'claude-2.1',
  209. base_provider = 'Anthropic',
  210. best_provider = Liaobots
  211. )
  212. # claude 3
  213. claude_3_opus = Model(
  214. name = 'claude-3-opus',
  215. base_provider = 'Anthropic',
  216. best_provider = Liaobots
  217. )
  218. claude_3_sonnet = Model(
  219. name = 'claude-3-sonnet',
  220. base_provider = 'Anthropic',
  221. best_provider = Liaobots
  222. )
  223. claude_3_haiku = Model(
  224. name = 'claude-3-haiku',
  225. base_provider = 'Anthropic',
  226. best_provider = IterListProvider([DDG, Liaobots])
  227. )
  228. # claude 3.5
  229. claude_3_5_sonnet = Model(
  230. name = 'claude-3.5-sonnet',
  231. base_provider = 'Anthropic',
  232. best_provider = IterListProvider([Blackbox, Liaobots])
  233. )
  234. ### Reka AI ###
  235. reka_core = Model(
  236. name = 'reka-core',
  237. base_provider = 'Reka AI',
  238. best_provider = Reka
  239. )
  240. ### Blackbox AI ###
  241. blackboxai = Model(
  242. name = 'blackboxai',
  243. base_provider = 'Blackbox AI',
  244. best_provider = Blackbox
  245. )
  246. blackboxai_pro = Model(
  247. name = 'blackboxai-pro',
  248. base_provider = 'Blackbox AI',
  249. best_provider = Blackbox
  250. )
  251. ### CohereForAI ###
  252. command_r_plus = Model(
  253. name = 'command-r-plus',
  254. base_provider = 'CohereForAI',
  255. best_provider = HuggingChat
  256. )
  257. ### Qwen ###
  258. # qwen 1_5
  259. qwen_1_5_7b = Model(
  260. name = 'qwen-1.5-7b',
  261. base_provider = 'Qwen',
  262. best_provider = Cloudflare
  263. )
  264. # qwen 2
  265. qwen_2_72b = Model(
  266. name = 'qwen-2-72b',
  267. base_provider = 'Qwen',
  268. best_provider = IterListProvider([DeepInfraChat, HuggingChat, HuggingFace])
  269. )
  270. # qwen 2.5
  271. qwen_2_5_coder_32b = Model(
  272. name = 'qwen-2.5-coder-32b',
  273. base_provider = 'Qwen',
  274. best_provider = IterListProvider([HuggingChat, HuggingFace])
  275. )
  276. ### Upstage ###
  277. solar_mini = Model(
  278. name = 'solar-mini',
  279. base_provider = 'Upstage',
  280. best_provider = Upstage
  281. )
  282. solar_pro = Model(
  283. name = 'solar-pro',
  284. base_provider = 'Upstage',
  285. best_provider = Upstage
  286. )
  287. ### Inflection ###
  288. pi = Model(
  289. name = 'pi',
  290. base_provider = 'Inflection',
  291. best_provider = Pi
  292. )
  293. ### DeepSeek ###
  294. deepseek_coder = Model(
  295. name = 'deepseek-coder',
  296. base_provider = 'DeepSeek',
  297. best_provider = Airforce
  298. )
  299. ### WizardLM ###
  300. wizardlm_2_8x22b = Model(
  301. name = 'wizardlm-2-8x22b',
  302. base_provider = 'WizardLM',
  303. best_provider = DeepInfraChat
  304. )
  305. ### Yorickvp ###
  306. llava_13b = Model(
  307. name = 'llava-13b',
  308. base_provider = 'Yorickvp',
  309. best_provider = ReplicateHome
  310. )
  311. ### OpenChat ###
  312. openchat_3_5 = Model(
  313. name = 'openchat-3.5',
  314. base_provider = 'OpenChat',
  315. best_provider = Airforce
  316. )
  317. ### x.ai ###
  318. grok_2 = Model(
  319. name = 'grok-2',
  320. base_provider = 'x.ai',
  321. best_provider = Liaobots
  322. )
  323. grok_2_mini = Model(
  324. name = 'grok-2-mini',
  325. base_provider = 'x.ai',
  326. best_provider = Liaobots
  327. )
  328. grok_beta = Model(
  329. name = 'grok-beta',
  330. base_provider = 'x.ai',
  331. best_provider = Liaobots
  332. )
  333. ### Perplexity AI ###
  334. sonar_online = Model(
  335. name = 'sonar-online',
  336. base_provider = 'Perplexity AI',
  337. best_provider = PerplexityLabs
  338. )
  339. sonar_chat = Model(
  340. name = 'sonar-chat',
  341. base_provider = 'Perplexity AI',
  342. best_provider = PerplexityLabs
  343. )
  344. ### Nvidia ###
  345. nemotron_70b = Model(
  346. name = 'nemotron-70b',
  347. base_provider = 'Nvidia',
  348. best_provider = IterListProvider([HuggingChat, HuggingFace])
  349. )
  350. ### Teknium ###
  351. openhermes_2_5 = Model(
  352. name = 'openhermes-2.5',
  353. base_provider = 'Teknium',
  354. best_provider = Airforce
  355. )
  356. ### Liquid ###
  357. lfm_40b = Model(
  358. name = 'lfm-40b',
  359. base_provider = 'Liquid',
  360. best_provider = IterListProvider([Airforce, PerplexityLabs])
  361. )
  362. ### DiscoResearch ###
  363. german_7b = Model(
  364. name = 'german-7b',
  365. base_provider = 'DiscoResearch',
  366. best_provider = Airforce
  367. )
  368. ### HuggingFaceH4 ###
  369. zephyr_7b = Model(
  370. name = 'zephyr-7b',
  371. base_provider = 'HuggingFaceH4',
  372. best_provider = Airforce
  373. )
  374. ### Inferless ###
  375. neural_7b = Model(
  376. name = 'neural-7b',
  377. base_provider = 'inferless',
  378. best_provider = Airforce
  379. )
  380. #############
  381. ### Image ###
  382. #############
  383. ### Stability AI ###
  384. sdxl = Model(
  385. name = 'sdxl',
  386. base_provider = 'Stability AI',
  387. best_provider = ReplicateHome
  388. )
  389. sd_3 = Model(
  390. name = 'sd-3',
  391. base_provider = 'Stability AI',
  392. best_provider = ReplicateHome
  393. )
  394. ### Playground ###
  395. playground_v2_5 = Model(
  396. name = 'playground-v2.5',
  397. base_provider = 'Playground AI',
  398. best_provider = ReplicateHome
  399. )
  400. ### Flux AI ###
  401. flux = Model(
  402. name = 'flux',
  403. base_provider = 'Flux AI',
  404. best_provider = IterListProvider([Blackbox, AIUncensored, Airforce])
  405. )
  406. flux_pro = Model(
  407. name = 'flux-pro',
  408. base_provider = 'Flux AI',
  409. best_provider = Airforce
  410. )
  411. flux_realism = Model(
  412. name = 'flux-realism',
  413. base_provider = 'Flux AI',
  414. best_provider = Airforce
  415. )
  416. flux_anime = Model(
  417. name = 'flux-anime',
  418. base_provider = 'Flux AI',
  419. best_provider = Airforce
  420. )
  421. flux_3d = Model(
  422. name = 'flux-3d',
  423. base_provider = 'Flux AI',
  424. best_provider = Airforce
  425. )
  426. flux_disney = Model(
  427. name = 'flux-disney',
  428. base_provider = 'Flux AI',
  429. best_provider = Airforce
  430. )
  431. flux_pixel = Model(
  432. name = 'flux-pixel',
  433. base_provider = 'Flux AI',
  434. best_provider = Airforce
  435. )
  436. flux_4o = Model(
  437. name = 'flux-4o',
  438. base_provider = 'Flux AI',
  439. best_provider = Airforce
  440. )
  441. ### Other ###
  442. any_dark = Model(
  443. name = 'any-dark',
  444. base_provider = '',
  445. best_provider = Airforce
  446. )
  447. class ModelUtils:
  448. """
  449. Utility class for mapping string identifiers to Model instances.
  450. Attributes:
  451. convert (dict[str, Model]): Dictionary mapping model string identifiers to Model instances.
  452. """
  453. convert: dict[str, Model] = {
  454. ############
  455. ### Text ###
  456. ############
  457. ### OpenAI ###
  458. # gpt-3
  459. 'gpt-3': gpt_35_turbo,
  460. # gpt-3.5
  461. 'gpt-3.5-turbo': gpt_35_turbo,
  462. # gpt-4
  463. 'gpt-4o': gpt_4o,
  464. 'gpt-4o-mini': gpt_4o_mini,
  465. 'gpt-4': gpt_4,
  466. 'gpt-4-turbo': gpt_4_turbo,
  467. ### Meta ###
  468. "meta-ai": meta,
  469. # llama-2
  470. 'llama-2-7b': llama_2_7b,
  471. # llama-3
  472. 'llama-3-8b': llama_3_8b,
  473. # llama-3.1
  474. 'llama-3.1-8b': llama_3_1_8b,
  475. 'llama-3.1-70b': llama_3_1_70b,
  476. 'llama-3.1-405b': llama_3_1_405b,
  477. # llama-3.2
  478. 'llama-3.2-1b': llama_3_2_1b,
  479. 'llama-3.2-11b': llama_3_2_11b,
  480. ### Mistral ###
  481. 'mixtral-8x7b': mixtral_8x7b,
  482. 'mistral-nemo': mistral_nemo,
  483. ### NousResearch ###
  484. 'hermes-3': hermes_3,
  485. ### Microsoft ###
  486. 'phi-2': phi_2,
  487. 'phi-3.5-mini': phi_3_5_mini,
  488. ### Google ###
  489. # gemini
  490. 'gemini': gemini,
  491. 'gemini-pro': gemini_pro,
  492. 'gemini-flash': gemini_flash,
  493. # gemma
  494. 'gemma-2b': gemma_2b,
  495. ### Anthropic ###
  496. 'claude-2.1': claude_2_1,
  497. # claude 3
  498. 'claude-3-opus': claude_3_opus,
  499. 'claude-3-sonnet': claude_3_sonnet,
  500. 'claude-3-haiku': claude_3_haiku,
  501. # claude 3.5
  502. 'claude-3.5-sonnet': claude_3_5_sonnet,
  503. ### Reka AI ###
  504. 'reka-core': reka_core,
  505. ### Blackbox AI ###
  506. 'blackboxai': blackboxai,
  507. 'blackboxai-pro': blackboxai_pro,
  508. ### CohereForAI ###
  509. 'command-r+': command_r_plus,
  510. ### GigaChat ###
  511. 'gigachat': gigachat,
  512. 'qwen-1.5-7b': qwen_1_5_7b,
  513. 'qwen-2-72b': qwen_2_72b,
  514. ### Upstage ###
  515. 'solar-pro': solar_pro,
  516. ### Inflection ###
  517. 'pi': pi,
  518. ### Yorickvp ###
  519. 'llava-13b': llava_13b,
  520. ### WizardLM ###
  521. 'wizardlm-2-8x22b': wizardlm_2_8x22b,
  522. ### OpenChat ###
  523. 'openchat-3.5': openchat_3_5,
  524. ### x.ai ###
  525. 'grok-2': grok_2,
  526. 'grok-2-mini': grok_2_mini,
  527. 'grok-beta': grok_beta,
  528. ### Perplexity AI ###
  529. 'sonar-online': sonar_online,
  530. 'sonar-chat': sonar_chat,
  531. ### TheBloke ###
  532. 'german-7b': german_7b,
  533. ### Nvidia ###
  534. 'nemotron-70b': nemotron_70b,
  535. #############
  536. ### Image ###
  537. #############
  538. ### Stability AI ###
  539. 'sdxl': sdxl,
  540. 'sd-3': sd_3,
  541. ### Playground ###
  542. 'playground-v2.5': playground_v2_5,
  543. ### Flux AI ###
  544. 'flux': flux,
  545. 'flux-pro': flux_pro,
  546. 'flux-realism': flux_realism,
  547. 'flux-anime': flux_anime,
  548. 'flux-3d': flux_3d,
  549. 'flux-disney': flux_disney,
  550. 'flux-pixel': flux_pixel,
  551. 'flux-4o': flux_4o,
  552. ### Other ###
  553. 'any-dark': any_dark,
  554. }
  555. _all_models = list(ModelUtils.convert.keys())