mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-26 17:51:54 +01:00
Azure OpenAI integration (#293)
This commit is contained in:
parent
bb58dce1c5
commit
204d89a148
@ -81,3 +81,11 @@ GEN_AI_MAX_OUTPUT_TOKENS = int(os.environ.get("GEN_AI_MAX_OUTPUT_TOKENS", "512")
|
||||
|
||||
# Danswer custom Deep Learning Models
|
||||
INTENT_MODEL_VERSION = "danswer/intent-model"
|
||||
|
||||
#####
|
||||
# OpenAI Azure
|
||||
#####
|
||||
API_BASE_OPENAI = os.environ.get("API_BASE_OPENAI", "")
|
||||
API_TYPE_OPENAI = os.environ.get("API_TYPE_OPENAI", "").lower()
|
||||
API_VERSION_OPENAI = os.environ.get("API_VERSION_OPENAI", "")
|
||||
AZURE_DEPLOYMENT_ID = os.environ.get("AZURE_DEPLOYMENT_ID", "") # used interchangeably with "engine" parameter
|
@ -17,6 +17,10 @@ from danswer.chunking.models import InferenceChunk
|
||||
from danswer.configs.app_configs import INCLUDE_METADATA
|
||||
from danswer.configs.model_configs import GEN_AI_MAX_OUTPUT_TOKENS
|
||||
from danswer.configs.model_configs import GEN_AI_MODEL_VERSION
|
||||
from danswer.configs.model_configs import API_BASE_OPENAI
|
||||
from danswer.configs.model_configs import API_TYPE_OPENAI
|
||||
from danswer.configs.model_configs import API_VERSION_OPENAI
|
||||
from danswer.configs.model_configs import AZURE_DEPLOYMENT_ID
|
||||
from danswer.direct_qa.exceptions import OpenAIKeyMissing
|
||||
from danswer.direct_qa.interfaces import DanswerAnswer
|
||||
from danswer.direct_qa.interfaces import DanswerQuote
|
||||
@ -38,6 +42,12 @@ logger = setup_logger()
|
||||
|
||||
F = TypeVar("F", bound=Callable)
|
||||
|
||||
if API_BASE_OPENAI:
|
||||
openai.api_base = API_BASE_OPENAI
|
||||
if API_TYPE_OPENAI in ["azure"]: #TODO: Azure AD support ["azure_ad", "azuread"]
|
||||
openai.api_type = API_TYPE_OPENAI
|
||||
openai.api_version = API_VERSION_OPENAI
|
||||
|
||||
|
||||
def _ensure_openai_api_key(api_key: str | None) -> str:
|
||||
try:
|
||||
@ -55,6 +65,7 @@ def _build_openai_settings(**kwargs: Any) -> dict[str, Any]:
|
||||
"top_p": 1,
|
||||
"frequency_penalty": 0,
|
||||
"presence_penalty": 0,
|
||||
**({"deployment_id": AZURE_DEPLOYMENT_ID} if AZURE_DEPLOYMENT_ID else {}),
|
||||
**kwargs,
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,10 @@ services:
|
||||
- GOOGLE_OAUTH_CLIENT_ID=${GOOGLE_OAUTH_CLIENT_ID:-}
|
||||
- GOOGLE_OAUTH_CLIENT_SECRET=${GOOGLE_OAUTH_CLIENT_SECRET:-}
|
||||
- DISABLE_GENERATIVE_AI=${DISABLE_GENERATIVE_AI:-}
|
||||
- API_BASE_OPENAI${API_BASE_OPENAI:-}
|
||||
- API_TYPE_OPENAI=${API_TYPE_OPENAI:-}
|
||||
- API_VERSION_OPENAI=${API_VERSION_OPENAI:-}
|
||||
- AZURE_DEPLOYMENT_ID=${AZURE_DEPLOYMENT_ID:-}
|
||||
volumes:
|
||||
- local_dynamic_storage:/home/storage
|
||||
- file_connector_tmp_storage:/home/file_connector_storage
|
||||
|
@ -11,6 +11,12 @@ INTERNAL_MODEL_VERSION=openai-chat-completion
|
||||
# Use a valid model for the choice above, consult https://platform.openai.com/docs/models/model-endpoint-compatibility
|
||||
GEN_AI_MODEL_VERSION=gpt-4
|
||||
|
||||
# Neccessary environment variables for Azure OpenAI:
|
||||
API_BASE_OPENAI=
|
||||
API_TYPE_OPENAI=
|
||||
API_VERSION_OPENAI=
|
||||
AZURE_DEPLOYMENT_ID=
|
||||
|
||||
# Could be something like danswer.companyname.com. Requires additional setup if not localhost
|
||||
WEB_DOMAIN=http://localhost:3000
|
||||
|
||||
@ -47,3 +53,4 @@ SMTP_SERVER=
|
||||
SMTP_PORT=
|
||||
SMTP_USER=
|
||||
SMTP_PASS=
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user