index.ts 18 KB

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