server: public: use relative routes for static files (#6325)

server: public: support custom `api_url`, default to relative base path
This commit is contained in:
Eric Zhang 2024-03-27 13:55:29 +08:00 committed by GitHub
parent a4f569e8a3
commit 0642b22cd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 2864 additions and 2848 deletions

View file

@ -21,6 +21,7 @@ let generation_settings = null;
//
export async function* llama(prompt, params = {}, config = {}) {
let controller = config.controller;
const api_url = config.api_url || "";
if (!controller) {
controller = new AbortController();
@ -28,7 +29,7 @@ export async function* llama(prompt, params = {}, config = {}) {
const completionParams = { ...paramDefaults, ...params, prompt };
const response = await fetch("/completion", {
const response = await fetch(`${api_url}/completion`, {
method: 'POST',
body: JSON.stringify(completionParams),
headers: {
@ -193,9 +194,10 @@ export const llamaComplete = async (params, controller, callback) => {
}
// Get the model info from the server. This is useful for getting the context window and so on.
export const llamaModelInfo = async () => {
export const llamaModelInfo = async (config = {}) => {
if (!generation_settings) {
const props = await fetch("/props").then(r => r.json());
const api_url = config.api_url || "";
const props = await fetch(`${api_url}/props`).then(r => r.json());
generation_settings = props.default_generation_settings;
}
return generation_settings;