mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-30 08:42:00 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -21,7 +21,7 @@ let generation_settings = null; | |||||||
| // | // | ||||||
| export async function* llama(prompt, params = {}, config = {}) { | export async function* llama(prompt, params = {}, config = {}) { | ||||||
|   let controller = config.controller; |   let controller = config.controller; | ||||||
|   const api_url = config.api_url || ""; |   const api_url = config.api_url?.replace(/\/+$/, '') || ""; | ||||||
|  |  | ||||||
|   if (!controller) { |   if (!controller) { | ||||||
|     controller = new AbortController(); |     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. | // Get the model info from the server. This is useful for getting the context window and so on. | ||||||
| export const llamaModelInfo = async (config = {}) => { | export const llamaModelInfo = async (config = {}) => { | ||||||
|   if (!generation_settings) { |   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()); |     const props = await fetch(`${api_url}/props`).then(r => r.json()); | ||||||
|     generation_settings = props.default_generation_settings; |     generation_settings = props.default_generation_settings; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -14,10 +14,10 @@ | |||||||
|   <script type="module"> |   <script type="module"> | ||||||
|     import { |     import { | ||||||
|       html, h, signal, effect, computed, render, useSignal, useEffect, useRef, Component |       html, h, signal, effect, computed, render, useSignal, useEffect, useRef, Component | ||||||
|     } from '/index.js'; |     } from './index.js'; | ||||||
|  |  | ||||||
|     import { llama } from '/completion.js'; |     import { llama } from './completion.js'; | ||||||
|     import { SchemaConverter } from '/json-schema-to-grammar.mjs'; |     import { SchemaConverter } from './json-schema-to-grammar.mjs'; | ||||||
|     import { promptFormats } from './prompt-formats.js'; |     import { promptFormats } from './prompt-formats.js'; | ||||||
|     import { systemPrompts } from './system-prompts.js'; // multilingual is wip |     import { systemPrompts } from './system-prompts.js'; // multilingual is wip | ||||||
|     let selected_image = false; |     let selected_image = false; | ||||||
| @@ -225,7 +225,7 @@ | |||||||
|         throw new Error("already running"); |         throw new Error("already running"); | ||||||
|       } |       } | ||||||
|       controller.value = new AbortController(); |       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; |         const data = chunk.data; | ||||||
|         if (data.stop) { |         if (data.stop) { | ||||||
|           while ( |           while ( | ||||||
|   | |||||||
| @@ -479,7 +479,7 @@ | |||||||
|         throw new Error("already running"); |         throw new Error("already running"); | ||||||
|       } |       } | ||||||
|       controller.value = new AbortController(); |       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; |         const data = chunk.data; | ||||||
|  |  | ||||||
|         if (data.stop) { |         if (data.stop) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Eric Zhang
					Eric Zhang