mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-20 04:37:09 +02:00
Default to API key in file (#531)
This commit is contained in:
@@ -75,7 +75,10 @@ INTERNAL_MODEL_VERSION = os.environ.get(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# If the Generative AI model requires an API key for access, otherwise can leave blank
|
# If the Generative AI model requires an API key for access, otherwise can leave blank
|
||||||
GEN_AI_API_KEY = os.environ.get("GEN_AI_API_KEY", "")
|
GEN_AI_API_KEY = (
|
||||||
|
os.environ.get("GEN_AI_API_KEY", os.environ.get("OPENAI_API_KEY"))
|
||||||
|
or "dummy_llm_key"
|
||||||
|
)
|
||||||
|
|
||||||
# If using GPT4All, HuggingFace Inference API, or OpenAI - specify the model version
|
# If using GPT4All, HuggingFace Inference API, or OpenAI - specify the model version
|
||||||
GEN_AI_MODEL_VERSION = os.environ.get(
|
GEN_AI_MODEL_VERSION = os.environ.get(
|
||||||
|
@@ -32,8 +32,9 @@ logger = setup_logger()
|
|||||||
|
|
||||||
|
|
||||||
def get_gen_ai_api_key() -> str:
|
def get_gen_ai_api_key() -> str:
|
||||||
return GEN_AI_API_KEY or cast(
|
return (
|
||||||
str, get_dynamic_config_store().load(GEN_AI_API_KEY_STORAGE_KEY)
|
cast(str, get_dynamic_config_store().load(GEN_AI_API_KEY_STORAGE_KEY))
|
||||||
|
or GEN_AI_API_KEY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain.chat_models.azure_openai import AzureChatOpenAI
|
from langchain.chat_models.azure_openai import AzureChatOpenAI
|
||||||
@@ -6,6 +5,7 @@ from langchain.chat_models.azure_openai import AzureChatOpenAI
|
|||||||
from danswer.configs.model_configs import API_BASE_OPENAI
|
from danswer.configs.model_configs import API_BASE_OPENAI
|
||||||
from danswer.configs.model_configs import API_VERSION_OPENAI
|
from danswer.configs.model_configs import API_VERSION_OPENAI
|
||||||
from danswer.configs.model_configs import AZURE_DEPLOYMENT_ID
|
from danswer.configs.model_configs import AZURE_DEPLOYMENT_ID
|
||||||
|
from danswer.configs.model_configs import GEN_AI_API_KEY
|
||||||
from danswer.llm.llm import LangChainChatLLM
|
from danswer.llm.llm import LangChainChatLLM
|
||||||
from danswer.llm.utils import should_be_verbose
|
from danswer.llm.utils import should_be_verbose
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class AzureGPT(LangChainChatLLM):
|
|||||||
# exception when trying to initialize the LLM which would prevent the API
|
# exception when trying to initialize the LLM which would prevent the API
|
||||||
# server from starting up
|
# server from starting up
|
||||||
if not api_key:
|
if not api_key:
|
||||||
api_key = os.environ.get("OPENAI_API_KEY") or "dummy_api_key"
|
api_key = GEN_AI_API_KEY
|
||||||
self._llm = AzureChatOpenAI(
|
self._llm = AzureChatOpenAI(
|
||||||
model=model_version,
|
model=model_version,
|
||||||
openai_api_type="azure",
|
openai_api_type="azure",
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import os
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from langchain.chat_models.openai import ChatOpenAI
|
from langchain.chat_models.openai import ChatOpenAI
|
||||||
|
|
||||||
|
from danswer.configs.model_configs import GEN_AI_API_KEY
|
||||||
from danswer.configs.model_configs import GEN_AI_TEMPERATURE
|
from danswer.configs.model_configs import GEN_AI_TEMPERATURE
|
||||||
from danswer.llm.llm import LangChainChatLLM
|
from danswer.llm.llm import LangChainChatLLM
|
||||||
from danswer.llm.utils import should_be_verbose
|
from danswer.llm.utils import should_be_verbose
|
||||||
@@ -24,7 +24,7 @@ class OpenAIGPT(LangChainChatLLM):
|
|||||||
# exception when trying to initialize the LLM which would prevent the API
|
# exception when trying to initialize the LLM which would prevent the API
|
||||||
# server from starting up
|
# server from starting up
|
||||||
if not api_key:
|
if not api_key:
|
||||||
api_key = os.environ.get("OPENAI_API_KEY") or "dummy_api_key"
|
api_key = GEN_AI_API_KEY
|
||||||
|
|
||||||
self._llm = ChatOpenAI(
|
self._llm = ChatOpenAI(
|
||||||
model=model_version,
|
model=model_version,
|
||||||
|
Reference in New Issue
Block a user