mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 05:40:17 +00:00
Use same openai base url env var name as the official openai client
This eases re-use of the OpenAI API across all openai clients, including chat, image generation, speech to text. Resolves #1085
This commit is contained in:
@@ -234,7 +234,7 @@ def configure_server(
|
||||
|
||||
if ConversationAdapters.has_valid_ai_model_api():
|
||||
ai_model_api = ConversationAdapters.get_ai_model_api()
|
||||
state.openai_client = openai.OpenAI(api_key=ai_model_api.api_key)
|
||||
state.openai_client = openai.OpenAI(api_key=ai_model_api.api_key, base_url=ai_model_api.api_base_url)
|
||||
|
||||
# Initialize Search Models from Config and initialize content
|
||||
try:
|
||||
|
||||
@@ -43,14 +43,14 @@ def initialization(interactive: bool = True):
|
||||
"🗣️ Configure chat models available to your server. You can always update these at /server/admin using your admin account"
|
||||
)
|
||||
|
||||
openai_api_base = os.getenv("OPENAI_API_BASE")
|
||||
provider = "Ollama" if openai_api_base and openai_api_base.endswith(":11434/v1/") else "OpenAI"
|
||||
openai_api_key = os.getenv("OPENAI_API_KEY", "placeholder" if openai_api_base else None)
|
||||
openai_base_url = os.getenv("OPENAI_BASE_URL")
|
||||
provider = "Ollama" if openai_base_url and openai_base_url.endswith(":11434/v1/") else "OpenAI"
|
||||
openai_api_key = os.getenv("OPENAI_API_KEY", "placeholder" if openai_base_url else None)
|
||||
default_chat_models = default_openai_chat_models
|
||||
if openai_api_base:
|
||||
if openai_base_url:
|
||||
# Get available chat models from OpenAI compatible API
|
||||
try:
|
||||
openai_client = openai.OpenAI(api_key=openai_api_key, base_url=openai_api_base)
|
||||
openai_client = openai.OpenAI(api_key=openai_api_key, base_url=openai_base_url)
|
||||
default_chat_models = [model.id for model in openai_client.models.list()]
|
||||
# Put the available default OpenAI models at the top
|
||||
valid_default_models = [model for model in default_openai_chat_models if model in default_chat_models]
|
||||
@@ -66,7 +66,7 @@ def initialization(interactive: bool = True):
|
||||
ChatModel.ModelType.OPENAI,
|
||||
default_chat_models,
|
||||
default_api_key=openai_api_key,
|
||||
api_base_url=openai_api_base,
|
||||
api_base_url=openai_base_url,
|
||||
vision_enabled=True,
|
||||
is_offline=False,
|
||||
interactive=interactive,
|
||||
|
||||
Reference in New Issue
Block a user