Skip to content

Commit 0d2c732

Browse files
authored
server: use relative routes for static files in new UI (#8552)
* server: public: fix api_url on non-index pages * server: public: use relative routes for static files in new UI
1 parent 672a6f1 commit 0d2c732

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

examples/server/public/completion.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let generation_settings = null;
2121
//
2222
export async function* llama(prompt, params = {}, config = {}) {
2323
let controller = config.controller;
24-
const api_url = config.api_url || "";
24+
const api_url = config.api_url?.replace(/\/+$/, '') || "";
2525

2626
if (!controller) {
2727
controller = new AbortController();
@@ -196,7 +196,7 @@ export const llamaComplete = async (params, controller, callback) => {
196196
// Get the model info from the server. This is useful for getting the context window and so on.
197197
export const llamaModelInfo = async (config = {}) => {
198198
if (!generation_settings) {
199-
const api_url = config.api_url || "";
199+
const api_url = config.api_url?.replace(/\/+$/, '') || "";
200200
const props = await fetch(`${api_url}/props`).then(r => r.json());
201201
generation_settings = props.default_generation_settings;
202202
}

examples/server/public/index-new.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<script type="module">
1515
import {
1616
html, h, signal, effect, computed, render, useSignal, useEffect, useRef, Component
17-
} from '/index.js';
17+
} from './index.js';
1818

19-
import { llama } from '/completion.js';
20-
import { SchemaConverter } from '/json-schema-to-grammar.mjs';
19+
import { llama } from './completion.js';
20+
import { SchemaConverter } from './json-schema-to-grammar.mjs';
2121
import { promptFormats } from './prompt-formats.js';
2222
import { systemPrompts } from './system-prompts.js'; // multilingual is wip
2323
let selected_image = false;
@@ -225,7 +225,7 @@
225225
throw new Error("already running");
226226
}
227227
controller.value = new AbortController();
228-
for await (const chunk of llama(prompt, llamaParams, { controller: controller.value })) {
228+
for await (const chunk of llama(prompt, llamaParams, { controller: controller.value, api_url: URL.parse('.', document.baseURI).href })) {
229229
const data = chunk.data;
230230
if (data.stop) {
231231
while (

examples/server/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
throw new Error("already running");
480480
}
481481
controller.value = new AbortController();
482-
for await (const chunk of llama(prompt, llamaParams, { controller: controller.value, api_url: location.pathname.replace(/\/+$/, '') })) {
482+
for await (const chunk of llama(prompt, llamaParams, { controller: controller.value, api_url: URL.parse('.', document.baseURI).href })) {
483483
const data = chunk.data;
484484

485485
if (data.stop) {

0 commit comments

Comments
 (0)