Skip to content

Commit

Permalink
Merge pull request open-webui#1131 from open-webui/dev
Browse files Browse the repository at this point in the history
fix: env var migration issue
  • Loading branch information
tjbck authored Mar 11, 2024
2 parents 11ca270 + e3fc972 commit 7ae4669
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
30 changes: 18 additions & 12 deletions backend/apps/openai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

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)
)
}
app.state.MODELS = {model["id"]: model for model in models["data"]}
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
return models


@app.get("/models")
Expand Down
11 changes: 5 additions & 6 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ def create_config_file(file_path):

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 = (
Expand All @@ -221,6 +217,11 @@ def create_config_file(file_path):
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

Expand All @@ -234,8 +235,6 @@ def create_config_file(file_path):
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"
Expand Down

0 comments on commit 7ae4669

Please sign in to comment.