From 553beae8485c7ba20f86b8a454da6c92fa749f43 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 22 Jun 2024 12:18:43 +0530 Subject: [PATCH] No need to set OpenAI API key from environment variable explicitly It is unnecessary as the OpenAI client automatically tries to use API key from OPENAI_API_KEY env var when the api_key field is unset --- src/khoj/processor/conversation/openai/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/khoj/processor/conversation/openai/utils.py b/src/khoj/processor/conversation/openai/utils.py index 49f1d6b6..b17e5c3d 100644 --- a/src/khoj/processor/conversation/openai/utils.py +++ b/src/khoj/processor/conversation/openai/utils.py @@ -1,5 +1,4 @@ import logging -import os from threading import Thread from typing import Dict @@ -40,7 +39,7 @@ def completion_with_backoff( client: openai.OpenAI = openai_clients.get(client_key) if not client: client = openai.OpenAI( - api_key=openai_api_key or os.getenv("OPENAI_API_KEY"), + api_key=openai_api_key, base_url=api_base_url, ) openai_clients[client_key] = client @@ -102,7 +101,7 @@ def llm_thread(g, messages, model_name, temperature, openai_api_key=None, api_ba client_key = f"{openai_api_key}--{api_base_url}" if client_key not in openai_clients: client: openai.OpenAI = openai.OpenAI( - api_key=openai_api_key or os.getenv("OPENAI_API_KEY"), + api_key=openai_api_key, base_url=api_base_url, ) openai_clients[client_key] = client