LocalAI icon indicating copy to clipboard operation
LocalAI copied to clipboard

Set url sub-path (Reverse Proxy)

Open senpro-ingwersenk opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. I am trying to set up a "uniform" AI server with OpenWebUI and LocalAI and would like to - at least for the time being - host the LocalAI UI on a sub-path. Take a look at this Caddyfile:

:80 {
  handle_path /localai* {
    reverse_proxy * http://localai:8080
  }
  handle /* {
    reverse_proxy * http://openwebui:8080
  }
}

It is very basic but everything runs in a local test network and we use this to triage software before we add it to the real network. Hence, I need to, for now, host it on a sub-path. API calls work fine, but the small UI it comes with, does not, as it uses /assets... URLs for resources - which obviously does not resolve.

Describe the solution you'd like There is the env variable ADDRESS to specify the listening address and port. So, something like BASEURL would be helpful.

Describe alternatives you've considered I can't quite think of one, apologies.

Additional context The finite setup will be Caddy with oauth2-proxy and OpenWebUI to integrate the whole system into the rest of the network as a dedicated node. By then, the LocalAI endpoints besides the API will probably only be useable from the internal network but on it's own subdomain. But the test network does not have "domains" - it doesn't even have a dedicated local DNS. :)

Thank you for this awesome project; I am looking forward for something really neat; working on RISC-V with TensTorrent Greyskulls installed by providing a gRPC backend for localai to use. So I am looking forward to contributing this!

senpro-ingwersenk avatar Jul 31 '24 13:07 senpro-ingwersenk

Thanks for opening the issue @senpro-ingwersenk. Looks a feature that would be interesting indeed to have. Any chance you are up for taking a stab at it? I'd be happy to review

mudler avatar Jul 31 '24 14:07 mudler

I never wrote a webapp with "just" Go; so it will take some time to get into this. But it's interesting and I need to learn the ins and outs anyway - so, might as well.

/cc @IngwiePhoenix (Private profile; so I don't lose this :))

senpro-ingwersenk avatar Aug 01 '24 10:08 senpro-ingwersenk

First thing I spotted is here:

https://github.com/mudler/LocalAI/blob/master/core/http/views/partials/head.html#L7

Off the cuff, do you know if the renderer can access configuration values? It'd be quite easy to prepend a env.BASEURL to a few of those. If you have some pointers, I could work with that. :)

senpro-ingwersenk avatar Aug 01 '24 10:08 senpro-ingwersenk

@senpro-ingwersenk I just created PR #4497 to address this issue. However, instead of making a single static base URL configurable within LocalAI I've let it honour the X-Forwarded-Prefix HTTP header so that the base URL can be derived on a per-request basis and the path prefix concern can be entirely configured within the reverse-proxy. That said, you'd have to make your reverse-proxy specify the path prefix within the X-Forwarded-Prefix HTTP request header. Is that fine with you or do you really need a static path prefix that is configured within LocalAI explicitly?

mgoltzsche avatar Dec 25 '24 21:12 mgoltzsche