diff --git a/.env.template b/.env.template index 525cd61c..cdf8e28c 100644 --- a/.env.template +++ b/.env.template @@ -10,5 +10,7 @@ USE_AZURE=False OPENAI_API_BASE=your-base-url-for-azure OPENAI_API_VERSION=api-version-for-azure OPENAI_DEPLOYMENT_ID=deployment-id-for-azure +AZURE_CHAT_DEPLOYMENT_ID=deployment-id-for-azure-chat-ai +AZURE_EMBEDDINGS_DEPLOYMENT_ID=deployment-id-for-azure-embeddigs-ai IMAGE_PROVIDER=dalle HUGGINGFACE_API_TOKEN= \ No newline at end of file diff --git a/README.md b/README.md index 118131e4..d93c598f 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ pip install -r requirements.txt 4. Rename `.env.template` to `.env` and fill in your `OPENAI_API_KEY`. If you plan to use Speech Mode, fill in your `ELEVEN_LABS_API_KEY` as well. - Obtain your OpenAI API key from: https://platform.openai.com/account/api-keys. - Obtain your ElevenLabs API key from: https://beta.elevenlabs.io. You can view your xi-api-key using the "Profile" tab on the website. - - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and provide the `OPENAI_API_BASE`, `OPENAI_API_VERSION` and `OPENAI_DEPLOYMENT_ID` values as explained here: https://pypi.org/project/openai/ in the `Microsoft Azure Endpoints` section + - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and provide the `OPENAI_API_BASE`, `OPENAI_API_VERSION` and `OPENAI_DEPLOYMENT_ID` values as explained here: https://pypi.org/project/openai/ in the `Microsoft Azure Endpoints` section. Additionally you need separate deployments for both embeddings and chat. Add their ID values to `AZURE_CHAT_DEPLOYMENT_ID` and `AZURE_EMBEDDINGS_DEPLOYMENT_ID` respectively ## 🔧 Usage diff --git a/scripts/config.py b/scripts/config.py index 1eb74b2b..7f446cd1 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -49,6 +49,8 @@ class Config(metaclass=Singleton): self.openai_api_base = os.getenv("OPENAI_API_BASE") self.openai_api_version = os.getenv("OPENAI_API_VERSION") self.openai_deployment_id = os.getenv("OPENAI_DEPLOYMENT_ID") + self.azure_chat_deployment_id = os.getenv("AZURE_CHAT_DEPLOYMENT_ID") + self.azure_embeddigs_deployment_id = os.getenv("AZURE_EMBEDDINGS_DEPLOYMENT_ID") openai.api_type = "azure" openai.api_base = self.openai_api_base openai.api_version = self.openai_api_version diff --git a/scripts/llm_utils.py b/scripts/llm_utils.py index 94ba5f13..3fb348f0 100644 --- a/scripts/llm_utils.py +++ b/scripts/llm_utils.py @@ -9,7 +9,7 @@ def create_chat_completion(messages, model=None, temperature=None, max_tokens=No """Create a chat completion using the OpenAI API""" if cfg.use_azure: response = openai.ChatCompletion.create( - deployment_id=cfg.openai_deployment_id, + deployment_id=cfg.azure_chat_deployment_id, model=model, messages=messages, temperature=temperature, diff --git a/scripts/memory/base.py b/scripts/memory/base.py index d7ab7fcf..bb22963a 100644 --- a/scripts/memory/base.py +++ b/scripts/memory/base.py @@ -1,12 +1,16 @@ """Base class for memory providers.""" import abc -from config import AbstractSingleton +from config import AbstractSingleton, Config import openai +cfg = Config() def get_ada_embedding(text): text = text.replace("\n", " ") - return openai.Embedding.create(input=[text], model="text-embedding-ada-002")["data"][0]["embedding"] + if cfg.use_azure: + return openai.Embedding.create(input=[text], engine=cfg.azure_embeddigs_deployment_id, model="text-embedding-ada-002")["data"][0]["embedding"] + else: + return openai.Embedding.create(input=[text], model="text-embedding-ada-002")["data"][0]["embedding"] class MemoryProviderSingleton(AbstractSingleton):