mirror of
https://github.com/mudler/LocalAI.git
synced 2025-01-25 21:59:27 +00:00
8cc2d01caa
Makes the web app honour the `X-Forwarded-Prefix` HTTP request header that may be sent by a reverse-proxy in order to inform the app that its public routes contain a path prefix.
For instance this allows to serve the webapp via a reverse-proxy/ingress controller under a path prefix/sub path such as e.g. `/localai/` while still being able to use the regular LocalAI routes/paths without prefix when directly connecting to the LocalAI server.
Changes:
* Add new `StripPathPrefix` middleware to strip the path prefix (provided with the `X-Forwarded-Prefix` HTTP request header) from the request path prior to matching the HTTP route.
* Add a `BaseURL` utility function to build the base URL, honouring the `X-Forwarded-Prefix` HTTP request header.
* Generate the derived base URL into the HTML (`head.html` template) as `<base/>` tag.
* Make all webapp-internal URLs (within HTML+JS) relative in order to make the browser resolve them against the `<base/>` URL specified within each HTML page's header.
* Make font URLs within the CSS files relative to the CSS file.
* Generate redirect location URLs using the new `BaseURL` function.
* Use the new `BaseURL` function to generate absolute URLs within gallery JSON responses.
Closes #3095
TL;DR:
The header-based approach allows to move the path prefix configuration concern completely to the reverse-proxy/ingress as opposed to having to align the path prefix configuration between LocalAI, the reverse-proxy and potentially other internal LocalAI clients.
The gofiber swagger handler already supports path prefixes this way, see e2d9e9916d/swagger.go (L79)
Signed-off-by: Max Goltzsche <max.goltzsche@gmail.com>
86 lines
4.8 KiB
HTML
86 lines
4.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
{{template "views/partials/head" .}}
|
|
|
|
<body class="bg-gray-900 text-gray-200">
|
|
<div class="flex flex-col min-h-screen">
|
|
|
|
{{template "views/partials/navbar" .}}
|
|
<div class="container mx-auto px-4 flex-grow">
|
|
|
|
<div class="models mt-12">
|
|
<h2 class="text-center text-3xl font-semibold text-gray-100">
|
|
🖼️ Available {{.AvailableModels}} models from <i>{{ len .Repositories }}</i> repositories <a href="https://localai.io/models/" target="_blank" >
|
|
<i class="fas fa-circle-info pr-2"></i>
|
|
</a></h2>
|
|
|
|
<div class="text-center font-semibold text-gray-100">
|
|
<h2>Filter by type:</h2>
|
|
<button hx-post="browse/search/models"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "tts"}'
|
|
hx-indicator=".htmx-indicator" >TTS</button>
|
|
<button hx-post="browse/search/models"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "stablediffusion"}'
|
|
hx-indicator=".htmx-indicator" >Image generation</button>
|
|
<button hx-post="browse/search/models" \
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "llm"}'
|
|
hx-indicator=".htmx-indicator" >Text generation</button>
|
|
<button hx-post="browse/search/models"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "multimodal"}'
|
|
hx-indicator=".htmx-indicator" >Multimodal</button>
|
|
<button hx-post="browse/search/models"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "embedding"}'
|
|
hx-indicator=".htmx-indicator" >Embeddings</button>
|
|
<button hx-post="browse/search/models"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "rerank"}'
|
|
hx-indicator=".htmx-indicator" >Rerankers</button>
|
|
<button
|
|
hx-post="browse/search/models"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
hx-target="#search-results"
|
|
hx-vals='{"search": "whisper"}'
|
|
hx-indicator=".htmx-indicator" >Audio transcription</button>
|
|
</div>
|
|
|
|
<div class="text-center text-xs font-semibold text-gray-100">
|
|
Filter by tags:
|
|
{{ range .AllTags }}
|
|
<button hx-post="browse/search/models" class="text-blue-500" hx-target="#search-results"
|
|
hx-vals='{"search": "{{.}}"}'
|
|
hx-indicator=".htmx-indicator" >{{.}}</button>
|
|
{{ end }}
|
|
</div>
|
|
|
|
|
|
<span class="htmx-indicator loader"></span>
|
|
{{template "views/partials/inprogress" .}}
|
|
|
|
<input class="form-control appearance-none block w-full mt-5 px-3 py-2 text-base font-normal text-gray-300 pb-2 mb-5 bg-gray-800 bg-clip-padding border border-solid border-gray-600 rounded transition ease-in-out m-0 focus:text-gray-300 focus:bg-gray-900 focus:border-blue-500 focus:outline-none" type="search"
|
|
name="search" placeholder="Begin Typing To Search models..."
|
|
hx-post="browse/search/models"
|
|
hx-trigger="input changed delay:500ms, search"
|
|
hx-target="#search-results"
|
|
hx-indicator=".htmx-indicator">
|
|
|
|
<div id="search-results">{{.Models}}</div>
|
|
</div>
|
|
</div>
|
|
|
|
{{template "views/partials/footer" .}}
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|