index.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { WEBUI_API_BASE_URL } from '$lib/constants';
  2. import type { Banner } from '$lib/types';
  3. export const setDefaultModels = async (token: string, models: string) => {
  4. let error = null;
  5. const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/models`, {
  6. method: 'POST',
  7. headers: {
  8. 'Content-Type': 'application/json',
  9. Authorization: `Bearer ${token}`
  10. },
  11. body: JSON.stringify({
  12. models: models
  13. })
  14. })
  15. .then(async (res) => {
  16. if (!res.ok) throw await res.json();
  17. return res.json();
  18. })
  19. .catch((err) => {
  20. console.log(err);
  21. error = err.detail;
  22. return null;
  23. });
  24. if (error) {
  25. throw error;
  26. }
  27. return res;
  28. };
  29. export const setDefaultPromptSuggestions = async (token: string, promptSuggestions: string) => {
  30. let error = null;
  31. const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/suggestions`, {
  32. method: 'POST',
  33. headers: {
  34. 'Content-Type': 'application/json',
  35. Authorization: `Bearer ${token}`
  36. },
  37. body: JSON.stringify({
  38. suggestions: promptSuggestions
  39. })
  40. })
  41. .then(async (res) => {
  42. if (!res.ok) throw await res.json();
  43. return res.json();
  44. })
  45. .catch((err) => {
  46. console.log(err);
  47. error = err.detail;
  48. return null;
  49. });
  50. if (error) {
  51. throw error;
  52. }
  53. return res;
  54. };
  55. export const getBanners = async (token: string): Promise<Banner[]> => {
  56. let error = null;
  57. const res = await fetch(`${WEBUI_API_BASE_URL}/configs/banners`, {
  58. method: 'GET',
  59. headers: {
  60. 'Content-Type': 'application/json',
  61. Authorization: `Bearer ${token}`
  62. }
  63. })
  64. .then(async (res) => {
  65. if (!res.ok) throw await res.json();
  66. return res.json();
  67. })
  68. .catch((err) => {
  69. console.log(err);
  70. error = err.detail;
  71. return null;
  72. });
  73. if (error) {
  74. throw error;
  75. }
  76. return res;
  77. };
  78. export const setBanners = async (token: string, banners: Banner[]) => {
  79. let error = null;
  80. const res = await fetch(`${WEBUI_API_BASE_URL}/configs/banners`, {
  81. method: 'POST',
  82. headers: {
  83. 'Content-Type': 'application/json',
  84. Authorization: `Bearer ${token}`
  85. },
  86. body: JSON.stringify({
  87. banners: banners
  88. })
  89. })
  90. .then(async (res) => {
  91. if (!res.ok) throw await res.json();
  92. return res.json();
  93. })
  94. .catch((err) => {
  95. console.log(err);
  96. error = err.detail;
  97. return null;
  98. });
  99. if (error) {
  100. throw error;
  101. }
  102. return res;
  103. };