openui
openui copied to clipboard
How to change OpenAI's baseURL
I've tried to directly modify the baseURL in openai.ts several times, but without success. I would appreciate any help, thank you.
File server.py
in the folder backend/openui
- line 68
Set the base_url
to whatever you wish.
openai = AsyncOpenAI(
base_url="https://YOUR-URL/v1"
) # AsyncOpenAI(base_url="http://127.0.0.1:11434/v1")
ollama = AsyncClient()
router = APIRouter()
session_store = DBSessionStore()
github_sso = GithubSSO(
config.GITHUB_CLIENT_ID, config.GITHUB_CLIENT_SECRET, f"{config.HOST}/v1/callback"
)
Thank you so much. I will try it right away. Thank you.
Love this! Thanks @mmuyakwa. I'll look into making this configurable / extensible.
File
server.py
in the folderbackend/openui
- line 68Set the
base_url
to whatever you wish.openai = AsyncOpenAI( base_url="https://YOUR-URL/v1" ) # AsyncOpenAI(base_url="http://127.0.0.1:11434/v1") ollama = AsyncClient() router = APIRouter() session_store = DBSessionStore() github_sso = GithubSSO( config.GITHUB_CLIENT_ID, config.GITHUB_CLIENT_SECRET, f"{config.HOST}/v1/callback" )
NO no no, it can not work after change the base_url in the server.py at AsyncOpenAI(base_url="http://192.168.1.103:11434/v1"), when i run python -m openui
, the error is as follows:
the api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable.
@zhjygit Unfortunately the app always requires the "OPENAI_API_KEY" to be set, whether you use it or not. If you don't require it, then set it with something. Anything. It just has to be present.
In my case I used it for Groq. I entered the Groq-API-Key and changed the base_url to the url of Groq's API.
Otherwise take a look at the following: https://github.com/wandb/openui/issues/73#issuecomment-2099840072
@mmuyakwa i have a question, how could i change the base url if i use docker?
Certainly! Here's an example of how you can set up a variable (e.g., "base_url") in docker-compose and read it in a Python application running in a Docker container:
version: '3'
services:
app:
build: .
environment:
- BASE_URL=${BASE_URL:-https://default-api.example.com}
In this example:
- We define an environment variable 'BASE_URL' in the docker-compose.yml file.
- The syntax ${BASE_URL:-https://default-api.example.com} means:
- Use the value of BASE_URL if it's set in the host environment.
- If BASE_URL is not set, use the default value 'https://default-api.example.com'.
To read this variable in your Python application, you can use the 'os' module:
import os
base_url = os.environ.get('BASE_URL')
print(f"The base URL is: {base_url}")
Ensure that the "base_url" is only used, when set.
When running docker-compose, you could also set the variable like this:
BASE_URL=https://my-api.example.com docker-compose up
This will override the default value in the docker-compose.yml file. If you don't set it, the default value will be used.