]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server: use relative routes for static files in new UI (#8552)
authorEric Zhang <redacted>
Thu, 18 Jul 2024 10:43:49 +0000 (18:43 +0800)
committerGitHub <redacted>
Thu, 18 Jul 2024 10:43:49 +0000 (12:43 +0200)
* server: public: fix api_url on non-index pages

* server: public: use relative routes for static files in new UI

examples/server/public/completion.js
examples/server/public/index-new.html
examples/server/public/index.html

index 987b9a3b891d0c9aac21b06be74c0f315cfc229d..36818f7644aa10cd5e8cdcf1e7d20c5e20c3e35e 100644 (file)
@@ -21,7 +21,7 @@ let generation_settings = null;
 //
 export async function* llama(prompt, params = {}, config = {}) {
   let controller = config.controller;
-  const api_url = config.api_url || "";
+  const api_url = config.api_url?.replace(/\/+$/, '') || "";
 
   if (!controller) {
     controller = new AbortController();
@@ -196,7 +196,7 @@ 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 (config = {}) => {
   if (!generation_settings) {
-    const api_url = config.api_url || "";
+    const api_url = config.api_url?.replace(/\/+$/, '') || "";
     const props = await fetch(`${api_url}/props`).then(r => r.json());
     generation_settings = props.default_generation_settings;
   }
index 5513e9121a40fd51603d68fcb3320d91fff903ad..bf2b0a3f0803c96621ae2aaef673357765fd0090 100644 (file)
   <script type="module">
     import {
       html, h, signal, effect, computed, render, useSignal, useEffect, useRef, Component
-    } from '/index.js';
+    } from './index.js';
 
-    import { llama } from '/completion.js';
-    import { SchemaConverter } from '/json-schema-to-grammar.mjs';
+    import { llama } from './completion.js';
+    import { SchemaConverter } from './json-schema-to-grammar.mjs';
     import { promptFormats } from './prompt-formats.js';
     import { systemPrompts } from './system-prompts.js'; // multilingual is wip
     let selected_image = false;
         throw new Error("already running");
       }
       controller.value = new AbortController();
-      for await (const chunk of llama(prompt, llamaParams, { controller: controller.value })) {
+      for await (const chunk of llama(prompt, llamaParams, { controller: controller.value, api_url: URL.parse('.', document.baseURI).href })) {
         const data = chunk.data;
         if (data.stop) {
           while (
index 2f60a76e88b87b6ecc99deb00049d041c9a7c8ed..a15424613499ff5c892bccabf0c660597aba0f33 100644 (file)
         throw new Error("already running");
       }
       controller.value = new AbortController();
-      for await (const chunk of llama(prompt, llamaParams, { controller: controller.value, api_url: location.pathname.replace(/\/+$/, '') })) {
+      for await (const chunk of llama(prompt, llamaParams, { controller: controller.value, api_url: URL.parse('.', document.baseURI).href })) {
         const data = chunk.data;
 
         if (data.stop) {