You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Setting.js 22 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import {Tag, Tooltip, message} from "antd";
  15. import {SyncOutlined} from "@ant-design/icons";
  16. import {isMobile as isMobileDevice} from "react-device-detect";
  17. import i18next from "i18next";
  18. import Sdk from "casdoor-js-sdk";
  19. import FileSaver from "file-saver";
  20. import XLSX from "xlsx";
  21. import moment from "moment/moment";
  22. import * as StoreBackend from "./backend/StoreBackend";
  23. export let ServerUrl = "";
  24. export let CasdoorSdk;
  25. export function initServerUrl() {
  26. const hostname = window.location.hostname;
  27. if (hostname === "localhost") {
  28. ServerUrl = `http://${hostname}:14000`;
  29. }
  30. }
  31. export function initCasdoorSdk(config) {
  32. CasdoorSdk = new Sdk(config);
  33. }
  34. function getUrlWithLanguage(url) {
  35. if (url.includes("?")) {
  36. return `${url}&language=${getLanguage()}`;
  37. } else {
  38. return `${url}?language=${getLanguage()}`;
  39. }
  40. }
  41. export function getSignupUrl() {
  42. return getUrlWithLanguage(CasdoorSdk.getSignupUrl());
  43. }
  44. export function getSigninUrl() {
  45. return getUrlWithLanguage(CasdoorSdk.getSigninUrl());
  46. }
  47. export function getUserProfileUrl(userName, account) {
  48. return getUrlWithLanguage(CasdoorSdk.getUserProfileUrl(userName, account));
  49. }
  50. export function getMyProfileUrl(account) {
  51. return getUrlWithLanguage(CasdoorSdk.getMyProfileUrl(account));
  52. }
  53. export function signin() {
  54. return CasdoorSdk.signin(ServerUrl);
  55. }
  56. export function parseJson(s) {
  57. if (s === "") {
  58. return null;
  59. } else {
  60. return JSON.parse(s);
  61. }
  62. }
  63. export function myParseInt(i) {
  64. const res = parseInt(i);
  65. return isNaN(res) ? 0 : res;
  66. }
  67. export function openLink(link) {
  68. // this.props.history.push(link);
  69. const w = window.open("about:blank");
  70. w.location.href = link;
  71. }
  72. export function goToLink(link) {
  73. window.location.href = link;
  74. }
  75. export function goToLinkSoft(ths, link) {
  76. ths.props.history.push(link);
  77. }
  78. export function showMessage(type, text) {
  79. if (type === "") {
  80. return;
  81. } else if (type === "success") {
  82. message.success(text);
  83. } else if (type === "error") {
  84. message.error(text);
  85. }
  86. }
  87. export function isAdminUser(account) {
  88. if (account === undefined || account === null) {
  89. return false;
  90. }
  91. return account.owner === "built-in" || account.isGlobalAdmin === true;
  92. }
  93. export function isLocalAdminUser(account) {
  94. if (account === undefined || account === null) {
  95. return false;
  96. }
  97. return account.isAdmin === true || isAdminUser(account);
  98. }
  99. export function deepCopy(obj) {
  100. if (obj === null) {
  101. showMessage("error", "deepCopy obj is null.");
  102. }
  103. return Object.assign({}, obj);
  104. }
  105. export function insertRow(array, row, i) {
  106. return [...array.slice(0, i), row, ...array.slice(i)];
  107. }
  108. export function addRow(array, row) {
  109. return [...array, row];
  110. }
  111. export function prependRow(array, row) {
  112. return [row, ...array];
  113. }
  114. export function deleteRow(array, i) {
  115. // return array = array.slice(0, i).concat(array.slice(i + 1));
  116. return [...array.slice(0, i), ...array.slice(i + 1)];
  117. }
  118. export function swapRow(array, i, j) {
  119. return [...array.slice(0, i), array[j], ...array.slice(i + 1, j), array[i], ...array.slice(j + 1)];
  120. }
  121. export function trim(str, ch) {
  122. if (str === undefined) {
  123. return undefined;
  124. }
  125. let start = 0;
  126. let end = str.length;
  127. while (start < end && str[start] === ch) {++start;}
  128. while (end > start && str[end - 1] === ch) {--end;}
  129. return (start > 0 || end < str.length) ? str.substring(start, end) : str;
  130. }
  131. export function isMobile() {
  132. // return getIsMobileView();
  133. return isMobileDevice;
  134. }
  135. export function getFormattedDate(date) {
  136. if (date === undefined || date === null) {
  137. return null;
  138. }
  139. date = date.replace("T", " ");
  140. date = date.replace("+08:00", " ");
  141. return date;
  142. }
  143. export function getFormattedDateShort(date) {
  144. return date.slice(0, 10);
  145. }
  146. export function getShortName(s) {
  147. return s.split("/").slice(-1)[0];
  148. }
  149. export function getShortText(s, maxLength = 35) {
  150. if (s.length > maxLength) {
  151. return `${s.slice(0, maxLength)}...`;
  152. } else {
  153. return s;
  154. }
  155. }
  156. function getRandomInt(s) {
  157. let hash = 0;
  158. if (s.length !== 0) {
  159. for (let i = 0; i < s.length; i++) {
  160. const char = s.charCodeAt(i);
  161. hash = ((hash << 5) - hash) + char;
  162. hash = hash & hash;
  163. }
  164. }
  165. return hash;
  166. }
  167. export function getAvatarColor(s) {
  168. const colorList = ["#f56a00", "#7265e6", "#ffbf00", "#00a2ae"];
  169. let random = getRandomInt(s);
  170. if (random < 0) {
  171. random = -random;
  172. }
  173. return colorList[random % 4];
  174. }
  175. export function getLanguage() {
  176. return i18next.language;
  177. }
  178. export function setLanguage(language) {
  179. localStorage.setItem("language", language);
  180. i18next.changeLanguage(language);
  181. }
  182. export function changeLanguage(language) {
  183. setLanguage(language);
  184. window.location.reload(true);
  185. }
  186. export function getTag(text, type, state) {
  187. let icon = null;
  188. let style = {};
  189. if (state === "Pending") {
  190. icon = <SyncOutlined spin />;
  191. style = {borderStyle: "dashed", backgroundColor: "white"};
  192. }
  193. if (type === "Read") {
  194. return (
  195. <Tooltip placement="top" title={"Read"}>
  196. <Tag icon={icon} style={style} color={"success"}>
  197. {text}
  198. </Tag>
  199. </Tooltip>
  200. );
  201. } else if (type === "Write") {
  202. return (
  203. <Tooltip placement="top" title={"Write"}>
  204. <Tag icon={icon} style={style} color={"processing"}>
  205. {text}
  206. </Tag>
  207. </Tooltip>
  208. );
  209. } else if (type === "Admin") {
  210. return (
  211. <Tooltip placement="top" title={"Admin"}>
  212. <Tag icon={icon} style={style} color={"error"}>
  213. {text}
  214. </Tag>
  215. </Tooltip>
  216. );
  217. } else {
  218. return null;
  219. }
  220. }
  221. export function getTags(factors, type) {
  222. if (!factors) {
  223. return [];
  224. }
  225. if (type === "factors") {
  226. return getFactorTag(factors);
  227. } else if (type === "users") {
  228. return getUserTag(factors);
  229. }
  230. }
  231. function getFactorTag(factors) {
  232. const res = [];
  233. factors.forEach((factor, i) => {
  234. if (factor.data.length !== 0) {
  235. res.push(
  236. <Tooltip placement="top" title={getShortText(JSON.stringify(factor.data), 500)}>
  237. <Tag color={"success"}>
  238. {factor.name}
  239. </Tag>
  240. </Tooltip>
  241. );
  242. } else {
  243. res.push(
  244. <Tag color={"warning"}>
  245. {factor.name}
  246. </Tag>
  247. );
  248. }
  249. });
  250. return res;
  251. }
  252. function getUserTag(users) {
  253. const res = [];
  254. users.forEach((user, i) => {
  255. if (user.length !== 0) {
  256. res.push(
  257. <Tooltip placement="top" title={getShortText(JSON.stringify(user), 500)}>
  258. <Tag color={"success"}>
  259. {user}
  260. </Tag>
  261. </Tooltip>
  262. );
  263. } else {
  264. res.push(
  265. <Tag color={"warning"}>
  266. {user}
  267. </Tag>
  268. );
  269. }
  270. });
  271. return res;
  272. }
  273. export function getLabelTags(labels) {
  274. if (!labels) {
  275. return [];
  276. }
  277. const res = [];
  278. labels.forEach((label, i) => {
  279. res.push(
  280. <Tooltip placement="top" title={getShortText(JSON.stringify(label.text), 500)}>
  281. <Tag color={"processing"}>
  282. {`${label.startTime}: ${label.text !== "" ? label.text : "(Empty)"}`}
  283. </Tag>
  284. </Tooltip>
  285. );
  286. });
  287. return res;
  288. }
  289. export function getPercentage(f) {
  290. if (f === undefined) {
  291. return 0.0;
  292. }
  293. return (100 * f).toFixed(1);
  294. }
  295. function s2ab(s) {
  296. const buf = new ArrayBuffer(s.length);
  297. const view = new Uint8Array(buf);
  298. for (let i = 0; i !== s.length; i++) {
  299. view[i] = s.charCodeAt(i) & 0xFF;
  300. }
  301. return buf;
  302. }
  303. export function sheet2blob(sheet, sheetName) {
  304. const workbook = {
  305. SheetNames: [sheetName],
  306. Sheets: {},
  307. };
  308. workbook.Sheets[sheetName] = sheet;
  309. return workbook2blob(workbook);
  310. }
  311. export function workbook2blob(workbook) {
  312. const wopts = {
  313. bookType: "xlsx",
  314. bookSST: false,
  315. type: "binary",
  316. };
  317. const wbout = XLSX.write(workbook, wopts);
  318. return new Blob([s2ab(wbout)], {type: "application/octet-stream"});
  319. }
  320. export function downloadXlsx(wordset) {
  321. const data = [];
  322. wordset.factors.forEach((factor, i) => {
  323. const row = {};
  324. row[0] = factor.name;
  325. factor.data.forEach((dataItem, i) => {
  326. row[i + 1] = dataItem;
  327. });
  328. data.push(row);
  329. });
  330. const sheet = XLSX.utils.json_to_sheet(data, {skipHeader: true});
  331. // sheet["!cols"] = [
  332. // { wch: 18 },
  333. // { wch: 7 },
  334. // ];
  335. try {
  336. const blob = sheet2blob(sheet, "factors");
  337. const fileName = `factors-${wordset.name}.xlsx`;
  338. FileSaver.saveAs(blob, fileName);
  339. } catch (error) {
  340. showMessage("error", `failed to download: ${error.message}`);
  341. }
  342. }
  343. export function downloadLabels(table) {
  344. const data = [];
  345. table.forEach((label, i) => {
  346. const row = {};
  347. row[0] = label.startTime;
  348. row[1] = label.endTime;
  349. row[2] = label.text;
  350. data.push(row);
  351. });
  352. const sheet = XLSX.utils.json_to_sheet(data, {skipHeader: true});
  353. try {
  354. const blob = sheet2blob(sheet, "labels");
  355. const fileName = `labels-${this.props.video.name}-${table.length}.xlsx`;
  356. FileSaver.saveAs(blob, fileName);
  357. } catch (error) {
  358. showMessage("error", `failed to download: ${error.message}`);
  359. }
  360. }
  361. export const redirectCatchJsonError = async(url) => {
  362. try {
  363. const response = await fetch(url);
  364. const msg = await response.json();
  365. if (response.ok) {
  366. this.props.history.push(url);
  367. } else {
  368. showMessage("error", `error in redirect: ${msg}`);
  369. }
  370. } catch (error) {
  371. showMessage("error", `failed to redirect: ${error.message}`);
  372. }
  373. };
  374. export function toFixed(f, n) {
  375. return parseFloat(f.toFixed(n));
  376. }
  377. export function getRandomName() {
  378. return Math.random().toString(36).slice(-6);
  379. }
  380. export function getFriendlyFileSize(size) {
  381. if (size < 1024) {
  382. return size + " B";
  383. }
  384. const i = Math.floor(Math.log(size) / Math.log(1024));
  385. let num = (size / Math.pow(1024, i));
  386. const round = Math.round(num);
  387. num = round < 10 ? num.toFixed(2) : round < 100 ? num.toFixed(1) : round;
  388. return `${num} ${"KMGTPEZY"[i - 1]}B`;
  389. }
  390. export function getTreeWithParents(tree) {
  391. const res = deepCopy(tree);
  392. res.children = tree.children.map((file, index) => {
  393. file.parent = tree;
  394. return getTreeWithParents(file);
  395. });
  396. return res;
  397. }
  398. export function getTreeWithSearch(tree, s) {
  399. const res = deepCopy(tree);
  400. res.children = tree.children.map((file, index) => {
  401. if (file.children.length === 0) {
  402. if (file.title.includes(s)) {
  403. return file;
  404. } else {
  405. return null;
  406. }
  407. } else {
  408. const tmpTree = getTreeWithSearch(file, s);
  409. if (tmpTree.children.length !== 0) {
  410. return tmpTree;
  411. } else {
  412. if (file.title.includes(s)) {
  413. return file;
  414. } else {
  415. return null;
  416. }
  417. }
  418. }
  419. }).filter((file, index) => {
  420. return file !== null;
  421. });
  422. return res;
  423. }
  424. export function getExtFromPath(path) {
  425. const filename = path.split("/").pop();
  426. if (filename.includes(".")) {
  427. return filename.split(".").pop().toLowerCase();
  428. } else {
  429. return "";
  430. }
  431. }
  432. export function getExtFromFile(file) {
  433. const res = file.title.split(".")[1];
  434. if (res === undefined) {
  435. return "";
  436. } else {
  437. return res;
  438. }
  439. }
  440. export function getFileCategory(file) {
  441. if (file.isLeaf) {
  442. return i18next.t("store:File");
  443. } else {
  444. return i18next.t("store:Folder");
  445. }
  446. }
  447. export function getDistinctArray(arr) {
  448. return [...new Set(arr)];
  449. }
  450. export function getCollectedTime(filename) {
  451. // 20220827_210300_CH~Logo.png
  452. const tokens = filename.split("~");
  453. if (tokens.length < 2) {
  454. return null;
  455. }
  456. const time = tokens[0].slice(0, -3);
  457. const m = new moment(time, "YYYYMMDD_HH:mm:ss");
  458. return m.format();
  459. }
  460. export function getSubject(filename) {
  461. // 20220827_210300_CH~Logo.png
  462. const tokens = filename.split("~");
  463. if (tokens.length < 2) {
  464. return null;
  465. }
  466. const subject = tokens[0].slice(tokens[0].length - 2);
  467. if (subject === "MA") {
  468. return i18next.t("store:Math");
  469. } else if (subject === "CH") {
  470. return i18next.t("store:Chinese");
  471. } else if (subject === "NU") {
  472. return null;
  473. } else {
  474. return subject;
  475. }
  476. }
  477. export function submitStoreEdit(storeObj) {
  478. const store = deepCopy(storeObj);
  479. store.fileTree = undefined;
  480. StoreBackend.updateStore(storeObj.owner, storeObj.name, store)
  481. .then((res) => {
  482. if (res.status === "ok") {
  483. if (res.data) {
  484. showMessage("success", "Successfully saved");
  485. } else {
  486. showMessage("error", "failed to save: server side failure");
  487. }
  488. } else {
  489. showMessage("error", `failed to save: ${res.msg}`);
  490. }
  491. })
  492. .catch(error => {
  493. showMessage("error", `failed to save: ${error}`);
  494. });
  495. }
  496. export const StaticBaseUrl = "https://cdn.casbin.org";
  497. export const Countries = [{label: "English", key: "en", country: "US", alt: "English"},
  498. {label: "中文", key: "zh", country: "CN", alt: "中文"},
  499. {label: "Español", key: "es", country: "ES", alt: "Español"},
  500. {label: "Français", key: "fr", country: "FR", alt: "Français"},
  501. {label: "Deutsch", key: "de", country: "DE", alt: "Deutsch"},
  502. {label: "Indonesia", key: "id", country: "ID", alt: "Indonesia"},
  503. {label: "日本語", key: "ja", country: "JP", alt: "日本語"},
  504. {label: "한국어", key: "ko", country: "KR", alt: "한국어"},
  505. {label: "Русский", key: "ru", country: "RU", alt: "Русский"},
  506. ];
  507. export function getItem(label, key, icon, children, type) {
  508. return {
  509. key,
  510. icon,
  511. children,
  512. label,
  513. type,
  514. };
  515. }
  516. export function getOption(label, value) {
  517. return {
  518. label,
  519. value,
  520. };
  521. }
  522. export function scrollToDiv(divId) {
  523. if (divId) {
  524. const ele = document.getElementById(divId);
  525. if (ele) {
  526. ele.scrollIntoView({behavior: "smooth"});
  527. }
  528. }
  529. }
  530. export function renderExternalLink() {
  531. return (
  532. <svg style={{marginLeft: "5px"}} width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" className="iconExternalLink_nPIU">
  533. <path fill="currentColor"
  534. d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path>
  535. </svg>
  536. );
  537. }
  538. export function isResponseDenied(data) {
  539. return data.msg === "Unauthorized operation";
  540. }
  541. export function getProviderTypeOptions(category) {
  542. if (category === "Storage") {
  543. return (
  544. [
  545. {id: "Local File System", name: "Local File System"},
  546. ]
  547. );
  548. } else if (category === "Model") {
  549. return (
  550. [
  551. {id: "OpenAI", name: "OpenAI"},
  552. {id: "Hugging Face", name: "Hugging Face"},
  553. {id: "OpenRouter", name: "OpenRouter"},
  554. {id: "Ernie", name: "Ernie"},
  555. {id: "iFlytek", name: "iFlytek"},
  556. ]
  557. );
  558. } else if (category === "Embedding") {
  559. return (
  560. [
  561. {id: "OpenAI", name: "OpenAI"},
  562. {id: "Hugging Face", name: "Hugging Face"},
  563. {id: "Cohere", name: "Cohere"},
  564. {id: "Ernie", name: "Ernie"},
  565. ]
  566. );
  567. } else {
  568. return [];
  569. }
  570. }
  571. export function getProviderSubTypeOptions(category, type) {
  572. if (type === "OpenAI") {
  573. if (category === "Model") {
  574. return (
  575. [
  576. {id: "gpt-4-32k-0613", name: "gpt-4-32k-0613"},
  577. {id: "gpt-4-32k-0314", name: "gpt-4-32k-0314"},
  578. {id: "gpt-4-32k", name: "gpt-4-32k"},
  579. {id: "gpt-4-0613", name: "gpt-4-0613"},
  580. {id: "gpt-4-0314", name: "gpt-4-0314"},
  581. {id: "gpt-4", name: "gpt-4"},
  582. {id: "gpt-3.5-turbo-0613", name: "gpt-3.5-turbo-0613"},
  583. {id: "gpt-3.5-turbo-0301", name: "gpt-3.5-turbo-0301"},
  584. {id: "gpt-3.5-turbo-16k", name: "gpt-3.5-turbo-16k"},
  585. {id: "gpt-3.5-turbo-16k-0613", name: "gpt-3.5-turbo-16k-0613"},
  586. {id: "gpt-3.5-turbo", name: "gpt-3.5-turbo"},
  587. {id: "text-davinci-003", name: "text-davinci-003"},
  588. {id: "text-davinci-002", name: "text-davinci-002"},
  589. {id: "text-curie-001", name: "text-curie-001"},
  590. {id: "text-babbage-001", name: "text-babbage-001"},
  591. {id: "text-ada-001", name: "text-ada-001"},
  592. {id: "text-davinci-001", name: "text-davinci-001"},
  593. {id: "davinci-instruct-beta", name: "davinci-instruct-beta"},
  594. {id: "davinci", name: "davinci"},
  595. {id: "curie-instruct-beta", name: "curie-instruct-beta"},
  596. {id: "curie", name: "curie"},
  597. {id: "ada", name: "ada"},
  598. {id: "babbage", name: "babbage"},
  599. ]
  600. );
  601. } else if (category === "Embedding") {
  602. return (
  603. [
  604. {id: "1", name: "AdaSimilarity"},
  605. {id: "2", name: "BabbageSimilarity"},
  606. {id: "3", name: "CurieSimilarity"},
  607. {id: "4", name: "DavinciSimilarity"},
  608. {id: "5", name: "AdaSearchDocument"},
  609. {id: "6", name: "AdaSearchQuery"},
  610. {id: "7", name: "BabbageSearchDocument"},
  611. {id: "8", name: "BabbageSearchQuery"},
  612. {id: "9", name: "CurieSearchDocument"},
  613. {id: "10", name: "CurieSearchQuery"},
  614. {id: "11", name: "DavinciSearchDocument"},
  615. {id: "12", name: "DavinciSearchQuery"},
  616. {id: "13", name: "AdaCodeSearchCode"},
  617. {id: "14", name: "AdaCodeSearchText"},
  618. {id: "15", name: "BabbageCodeSearchCode"},
  619. {id: "16", name: "BabbageCodeSearchText"},
  620. {id: "17", name: "AdaEmbeddingV2"},
  621. ]
  622. );
  623. } else {
  624. return [];
  625. }
  626. } else if (type === "Hugging Face") {
  627. if (category === "Model") {
  628. return (
  629. [
  630. {id: "meta-llama/Llama-2-7b", name: "meta-llama/Llama-2-7b"},
  631. {id: "tiiuae/falcon-180B", name: "tiiuae/falcon-180B"},
  632. {id: "bigscience/bloom", name: "bigscience/bloom"},
  633. {id: "gpt2", name: "gpt2"},
  634. {id: "baichuan-inc/Baichuan2-13B-Chat", name: "baichuan-inc/Baichuan2-13B-Chat"},
  635. {id: "THUDM/chatglm2-6b", name: "THUDM/chatglm2-6b"},
  636. ]
  637. );
  638. } else if (category === "Embedding") {
  639. return (
  640. [
  641. {id: "sentence-transformers/all-MiniLM-L6-v2", name: "sentence-transformers/all-MiniLM-L6-v2"},
  642. ]
  643. );
  644. } else {
  645. return [];
  646. }
  647. } else if (type === "OpenRouter") {
  648. return (
  649. [
  650. {id: "google/palm-2-codechat-bison", name: "google/palm-2-codechat-bison"},
  651. {id: "google/palm-2-chat-bison", name: "google/palm-2-chat-bison"},
  652. {id: "openai/gpt-3.5-turbo", name: "openai/gpt-3.5-turbo"},
  653. {id: "openai/gpt-3.5-turbo-16k", name: "openai/gpt-3.5-turbo-16k"},
  654. {id: "openai/gpt-4", name: "openai/gpt-4"},
  655. {id: "openai/gpt-4-32k", name: "openai/gpt-4-32k"},
  656. {id: "anthropic/claude-2", name: "anthropic/claude-2"},
  657. {id: "anthropic/claude-instant-v1", name: "anthropic/claude-instant-v1"},
  658. {id: "meta-llama/llama-2-13b-chat", name: "meta-llama/llama-2-13b-chat"},
  659. {id: "meta-llama/llama-2-70b-chat", name: "meta-llama/llama-2-70b-chat"},
  660. {id: "palm-2-codechat-bison", name: "palm-2-codechat-bison"},
  661. {id: "palm-2-chat-bison", name: "palm-2-chat-bison"},
  662. {id: "gpt-3.5-turbo", name: "gpt-3.5-turbo"},
  663. {id: "gpt-3.5-turbo-16k", name: "gpt-3.5-turbo-16k"},
  664. {id: "gpt-4", name: "gpt-4"},
  665. {id: "gpt-4-32k", name: "gpt-4-32k"},
  666. {id: "claude-2", name: "claude-2"},
  667. {id: "claude-instant-v1", name: "claude-instant-v1"},
  668. {id: "llama-2-13b-chat", name: "llama-2-13b-chat"},
  669. {id: "llama-2-70b-chat", name: "llama-2-70b-chat"},
  670. ]
  671. );
  672. } else if (type === "Ernie") {
  673. if (category === "Model") {
  674. return (
  675. [
  676. {id: "ERNIE-Bot", name: "ERNIE-Bot"},
  677. {id: "ERNIE-Bot-turbo", name: "ERNIE-Bot-turbo"},
  678. {id: "BLOOMZ-7B", name: "BLOOMZ-7B"},
  679. {id: "Llama-2", name: "Llama-2"},
  680. ]
  681. );
  682. } else if (category === "Embedding") {
  683. return (
  684. [
  685. {id: "default", name: "default"},
  686. ]
  687. );
  688. } else {
  689. return [];
  690. }
  691. } else if (type === "Cohere") {
  692. return (
  693. [
  694. {id: "embed-english-v2.0", name: "embed-english-v2.0"},
  695. {id: "embed-english-light-v2.0", name: "embed-english-light-v2.0"},
  696. {id: "embed-multilingual-v2.0", name: "embed-multilingual-v2.0"},
  697. ]
  698. );
  699. } else if (type === "iFlytek") {
  700. return (
  701. [
  702. {id: "spark-v1.5", name: "spark-v1.5"},
  703. {id: "spark-v2.0", name: "spark-v2.0"},
  704. ]
  705. );
  706. } else {
  707. return [];
  708. }
  709. }