From b4c770d74bfea252f73c822a2ea4a0a407357870 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 10 Mar 2024 19:00:43 -0700 Subject: [PATCH 1/2] fix: disable openai model by default --- backend/apps/openai/main.py | 32 +++++++++++++++++++------------- backend/config.py | 2 -- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index e902bea27..375ed3f12 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -179,20 +179,26 @@ def merge_models_lists(model_lists): async def get_all_models(): print("get_all_models") - tasks = [ - fetch_url(f"{url}/models", app.state.OPENAI_API_KEYS[idx]) - for idx, url in enumerate(app.state.OPENAI_API_BASE_URLS) - ] - responses = await asyncio.gather(*tasks) - responses = list(filter(lambda x: x is not None and "error" not in x, responses)) - models = { - "data": merge_models_lists( - list(map(lambda response: response["data"], responses)) - ) - } - app.state.MODELS = {model["id"]: model for model in models["data"]} - return models + if len(app.state.OPENAI_API_KEYS) == 1 and app.state.OPENAI_API_KEYS[0] == "": + models = {"data": []} + else: + tasks = [ + fetch_url(f"{url}/models", app.state.OPENAI_API_KEYS[idx]) + for idx, url in enumerate(app.state.OPENAI_API_BASE_URLS) + ] + responses = await asyncio.gather(*tasks) + responses = list( + filter(lambda x: x is not None and "error" not in x, responses) + ) + models = { + "data": merge_models_lists( + list(map(lambda response: response["data"], responses)) + ) + } + app.state.MODELS = {model["id"]: model for model in models["data"]} + + return models @app.get("/models") diff --git a/backend/config.py b/backend/config.py index 019e44e01..f680e08ae 100644 --- a/backend/config.py +++ b/backend/config.py @@ -234,8 +234,6 @@ OLLAMA_BASE_URLS = [url.strip() for url in OLLAMA_BASE_URLS.split(";")] OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "") OPENAI_API_BASE_URL = os.environ.get("OPENAI_API_BASE_URL", "") -if OPENAI_API_KEY == "": - OPENAI_API_KEY = "none" if OPENAI_API_BASE_URL == "": OPENAI_API_BASE_URL = "https://api.openai.com/v1" From e3fc97241d2c14038396117af83bd9ba2e3a123b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 10 Mar 2024 19:26:06 -0700 Subject: [PATCH 2/2] fix: env var migration issue --- backend/config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/config.py b/backend/config.py index f680e08ae..831371bb7 100644 --- a/backend/config.py +++ b/backend/config.py @@ -209,10 +209,6 @@ OLLAMA_API_BASE_URL = os.environ.get( OLLAMA_BASE_URL = os.environ.get("OLLAMA_BASE_URL", "") -if ENV == "prod": - if OLLAMA_BASE_URL == "/ollama": - OLLAMA_BASE_URL = "http://host.docker.internal:11434" - if OLLAMA_BASE_URL == "" and OLLAMA_API_BASE_URL != "": OLLAMA_BASE_URL = ( @@ -221,6 +217,11 @@ if OLLAMA_BASE_URL == "" and OLLAMA_API_BASE_URL != "": else OLLAMA_API_BASE_URL ) +if ENV == "prod": + if OLLAMA_BASE_URL == "/ollama": + OLLAMA_BASE_URL = "http://host.docker.internal:11434" + + OLLAMA_BASE_URLS = os.environ.get("OLLAMA_BASE_URLS", "") OLLAMA_BASE_URLS = OLLAMA_BASE_URLS if OLLAMA_BASE_URLS != "" else OLLAMA_BASE_URL