In this tutorial, we will guide you through setting up your environment variables for Azure services using an .env file. Environment variables allow you to securely manage sensitive credentials, such as API keys, without hard-coding them into your codebase.
Important
- Only one language model service (Azure OpenAI or OpenAI) needs to be configured. Fill in the environment variables for your preferred service. If environment variables for multiple language models are set, the co-op translator will select one based on priority.
- If Computer Vision environment variables are not set, the translator will automatically switch to Markdown-only mode.
Note
This guide primarily focuses on Azure services, but you can choose any supported language model from the supported models and services list.
In the root directory of your project, create a file named .env. This file will store all your environment variables in a simple format.
Warning
Do not commit your .env file to version control systems like Git. Add .env to your .gitignore file to prevent accidental commits.
-
Navigate to the root directory of your project.
-
Create an .env file in the root directory of your project.
-
Open the .env file and paste the following template:
# Azure Credentials AZURE_SUBSCRIPTION_KEY="your_azure_subscription_key" AZURE_AI_SERVICE_ENDPOINT="https://your_azure_ai_service_endpoint" # Azure OpenAI Credentials AZURE_OPENAI_API_KEY="your_azure_openai_api_key" AZURE_OPENAI_ENDPOINT="https://your_azure_openai_endpoint" AZURE_OPENAI_MODEL_NAME="your_model_name" AZURE_OPENAI_CHAT_DEPLOYMENT_NAME="your_deployment_name" AZURE_OPENAI_API_VERSION="your_api_version" # OpenAI Credentials OPENAI_API_KEY="your_openai_api_key" OPENAI_ORG_ID="your_openai_org_id" OPENAI_CHAT_MODEL_ID="your_chat_model_id(ex. gpt-4o)" OPENAI_BASE_URL="https://api.openai.com/v1 (If you don't have a custom base URL, you can delete this lin, then it will use the default base URL)"
You will need the following Azure credentials on hand to configure the environment:
-
For Azure AI Service:
- Azure Subscription Key: Your Azure subscription key, which allows you to access the Azure AI services.
- Azure AI Service Endpoint: The endpoint URL for your specific Azure AI service.
-
For Azure OpenAI Service:
- Azure OpenAI API Key: The API key for accessing Azure OpenAI services.
- Azure OpenAI Endpoint: The endpoint URL for your Azure OpenAI service.
- Azure OpenAI Model Name: The name of the model you will be interacting with.
- Azure OpenAI Deployment Name: The name of your deployment for Azure OpenAI models.
- Azure OpenAI API Version: The version of the Azure OpenAI API you are using.
-
Perform the following tasks to add the Azure Subscription key and Azure AI Services Endpoint:
-
Perform the following tasks to add the Azure OpenAI API Key and Endpoint:
- Type azure openai in the search bar at the top of the portal page and select Azure OpenAI from the options that appear.
- Navigate the Azure OpenAI resource that you are currently using.
- Select Keys and Endpoint from the left side tab.
- Copy and paste your Azure OpenAI API Key and Endpoint into the .env file.
-
Perform the following tasks to add the Azure OpenAI Deployment Name and Version:
-
Save the .env file.
-
Now, you can access these environment variables to use Co-op Translator with your Azure services.