render.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import {Label} from 'semantic-ui-react';
  2. import {Tag} from "@douyinfe/semi-ui";
  3. export function renderText(text, limit) {
  4. if (text.length > limit) {
  5. return text.slice(0, limit - 3) + '...';
  6. }
  7. return text;
  8. }
  9. export function renderGroup(group) {
  10. if (group === '') {
  11. return <Tag size='large'>default</Tag>;
  12. }
  13. let groups = group.split(',');
  14. groups.sort();
  15. return <>
  16. {groups.map((group) => {
  17. if (group === 'vip' || group === 'pro') {
  18. return <Tag size='large' color='yellow'>{group}</Tag>;
  19. } else if (group === 'svip' || group === 'premium') {
  20. return <Tag size='large' color='red'>{group}</Tag>;
  21. }
  22. if (group === 'default') {
  23. return <Tag size='large'>{group}</Tag>;
  24. } else {
  25. return <Tag size='large' color={stringToColor(group)}>{group}</Tag>;
  26. }
  27. })}
  28. </>;
  29. }
  30. export function renderNumber(num) {
  31. if (num >= 1000000000) {
  32. return (num / 1000000000).toFixed(1) + 'B';
  33. } else if (num >= 1000000) {
  34. return (num / 1000000).toFixed(1) + 'M';
  35. } else if (num >= 10000) {
  36. return (num / 1000).toFixed(1) + 'k';
  37. } else {
  38. return num;
  39. }
  40. }
  41. export function renderQuotaNumberWithDigit(num, digits = 2) {
  42. let displayInCurrency = localStorage.getItem('display_in_currency');
  43. num = num.toFixed(digits);
  44. if (displayInCurrency) {
  45. return '$' + num;
  46. }
  47. return num;
  48. }
  49. export function renderNumberWithPoint(num) {
  50. num = num.toFixed(2);
  51. if (num >= 100000) {
  52. // Convert number to string to manipulate it
  53. let numStr = num.toString();
  54. // Find the position of the decimal point
  55. let decimalPointIndex = numStr.indexOf('.');
  56. let wholePart = numStr;
  57. let decimalPart = '';
  58. // If there is a decimal point, split the number into whole and decimal parts
  59. if (decimalPointIndex !== -1) {
  60. wholePart = numStr.slice(0, decimalPointIndex);
  61. decimalPart = numStr.slice(decimalPointIndex);
  62. }
  63. // Take the first two and last two digits of the whole number part
  64. let shortenedWholePart = wholePart.slice(0, 2) + '..' + wholePart.slice(-2);
  65. // Return the formatted number
  66. return shortenedWholePart + decimalPart;
  67. }
  68. // If the number is less than 100,000, return it unmodified
  69. return num;
  70. }
  71. export function getQuotaPerUnit() {
  72. let quotaPerUnit = localStorage.getItem('quota_per_unit');
  73. quotaPerUnit = parseFloat(quotaPerUnit);
  74. return quotaPerUnit;
  75. }
  76. export function getQuotaWithUnit(quota, digits = 6) {
  77. let quotaPerUnit = localStorage.getItem('quota_per_unit');
  78. quotaPerUnit = parseFloat(quotaPerUnit);
  79. return (quota / quotaPerUnit).toFixed(digits);
  80. }
  81. export function renderQuota(quota, digits = 2) {
  82. let quotaPerUnit = localStorage.getItem('quota_per_unit');
  83. let displayInCurrency = localStorage.getItem('display_in_currency');
  84. quotaPerUnit = parseFloat(quotaPerUnit);
  85. displayInCurrency = displayInCurrency === 'true';
  86. if (displayInCurrency) {
  87. return '$' + (quota / quotaPerUnit).toFixed(digits);
  88. }
  89. return renderNumber(quota);
  90. }
  91. export function renderQuotaWithPrompt(quota, digits) {
  92. let displayInCurrency = localStorage.getItem('display_in_currency');
  93. displayInCurrency = displayInCurrency === 'true';
  94. if (displayInCurrency) {
  95. return `(等价金额:${renderQuota(quota, digits)})`;
  96. }
  97. return '';
  98. }
  99. const colors = ['amber', 'blue', 'cyan', 'green', 'grey', 'indigo',
  100. 'light-blue', 'lime', 'orange', 'pink',
  101. 'purple', 'red', 'teal', 'violet', 'yellow'
  102. ]
  103. export const modelColorMap = {
  104. 'dall-e': 'rgb(147,112,219)', // 深紫色
  105. 'dall-e-2': 'rgb(147,112,219)', // 介于紫色和蓝色之间的色调
  106. 'dall-e-3': 'rgb(153,50,204)', // 介于紫罗兰和洋红之间的色调
  107. 'midjourney': 'rgb(136,43,180)', // 介于紫罗兰和洋红之间的色调
  108. 'gpt-3.5-turbo': 'rgb(184,227,167)', // 浅绿色
  109. 'gpt-3.5-turbo-0301': 'rgb(131,220,131)', // 亮绿色
  110. 'gpt-3.5-turbo-0613': 'rgb(60,179,113)', // 海洋绿
  111. 'gpt-3.5-turbo-1106': 'rgb(32,178,170)', // 浅海洋绿
  112. 'gpt-3.5-turbo-16k': 'rgb(252,200,149)', // 淡橙色
  113. 'gpt-3.5-turbo-16k-0613': 'rgb(255,181,119)', // 淡桃色
  114. 'gpt-3.5-turbo-instruct': 'rgb(175,238,238)', // 粉蓝色
  115. 'gpt-4': 'rgb(135,206,235)', // 天蓝色
  116. 'gpt-4-0314': 'rgb(70,130,180)', // 钢蓝色
  117. 'gpt-4-0613': 'rgb(100,149,237)', // 矢车菊蓝
  118. 'gpt-4-1106-preview': 'rgb(30,144,255)', // 道奇蓝
  119. 'gpt-4-0125-preview': 'rgb(2,177,236)', // 深天蓝
  120. 'gpt-4-turbo-preview': 'rgb(2,177,255)', // 深天蓝
  121. 'gpt-4-32k': 'rgb(104,111,238)', // 中紫色
  122. 'gpt-4-32k-0314': 'rgb(90,105,205)', // 暗灰蓝色
  123. 'gpt-4-32k-0613': 'rgb(61,71,139)', // 暗蓝灰色
  124. 'gpt-4-all': 'rgb(65,105,225)', // 皇家蓝
  125. 'gpt-4-gizmo-*': 'rgb(0,0,255)', // 纯蓝色
  126. 'gpt-4-vision-preview': 'rgb(25,25,112)', // 午夜蓝
  127. 'text-ada-001': 'rgb(255,192,203)', // 粉红色
  128. 'text-babbage-001': 'rgb(255,160,122)', // 浅珊瑚色
  129. 'text-curie-001': 'rgb(219,112,147)', // 苍紫罗兰色
  130. 'text-davinci-002': 'rgb(199,21,133)', // 中紫罗兰红色
  131. 'text-davinci-003': 'rgb(219,112,147)', // 苍紫罗兰色(与Curie相同,表示同一个系列)
  132. 'text-davinci-edit-001': 'rgb(255,105,180)', // 热粉色
  133. 'text-embedding-ada-002': 'rgb(255,182,193)', // 浅粉红
  134. 'text-embedding-v1': 'rgb(255,174,185)', // 浅粉红色(略有区别)
  135. 'text-moderation-latest': 'rgb(255,130,171)', // 强粉色
  136. 'text-moderation-stable': 'rgb(255,160,122)', // 浅珊瑚色(与Babbage相同,表示同一类功能)
  137. 'tts-1': 'rgb(255,140,0)', // 深橙色
  138. 'tts-1-1106': 'rgb(255,165,0)', // 橙色
  139. 'tts-1-hd': 'rgb(255,215,0)', // 金色
  140. 'tts-1-hd-1106': 'rgb(255,223,0)', // 金黄色(略有区别)
  141. 'whisper-1': 'rgb(245,245,220)' // 米色
  142. }
  143. export function stringToColor(str) {
  144. let sum = 0;
  145. // 对字符串中的每个字符进行操作
  146. for (let i = 0; i < str.length; i++) {
  147. // 将字符的ASCII值加到sum中
  148. sum += str.charCodeAt(i);
  149. }
  150. // 使用模运算得到个位数
  151. let i = sum % colors.length;
  152. return colors[i];
  153. }