mirror of
https://github.com/open-webui/open-webui
synced 2024-11-22 08:07:55 +00:00
feat: enable static builds
This commit is contained in:
parent
78ebae6095
commit
f4f1283cd5
17
package-lock.json
generated
17
package-lock.json
generated
@ -18,6 +18,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^2.0.0",
|
"@sveltejs/adapter-auto": "^2.0.0",
|
||||||
|
"@sveltejs/adapter-static": "^2.0.3",
|
||||||
"@sveltejs/kit": "^1.20.4",
|
"@sveltejs/kit": "^1.20.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||||
"@typescript-eslint/parser": "^6.0.0",
|
"@typescript-eslint/parser": "^6.0.0",
|
||||||
@ -759,6 +760,15 @@
|
|||||||
"@sveltejs/kit": "^1.0.0"
|
"@sveltejs/kit": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@sveltejs/adapter-static": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-VUqTfXsxYGugCpMqQv1U0LIdbR3S5nBkMMDmpjGVJyM6Q2jHVMFtdWJCkeHMySc6mZxJ+0eZK3T7IgmUCDrcUQ==",
|
||||||
|
"dev": true,
|
||||||
|
"peerDependencies": {
|
||||||
|
"@sveltejs/kit": "^1.5.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@sveltejs/kit": {
|
"node_modules/@sveltejs/kit": {
|
||||||
"version": "1.26.0",
|
"version": "1.26.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.26.0.tgz",
|
||||||
@ -4254,6 +4264,13 @@
|
|||||||
"rollup": "^3.7.0"
|
"rollup": "^3.7.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@sveltejs/adapter-static": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-VUqTfXsxYGugCpMqQv1U0LIdbR3S5nBkMMDmpjGVJyM6Q2jHVMFtdWJCkeHMySc6mZxJ+0eZK3T7IgmUCDrcUQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {}
|
||||||
|
},
|
||||||
"@sveltejs/kit": {
|
"@sveltejs/kit": {
|
||||||
"version": "1.26.0",
|
"version": "1.26.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.26.0.tgz",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^2.0.0",
|
"@sveltejs/adapter-auto": "^2.0.0",
|
||||||
|
"@sveltejs/adapter-static": "^2.0.3",
|
||||||
"@sveltejs/kit": "^1.20.4",
|
"@sveltejs/kit": "^1.20.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||||
"@typescript-eslint/parser": "^6.0.0",
|
"@typescript-eslint/parser": "^6.0.0",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { browser, dev } from '$app/environment';
|
import { browser, dev } from '$app/environment';
|
||||||
|
|
||||||
export const ENDPOINT = browser
|
export const API_ENDPOINT = browser
|
||||||
? `http://${location.hostname}:11434`
|
? `https://localhost/api`
|
||||||
: dev
|
: dev
|
||||||
? 'http://127.0.0.1:11434'
|
? `http://localhost:11434/api`
|
||||||
: 'http://host.docker.internal:11434';
|
: 'http://host.docker.internal:11434/api';
|
||||||
|
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';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ url }) => {
|
export const load: PageServerLoad = () => {
|
||||||
const OLLAMA_ENDPOINT = process.env.OLLAMA_ENDPOINT;
|
const API_ENDPOINT = process.env.API_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;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
models: models?.models ?? [],
|
API_ENDPOINT
|
||||||
OLLAMA_ENDPOINT: process.env.OLLAMA_ENDPOINT
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -9,18 +9,23 @@
|
|||||||
import 'highlight.js/styles/dark.min.css';
|
import 'highlight.js/styles/dark.min.css';
|
||||||
|
|
||||||
import type { PageData } from './$types';
|
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 { onMount, tick } from 'svelte';
|
||||||
import { page } from '$app/stores';
|
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 Navbar from '$lib/components/layout/Navbar.svelte';
|
||||||
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
|
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
|
||||||
|
|
||||||
export let data: PageData;
|
/* export let data: PageData; */
|
||||||
$: ({ models, OLLAMA_ENDPOINT } = data);
|
/* $: ({ 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 textareaElement;
|
||||||
let showSettings = false;
|
let showSettings = false;
|
||||||
let db;
|
let db;
|
||||||
@ -36,10 +41,21 @@
|
|||||||
let messages = [];
|
let messages = [];
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
ENDPOINT = OLLAMA_ENDPOINT ? OLLAMA_ENDPOINT : SERVER_ENDPOINT;
|
/* console.log('API_ENDPOINT 2', API_ENDPOINT) */
|
||||||
console.log(OLLAMA_ENDPOINT);
|
const resp = await fetch(`${DEV_API_ENDPOINT}/tags`, {
|
||||||
console.log(SERVER_ENDPOINT);
|
method: 'GET',
|
||||||
console.log(ENDPOINT);
|
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');
|
let settings = localStorage.getItem('settings');
|
||||||
if (settings) {
|
if (settings) {
|
||||||
@ -267,7 +283,7 @@
|
|||||||
messages = [...messages, responseMessage];
|
messages = [...messages, responseMessage];
|
||||||
window.scrollTo({ top: document.body.scrollHeight });
|
window.scrollTo({ top: document.body.scrollHeight });
|
||||||
|
|
||||||
const res = await fetch(`${ENDPOINT}/api/generate`, {
|
const res = await fetch(`${API_ENDPOINT}/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/event-stream'
|
'Content-Type': 'text/event-stream'
|
||||||
@ -363,7 +379,7 @@
|
|||||||
messages = [...messages, responseMessage];
|
messages = [...messages, responseMessage];
|
||||||
window.scrollTo({ top: document.body.scrollHeight });
|
window.scrollTo({ top: document.body.scrollHeight });
|
||||||
|
|
||||||
const res = await fetch(`${ENDPOINT}/api/generate`, {
|
const res = await fetch(`${API_ENDPOINT}/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/event-stream'
|
'Content-Type': 'text/event-stream'
|
||||||
@ -443,7 +459,7 @@
|
|||||||
const generateTitle = async (user_prompt) => {
|
const generateTitle = async (user_prompt) => {
|
||||||
console.log('generateTitle');
|
console.log('generateTitle');
|
||||||
|
|
||||||
const res = await fetch(`${ENDPOINT}/api/generate`, {
|
const res = await fetch(`${API_ENDPOINT}/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/event-stream'
|
'Content-Type': 'text/event-stream'
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import adapter from '@sveltejs/adapter-node';
|
import adapter from '@sveltejs/adapter-static';
|
||||||
import { vitePreprocess } from '@sveltejs/kit/vite';
|
import { vitePreprocess } from '@sveltejs/kit/vite';
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
@ -11,7 +11,11 @@ const config = {
|
|||||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
||||||
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
||||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
||||||
adapter: adapter()
|
adapter: adapter({
|
||||||
|
pages: 'build',
|
||||||
|
assets: 'build',
|
||||||
|
fallback: null
|
||||||
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user