open-webui/src/routes/+page.server.ts

31 lines
712 B
TypeScript
Raw Normal View History

2023-10-08 22:38:42 +00:00
import { ENDPOINT } from '$lib/contants';
import type { PageServerLoad } from './$types';
2023-10-09 01:32:54 +00:00
export const load: PageServerLoad = async ({ url }) => {
2023-10-19 04:47:28 +00:00
const OLLAMA_ENDPOINT = process.env.OLLAMA_ENDPOINT;
console.log(OLLAMA_ENDPOINT);
const models = await fetch(
`${OLLAMA_ENDPOINT != undefined ? OLLAMA_ENDPOINT : ENDPOINT}/api/tags`,
{
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
2023-10-08 22:38:42 +00:00
}
2023-10-19 04:47:28 +00:00
)
2023-10-08 22:38:42 +00:00
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((error) => {
console.log(error);
return null;
});
return {
2023-10-18 09:59:00 +00:00
models: models?.models ?? [],
2023-10-18 10:10:01 +00:00
OLLAMA_ENDPOINT: process.env.OLLAMA_ENDPOINT
2023-10-08 22:38:42 +00:00
};
};