index.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
  2. export const getModels = async (token: string = '') => {
  3. let error = null;
  4. const res = await fetch(`${WEBUI_BASE_URL}/api/models`, {
  5. method: 'GET',
  6. headers: {
  7. Accept: 'application/json',
  8. 'Content-Type': 'application/json',
  9. ...(token && { authorization: `Bearer ${token}` })
  10. }
  11. })
  12. .then(async (res) => {
  13. if (!res.ok) throw await res.json();
  14. return res.json();
  15. })
  16. .catch((err) => {
  17. console.log(err);
  18. error = err;
  19. return null;
  20. });
  21. if (error) {
  22. throw error;
  23. }
  24. let models = res?.data ?? [];
  25. models = models
  26. .filter((models) => models)
  27. // Sort the models
  28. .sort((a, b) => {
  29. // Check if models have position property
  30. const aHasPosition = a.info?.meta?.position !== undefined;
  31. const bHasPosition = b.info?.meta?.position !== undefined;
  32. // If both a and b have the position property
  33. if (aHasPosition && bHasPosition) {
  34. return a.info.meta.position - b.info.meta.position;
  35. }
  36. // If only a has the position property, it should come first
  37. if (aHasPosition) return -1;
  38. // If only b has the position property, it should come first
  39. if (bHasPosition) return 1;
  40. // Compare case-insensitively by name for models without position property
  41. const lowerA = a.name.toLowerCase();
  42. const lowerB = b.name.toLowerCase();
  43. if (lowerA < lowerB) return -1;
  44. if (lowerA > lowerB) return 1;
  45. // If same case-insensitively, sort by original strings,
  46. // lowercase will come before uppercase due to ASCII values
  47. if (a.name < b.name) return -1;
  48. if (a.name > b.name) return 1;
  49. return 0; // They are equal
  50. });
  51. console.log(models);
  52. return models;
  53. };
  54. type ChatCompletedForm = {
  55. model: string;
  56. messages: string[];
  57. chat_id: string;
  58. };
  59. export const chatCompleted = async (token: string, body: ChatCompletedForm) => {
  60. let error = null;
  61. const res = await fetch(`${WEBUI_BASE_URL}/api/chat/completed`, {
  62. method: 'POST',
  63. headers: {
  64. Accept: 'application/json',
  65. 'Content-Type': 'application/json',
  66. ...(token && { authorization: `Bearer ${token}` })
  67. },
  68. body: JSON.stringify(body)
  69. })
  70. .then(async (res) => {
  71. if (!res.ok) throw await res.json();
  72. return res.json();
  73. })
  74. .catch((err) => {
  75. console.log(err);
  76. if ('detail' in err) {
  77. error = err.detail;
  78. } else {
  79. error = err;
  80. }
  81. return null;
  82. });
  83. if (error) {
  84. throw error;
  85. }
  86. return res;
  87. };
  88. type ChatActionForm = {
  89. model: string;
  90. messages: string[];
  91. chat_id: string;
  92. };
  93. export const chatAction = async (token: string, action_id: string, body: ChatActionForm) => {
  94. let error = null;
  95. const res = await fetch(`${WEBUI_BASE_URL}/api/chat/actions/${action_id}`, {
  96. method: 'POST',
  97. headers: {
  98. Accept: 'application/json',
  99. 'Content-Type': 'application/json',
  100. ...(token && { authorization: `Bearer ${token}` })
  101. },
  102. body: JSON.stringify(body)
  103. })
  104. .then(async (res) => {
  105. if (!res.ok) throw await res.json();
  106. return res.json();
  107. })
  108. .catch((err) => {
  109. console.log(err);
  110. if ('detail' in err) {
  111. error = err.detail;
  112. } else {
  113. error = err;
  114. }
  115. return null;
  116. });
  117. if (error) {
  118. throw error;
  119. }
  120. return res;
  121. };
  122. export const getTaskConfig = async (token: string = '') => {
  123. let error = null;
  124. const res = await fetch(`${WEBUI_BASE_URL}/api/task/config`, {
  125. method: 'GET',
  126. headers: {
  127. Accept: 'application/json',
  128. 'Content-Type': 'application/json',
  129. ...(token && { authorization: `Bearer ${token}` })
  130. }
  131. })
  132. .then(async (res) => {
  133. if (!res.ok) throw await res.json();
  134. return res.json();
  135. })
  136. .catch((err) => {
  137. console.log(err);
  138. error = err;
  139. return null;
  140. });
  141. if (error) {
  142. throw error;
  143. }
  144. return res;
  145. };
  146. export const updateTaskConfig = async (token: string, config: object) => {
  147. let error = null;
  148. const res = await fetch(`${WEBUI_BASE_URL}/api/task/config/update`, {
  149. method: 'POST',
  150. headers: {
  151. Accept: 'application/json',
  152. 'Content-Type': 'application/json',
  153. ...(token && { authorization: `Bearer ${token}` })
  154. },
  155. body: JSON.stringify(config)
  156. })
  157. .then(async (res) => {
  158. if (!res.ok) throw await res.json();
  159. return res.json();
  160. })
  161. .catch((err) => {
  162. console.log(err);
  163. if ('detail' in err) {
  164. error = err.detail;
  165. } else {
  166. error = err;
  167. }
  168. return null;
  169. });
  170. if (error) {
  171. throw error;
  172. }
  173. return res;
  174. };
  175. export const generateTitle = async (
  176. token: string = '',
  177. model: string,
  178. prompt: string,
  179. chat_id?: string
  180. ) => {
  181. let error = null;
  182. const res = await fetch(`${WEBUI_BASE_URL}/api/task/title/completions`, {
  183. method: 'POST',
  184. headers: {
  185. Accept: 'application/json',
  186. 'Content-Type': 'application/json',
  187. Authorization: `Bearer ${token}`
  188. },
  189. body: JSON.stringify({
  190. model: model,
  191. prompt: prompt,
  192. ...(chat_id && { chat_id: chat_id })
  193. })
  194. })
  195. .then(async (res) => {
  196. if (!res.ok) throw await res.json();
  197. return res.json();
  198. })
  199. .catch((err) => {
  200. console.log(err);
  201. if ('detail' in err) {
  202. error = err.detail;
  203. }
  204. return null;
  205. });
  206. if (error) {
  207. throw error;
  208. }
  209. return res?.choices[0]?.message?.content.replace(/["']/g, '') ?? 'New Chat';
  210. };
  211. export const generateEmoji = async (
  212. token: string = '',
  213. model: string,
  214. prompt: string,
  215. chat_id?: string
  216. ) => {
  217. let error = null;
  218. const res = await fetch(`${WEBUI_BASE_URL}/api/task/emoji/completions`, {
  219. method: 'POST',
  220. headers: {
  221. Accept: 'application/json',
  222. 'Content-Type': 'application/json',
  223. Authorization: `Bearer ${token}`
  224. },
  225. body: JSON.stringify({
  226. model: model,
  227. prompt: prompt,
  228. ...(chat_id && { chat_id: chat_id })
  229. })
  230. })
  231. .then(async (res) => {
  232. if (!res.ok) throw await res.json();
  233. return res.json();
  234. })
  235. .catch((err) => {
  236. console.log(err);
  237. if ('detail' in err) {
  238. error = err.detail;
  239. }
  240. return null;
  241. });
  242. if (error) {
  243. throw error;
  244. }
  245. const response = res?.choices[0]?.message?.content.replace(/["']/g, '') ?? null;
  246. if (response) {
  247. if (/\p{Extended_Pictographic}/u.test(response)) {
  248. return response.match(/\p{Extended_Pictographic}/gu)[0];
  249. }
  250. }
  251. return null;
  252. };
  253. export const generateSearchQuery = async (
  254. token: string = '',
  255. model: string,
  256. messages: object[],
  257. prompt: string
  258. ) => {
  259. let error = null;
  260. const res = await fetch(`${WEBUI_BASE_URL}/api/task/query/completions`, {
  261. method: 'POST',
  262. headers: {
  263. Accept: 'application/json',
  264. 'Content-Type': 'application/json',
  265. Authorization: `Bearer ${token}`
  266. },
  267. body: JSON.stringify({
  268. model: model,
  269. messages: messages,
  270. prompt: prompt
  271. })
  272. })
  273. .then(async (res) => {
  274. if (!res.ok) throw await res.json();
  275. return res.json();
  276. })
  277. .catch((err) => {
  278. console.log(err);
  279. if ('detail' in err) {
  280. error = err.detail;
  281. }
  282. return null;
  283. });
  284. if (error) {
  285. throw error;
  286. }
  287. return res?.choices[0]?.message?.content.replace(/["']/g, '') ?? prompt;
  288. };
  289. export const getPipelinesList = async (token: string = '') => {
  290. let error = null;
  291. const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/list`, {
  292. method: 'GET',
  293. headers: {
  294. Accept: 'application/json',
  295. 'Content-Type': 'application/json',
  296. ...(token && { authorization: `Bearer ${token}` })
  297. }
  298. })
  299. .then(async (res) => {
  300. if (!res.ok) throw await res.json();
  301. return res.json();
  302. })
  303. .catch((err) => {
  304. console.log(err);
  305. error = err;
  306. return null;
  307. });
  308. if (error) {
  309. throw error;
  310. }
  311. let pipelines = res?.data ?? [];
  312. return pipelines;
  313. };
  314. export const uploadPipeline = async (token: string, file: File, urlIdx: string) => {
  315. let error = null;
  316. // Create a new FormData object to handle the file upload
  317. const formData = new FormData();
  318. formData.append('file', file);
  319. formData.append('urlIdx', urlIdx);
  320. const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/upload`, {
  321. method: 'POST',
  322. headers: {
  323. ...(token && { authorization: `Bearer ${token}` })
  324. // 'Content-Type': 'multipart/form-data' is not needed as Fetch API will set it automatically
  325. },
  326. body: formData
  327. })
  328. .then(async (res) => {
  329. if (!res.ok) throw await res.json();
  330. return res.json();
  331. })
  332. .catch((err) => {
  333. console.log(err);
  334. if ('detail' in err) {
  335. error = err.detail;
  336. } else {
  337. error = err;
  338. }
  339. return null;
  340. });
  341. if (error) {
  342. throw error;
  343. }
  344. return res;
  345. };
  346. export const downloadPipeline = async (token: string, url: string, urlIdx: string) => {
  347. let error = null;
  348. const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/add`, {
  349. method: 'POST',
  350. headers: {
  351. Accept: 'application/json',
  352. 'Content-Type': 'application/json',
  353. ...(token && { authorization: `Bearer ${token}` })
  354. },
  355. body: JSON.stringify({
  356. url: url,
  357. urlIdx: urlIdx
  358. })
  359. })
  360. .then(async (res) => {
  361. if (!res.ok) throw await res.json();
  362. return res.json();
  363. })
  364. .catch((err) => {
  365. console.log(err);
  366. if ('detail' in err) {
  367. error = err.detail;
  368. } else {
  369. error = err;
  370. }
  371. return null;
  372. });
  373. if (error) {
  374. throw error;
  375. }
  376. return res;
  377. };
  378. export const deletePipeline = async (token: string, id: string, urlIdx: string) => {
  379. let error = null;
  380. const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/delete`, {
  381. method: 'DELETE',
  382. headers: {
  383. Accept: 'application/json',
  384. 'Content-Type': 'application/json',
  385. ...(token && { authorization: `Bearer ${token}` })
  386. },
  387. body: JSON.stringify({
  388. id: id,
  389. urlIdx: urlIdx
  390. })
  391. })
  392. .then(async (res) => {
  393. if (!res.ok) throw await res.json();
  394. return res.json();
  395. })
  396. .catch((err) => {
  397. console.log(err);
  398. if ('detail' in err) {
  399. error = err.detail;
  400. } else {
  401. error = err;
  402. }
  403. return null;
  404. });
  405. if (error) {
  406. throw error;
  407. }
  408. return res;
  409. };
  410. export const getPipelines = async (token: string, urlIdx?: string) => {
  411. let error = null;
  412. const searchParams = new URLSearchParams();
  413. if (urlIdx !== undefined) {
  414. searchParams.append('urlIdx', urlIdx);
  415. }
  416. const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines?${searchParams.toString()}`, {
  417. method: 'GET',
  418. headers: {
  419. Accept: 'application/json',
  420. 'Content-Type': 'application/json',
  421. ...(token && { authorization: `Bearer ${token}` })
  422. }
  423. })
  424. .then(async (res) => {
  425. if (!res.ok) throw await res.json();
  426. return res.json();
  427. })
  428. .catch((err) => {
  429. console.log(err);
  430. error = err;
  431. return null;
  432. });
  433. if (error) {
  434. throw error;
  435. }
  436. let pipelines = res?.data ?? [];
  437. return pipelines;
  438. };
  439. export const getPipelineValves = async (token: string, pipeline_id: string, urlIdx: string) => {
  440. let error = null;
  441. const searchParams = new URLSearchParams();
  442. if (urlIdx !== undefined) {
  443. searchParams.append('urlIdx', urlIdx);
  444. }
  445. const res = await fetch(
  446. `${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves?${searchParams.toString()}`,
  447. {
  448. method: 'GET',
  449. headers: {
  450. Accept: 'application/json',
  451. 'Content-Type': 'application/json',
  452. ...(token && { authorization: `Bearer ${token}` })
  453. }
  454. }
  455. )
  456. .then(async (res) => {
  457. if (!res.ok) throw await res.json();
  458. return res.json();
  459. })
  460. .catch((err) => {
  461. console.log(err);
  462. error = err;
  463. return null;
  464. });
  465. if (error) {
  466. throw error;
  467. }
  468. return res;
  469. };
  470. export const getPipelineValvesSpec = async (token: string, pipeline_id: string, urlIdx: string) => {
  471. let error = null;
  472. const searchParams = new URLSearchParams();
  473. if (urlIdx !== undefined) {
  474. searchParams.append('urlIdx', urlIdx);
  475. }
  476. const res = await fetch(
  477. `${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves/spec?${searchParams.toString()}`,
  478. {
  479. method: 'GET',
  480. headers: {
  481. Accept: 'application/json',
  482. 'Content-Type': 'application/json',
  483. ...(token && { authorization: `Bearer ${token}` })
  484. }
  485. }
  486. )
  487. .then(async (res) => {
  488. if (!res.ok) throw await res.json();
  489. return res.json();
  490. })
  491. .catch((err) => {
  492. console.log(err);
  493. error = err;
  494. return null;
  495. });
  496. if (error) {
  497. throw error;
  498. }
  499. return res;
  500. };
  501. export const updatePipelineValves = async (
  502. token: string = '',
  503. pipeline_id: string,
  504. valves: object,
  505. urlIdx: string
  506. ) => {
  507. let error = null;
  508. const searchParams = new URLSearchParams();
  509. if (urlIdx !== undefined) {
  510. searchParams.append('urlIdx', urlIdx);
  511. }
  512. const res = await fetch(
  513. `${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves/update?${searchParams.toString()}`,
  514. {
  515. method: 'POST',
  516. headers: {
  517. Accept: 'application/json',
  518. 'Content-Type': 'application/json',
  519. ...(token && { authorization: `Bearer ${token}` })
  520. },
  521. body: JSON.stringify(valves)
  522. }
  523. )
  524. .then(async (res) => {
  525. if (!res.ok) throw await res.json();
  526. return res.json();
  527. })
  528. .catch((err) => {
  529. console.log(err);
  530. if ('detail' in err) {
  531. error = err.detail;
  532. } else {
  533. error = err;
  534. }
  535. return null;
  536. });
  537. if (error) {
  538. throw error;
  539. }
  540. return res;
  541. };
  542. export const getBackendConfig = async () => {
  543. let error = null;
  544. const res = await fetch(`${WEBUI_BASE_URL}/api/config`, {
  545. method: 'GET',
  546. headers: {
  547. 'Content-Type': 'application/json'
  548. }
  549. })
  550. .then(async (res) => {
  551. if (!res.ok) throw await res.json();
  552. return res.json();
  553. })
  554. .catch((err) => {
  555. console.log(err);
  556. error = err;
  557. return null;
  558. });
  559. if (error) {
  560. throw error;
  561. }
  562. return res;
  563. };
  564. export const getChangelog = async () => {
  565. let error = null;
  566. const res = await fetch(`${WEBUI_BASE_URL}/api/changelog`, {
  567. method: 'GET',
  568. headers: {
  569. 'Content-Type': 'application/json'
  570. }
  571. })
  572. .then(async (res) => {
  573. if (!res.ok) throw await res.json();
  574. return res.json();
  575. })
  576. .catch((err) => {
  577. console.log(err);
  578. error = err;
  579. return null;
  580. });
  581. if (error) {
  582. throw error;
  583. }
  584. return res;
  585. };
  586. export const getVersionUpdates = async () => {
  587. let error = null;
  588. const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, {
  589. method: 'GET',
  590. headers: {
  591. 'Content-Type': 'application/json'
  592. }
  593. })
  594. .then(async (res) => {
  595. if (!res.ok) throw await res.json();
  596. return res.json();
  597. })
  598. .catch((err) => {
  599. console.log(err);
  600. error = err;
  601. return null;
  602. });
  603. if (error) {
  604. throw error;
  605. }
  606. return res;
  607. };
  608. export const getModelFilterConfig = async (token: string) => {
  609. let error = null;
  610. const res = await fetch(`${WEBUI_BASE_URL}/api/config/model/filter`, {
  611. method: 'GET',
  612. headers: {
  613. 'Content-Type': 'application/json',
  614. Authorization: `Bearer ${token}`
  615. }
  616. })
  617. .then(async (res) => {
  618. if (!res.ok) throw await res.json();
  619. return res.json();
  620. })
  621. .catch((err) => {
  622. console.log(err);
  623. error = err;
  624. return null;
  625. });
  626. if (error) {
  627. throw error;
  628. }
  629. return res;
  630. };
  631. export const updateModelFilterConfig = async (
  632. token: string,
  633. enabled: boolean,
  634. models: string[]
  635. ) => {
  636. let error = null;
  637. const res = await fetch(`${WEBUI_BASE_URL}/api/config/model/filter`, {
  638. method: 'POST',
  639. headers: {
  640. 'Content-Type': 'application/json',
  641. Authorization: `Bearer ${token}`
  642. },
  643. body: JSON.stringify({
  644. enabled: enabled,
  645. models: models
  646. })
  647. })
  648. .then(async (res) => {
  649. if (!res.ok) throw await res.json();
  650. return res.json();
  651. })
  652. .catch((err) => {
  653. console.log(err);
  654. error = err;
  655. return null;
  656. });
  657. if (error) {
  658. throw error;
  659. }
  660. return res;
  661. };
  662. export const getWebhookUrl = async (token: string) => {
  663. let error = null;
  664. const res = await fetch(`${WEBUI_BASE_URL}/api/webhook`, {
  665. method: 'GET',
  666. headers: {
  667. 'Content-Type': 'application/json',
  668. Authorization: `Bearer ${token}`
  669. }
  670. })
  671. .then(async (res) => {
  672. if (!res.ok) throw await res.json();
  673. return res.json();
  674. })
  675. .catch((err) => {
  676. console.log(err);
  677. error = err;
  678. return null;
  679. });
  680. if (error) {
  681. throw error;
  682. }
  683. return res.url;
  684. };
  685. export const updateWebhookUrl = async (token: string, url: string) => {
  686. let error = null;
  687. const res = await fetch(`${WEBUI_BASE_URL}/api/webhook`, {
  688. method: 'POST',
  689. headers: {
  690. 'Content-Type': 'application/json',
  691. Authorization: `Bearer ${token}`
  692. },
  693. body: JSON.stringify({
  694. url: url
  695. })
  696. })
  697. .then(async (res) => {
  698. if (!res.ok) throw await res.json();
  699. return res.json();
  700. })
  701. .catch((err) => {
  702. console.log(err);
  703. error = err;
  704. return null;
  705. });
  706. if (error) {
  707. throw error;
  708. }
  709. return res.url;
  710. };
  711. export const getCommunitySharingEnabledStatus = async (token: string) => {
  712. let error = null;
  713. const res = await fetch(`${WEBUI_BASE_URL}/api/community_sharing`, {
  714. method: 'GET',
  715. headers: {
  716. 'Content-Type': 'application/json',
  717. Authorization: `Bearer ${token}`
  718. }
  719. })
  720. .then(async (res) => {
  721. if (!res.ok) throw await res.json();
  722. return res.json();
  723. })
  724. .catch((err) => {
  725. console.log(err);
  726. error = err;
  727. return null;
  728. });
  729. if (error) {
  730. throw error;
  731. }
  732. return res;
  733. };
  734. export const toggleCommunitySharingEnabledStatus = async (token: string) => {
  735. let error = null;
  736. const res = await fetch(`${WEBUI_BASE_URL}/api/community_sharing/toggle`, {
  737. method: 'GET',
  738. headers: {
  739. 'Content-Type': 'application/json',
  740. Authorization: `Bearer ${token}`
  741. }
  742. })
  743. .then(async (res) => {
  744. if (!res.ok) throw await res.json();
  745. return res.json();
  746. })
  747. .catch((err) => {
  748. console.log(err);
  749. error = err.detail;
  750. return null;
  751. });
  752. if (error) {
  753. throw error;
  754. }
  755. return res;
  756. };
  757. export const getModelConfig = async (token: string): Promise<GlobalModelConfig> => {
  758. let error = null;
  759. const res = await fetch(`${WEBUI_BASE_URL}/api/config/models`, {
  760. method: 'GET',
  761. headers: {
  762. 'Content-Type': 'application/json',
  763. Authorization: `Bearer ${token}`
  764. }
  765. })
  766. .then(async (res) => {
  767. if (!res.ok) throw await res.json();
  768. return res.json();
  769. })
  770. .catch((err) => {
  771. console.log(err);
  772. error = err;
  773. return null;
  774. });
  775. if (error) {
  776. throw error;
  777. }
  778. return res.models;
  779. };
  780. export interface ModelConfig {
  781. id: string;
  782. name: string;
  783. meta: ModelMeta;
  784. base_model_id?: string;
  785. params: ModelParams;
  786. }
  787. export interface ModelMeta {
  788. description?: string;
  789. capabilities?: object;
  790. }
  791. export interface ModelParams {}
  792. export type GlobalModelConfig = ModelConfig[];
  793. export const updateModelConfig = async (token: string, config: GlobalModelConfig) => {
  794. let error = null;
  795. const res = await fetch(`${WEBUI_BASE_URL}/api/config/models`, {
  796. method: 'POST',
  797. headers: {
  798. 'Content-Type': 'application/json',
  799. Authorization: `Bearer ${token}`
  800. },
  801. body: JSON.stringify({
  802. models: config
  803. })
  804. })
  805. .then(async (res) => {
  806. if (!res.ok) throw await res.json();
  807. return res.json();
  808. })
  809. .catch((err) => {
  810. console.log(err);
  811. error = err;
  812. return null;
  813. });
  814. if (error) {
  815. throw error;
  816. }
  817. return res;
  818. };