forked from open-webui/open-webui
		
	feat: enable static builds
This commit is contained in:
		
							parent
							
								
									78ebae6095
								
							
						
					
					
						commit
						f4f1283cd5
					
				
					 7 changed files with 75 additions and 43 deletions
				
			
		
							
								
								
									
										16
									
								
								src/routes/+layout.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/routes/+layout.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| // if you want to generate a static html file
 | ||||
| // for your page.
 | ||||
| // Documentation: https://kit.svelte.dev/docs/page-options#prerender
 | ||||
| export const prerender = true; | ||||
| 
 | ||||
| // if you want to Generate a SPA
 | ||||
| // you have to set ssr to false.
 | ||||
| // This is not the case (so set as true or comment the line)
 | ||||
| // Documentation: https://kit.svelte.dev/docs/page-options#ssr
 | ||||
| export const ssr = true; | ||||
| 
 | ||||
| // How to manage the trailing slashes in the URLs
 | ||||
| // the URL for about page witll be /about with 'ignore' (default)
 | ||||
| // the URL for about page witll be /about/ with 'always'
 | ||||
| // https://kit.svelte.dev/docs/page-options#trailingslash
 | ||||
| export const trailingSlash = 'ignore'; | ||||
|  | @ -1,30 +1,8 @@ | |||
| import { ENDPOINT } from '$lib/constants'; | ||||
| import type { PageServerLoad } from './$types'; | ||||
| 
 | ||||
| export const load: PageServerLoad = async ({ url }) => { | ||||
| 	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' | ||||
| 			} | ||||
| 		} | ||||
| 	) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((error) => { | ||||
| 			console.log(error); | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| export const load: PageServerLoad = () => { | ||||
| 	const API_ENDPOINT = process.env.API_ENDPOINT; | ||||
| 	return { | ||||
| 		models: models?.models ?? [], | ||||
| 		OLLAMA_ENDPOINT: process.env.OLLAMA_ENDPOINT | ||||
| 		API_ENDPOINT | ||||
| 	}; | ||||
| }; | ||||
|  |  | |||
|  | @ -9,18 +9,23 @@ | |||
| 	import 'highlight.js/styles/dark.min.css'; | ||||
| 
 | ||||
| 	import type { PageData } from './$types'; | ||||
| 	import { ENDPOINT as SERVER_ENDPOINT } from '$lib/constants'; | ||||
| 	import { API_ENDPOINT as DEV_API_ENDPOINT } from '$lib/constants'; | ||||
| 	import { onMount, tick } from 'svelte'; | ||||
| 	import { page } from '$app/stores'; | ||||
| 	const suggestions = $page.url.searchParams.get('suggestions'); | ||||
| 	const suggestions = ''; // $page.url.searchParams.get('suggestions'); | ||||
| 
 | ||||
| 	import Navbar from '$lib/components/layout/Navbar.svelte'; | ||||
| 	import SettingsModal from '$lib/components/chat/SettingsModal.svelte'; | ||||
| 
 | ||||
| 	export let data: PageData; | ||||
| 	$: ({ models, OLLAMA_ENDPOINT } = data); | ||||
| 	/* export let data: PageData; */ | ||||
| 	/* $: ({ API_ENDPOINT } = data); */ | ||||
| 	/* if (!API_ENDPOINT) { */ | ||||
| 	/*     API_ENDPOINT = DEV_API_ENDPOINT; */ | ||||
| 	/* } */ | ||||
| 	/* console.log('API_ENDPOINT',API_ENDPOINT) */ | ||||
| 	/* console.log('DEV_API_ENDPOINT', DEV_API_ENDPOINT) */ | ||||
| 
 | ||||
| 	let ENDPOINT; | ||||
| 	let models = []; | ||||
| 	let textareaElement; | ||||
| 	let showSettings = false; | ||||
| 	let db; | ||||
|  | @ -36,10 +41,21 @@ | |||
| 	let messages = []; | ||||
| 
 | ||||
| 	onMount(async () => { | ||||
| 		ENDPOINT = OLLAMA_ENDPOINT ? OLLAMA_ENDPOINT : SERVER_ENDPOINT; | ||||
| 		console.log(OLLAMA_ENDPOINT); | ||||
| 		console.log(SERVER_ENDPOINT); | ||||
| 		console.log(ENDPOINT); | ||||
| 		/* console.log('API_ENDPOINT 2', API_ENDPOINT) */ | ||||
| 		const resp = await fetch(`${DEV_API_ENDPOINT}/tags`, { | ||||
| 			method: 'GET', | ||||
| 			headers: { | ||||
| 				Accept: 'application/json', | ||||
| 				'Content-Type': 'application/json' | ||||
| 			} | ||||
| 		}); | ||||
| 		if (!resp.ok) { | ||||
| 			let msg = await resp.text(); | ||||
| 			let err = new Error(msg); | ||||
| 			throw err; | ||||
| 		} | ||||
| 		const data = await resp.json(); | ||||
| 		models = data.models; | ||||
| 
 | ||||
| 		let settings = localStorage.getItem('settings'); | ||||
| 		if (settings) { | ||||
|  | @ -267,7 +283,7 @@ | |||
| 			messages = [...messages, responseMessage]; | ||||
| 			window.scrollTo({ top: document.body.scrollHeight }); | ||||
| 
 | ||||
| 			const res = await fetch(`${ENDPOINT}/api/generate`, { | ||||
| 			const res = await fetch(`${API_ENDPOINT}/generate`, { | ||||
| 				method: 'POST', | ||||
| 				headers: { | ||||
| 					'Content-Type': 'text/event-stream' | ||||
|  | @ -363,7 +379,7 @@ | |||
| 			messages = [...messages, responseMessage]; | ||||
| 			window.scrollTo({ top: document.body.scrollHeight }); | ||||
| 
 | ||||
| 			const res = await fetch(`${ENDPOINT}/api/generate`, { | ||||
| 			const res = await fetch(`${API_ENDPOINT}/generate`, { | ||||
| 				method: 'POST', | ||||
| 				headers: { | ||||
| 					'Content-Type': 'text/event-stream' | ||||
|  | @ -443,7 +459,7 @@ | |||
| 	const generateTitle = async (user_prompt) => { | ||||
| 		console.log('generateTitle'); | ||||
| 
 | ||||
| 		const res = await fetch(`${ENDPOINT}/api/generate`, { | ||||
| 		const res = await fetch(`${API_ENDPOINT}/generate`, { | ||||
| 			method: 'POST', | ||||
| 			headers: { | ||||
| 				'Content-Type': 'text/event-stream' | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AJ ONeal
						AJ ONeal