openui icon indicating copy to clipboard operation
openui copied to clipboard

How to change OpenAI's baseURL

Open zsychn opened this issue 9 months ago • 5 comments

I've tried to directly modify the baseURL in openai.ts several times, but without success. I would appreciate any help, thank you.

zsychn avatar May 07 '24 11:05 zsychn

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"
)

mmuyakwa avatar May 07 '24 20:05 mmuyakwa

Thank you so much. I will try it right away. Thank you.

zsychn avatar May 08 '24 05:05 zsychn

Love this! Thanks @mmuyakwa. I'll look into making this configurable / extensible.

vanpelt avatar May 08 '24 10:05 vanpelt

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"
)

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 avatar May 09 '24 01:05 zhjygit

@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 avatar May 09 '24 12:05 mmuyakwa

@mmuyakwa i have a question, how could i change the base url if i use docker?

xingpingcn avatar Jul 21 '24 14:07 xingpingcn

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:

  1. We define an environment variable 'BASE_URL' in the docker-compose.yml file.
  2. 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.

mmuyakwa avatar Jul 21 '24 22:07 mmuyakwa