+page.server.ts 712 Bytes
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
3
import { ENDPOINT } from '$lib/contants';
import type { PageServerLoad } from './$types';

Timothy J. Baek's avatar
Timothy J. Baek committed
4
export const load: PageServerLoad = async ({ url }) => {
Timothy J. Baek's avatar
Timothy J. Baek committed
5
6
7
8
9
10
11
12
13
14
	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'
			}
Timothy J. Baek's avatar
Timothy J. Baek committed
15
		}
Timothy J. Baek's avatar
Timothy J. Baek committed
16
	)
Timothy J. Baek's avatar
Timothy J. Baek committed
17
18
19
20
21
22
23
24
25
26
		.then(async (res) => {
			if (!res.ok) throw await res.json();
			return res.json();
		})
		.catch((error) => {
			console.log(error);
			return null;
		});

	return {
27
		models: models?.models ?? [],
Timothy J. Baek's avatar
Timothy J. Baek committed
28
		OLLAMA_ENDPOINT: process.env.OLLAMA_ENDPOINT
Timothy J. Baek's avatar
Timothy J. Baek committed
29
30
	};
};