index.ts 615 B

12345678910111213141516171819202122232425262728293031
  1. import { WEBUI_API_BASE_URL } from '$lib/constants';
  2. export const setDefaultModels = async (token: string, models: string) => {
  3. let error = null;
  4. const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/models`, {
  5. method: 'POST',
  6. headers: {
  7. 'Content-Type': 'application/json',
  8. Authorization: `Bearer ${token}`
  9. },
  10. body: JSON.stringify({
  11. models: models
  12. })
  13. })
  14. .then(async (res) => {
  15. if (!res.ok) throw await res.json();
  16. return res.json();
  17. })
  18. .catch((err) => {
  19. console.log(err);
  20. error = err.detail;
  21. return null;
  22. });
  23. if (error) {
  24. throw error;
  25. }
  26. return res;
  27. };