Skip to content

Instantly share code, notes, and snippets.

@HamedFathi
Forked from primaryobjects/readme.md
Created July 20, 2023 14:19
Show Gist options
  • Save HamedFathi/f34f39dfe2966e8586642f16c2e4a4ca to your computer and use it in GitHub Desktop.
Save HamedFathi/f34f39dfe2966e8586642f16c2e4a4ca to your computer and use it in GitHub Desktop.
How to Configure AutoGPT with Azure OpenAI Active Directory Managed Identity

How to Configure AutoGPT with Azure OpenAI Active Directory Managed Identity

AutoGPT is an extension of ChatGPT to automatically run an agent to complete a solution without human intervention.

Normally, an OpenAI API key is used.

For Azure OpenAI, you must use either an API token or an Azure Active Directory account.

Loading an API Key with Azure Managed Identity

  1. Download and install Azure CLI.

    pip install azure-cli azure-functions azure-identity
  2. Login to Azure.

    az login
  3. Obtain an API key or modify your run.sh script to automate.

    export accessToken=$(az account get-access-token --resource https://cognitiveservices.azure.com | jq -r .accessToken)
    echo $accessToken
  4. Copy and paste the accessToken contents into your AutoGPT env file.

    OPENAI_API_KEY=<accessToken contents go here>
    USE_AZURE=True
    
  5. Create a file named azure.yaml with the following contents, adjust for your Azure account:

    azure_api_type: azure_ad
    azure_api_base: https://your-domain.openai.azure.com
    azure_api_version: 2023-03-01-preview
    azure_model_map:
        fast_llm_model_deployment_id: gpt-4
        smart_llm_model_deployment_id: gpt-4
        embedding_model_deployment_id: text-embedding-ada-002
    

Automatic Login to Azure

You can setup run.sh to automatically extract the accessToken each time you run AutoGPT by editing the script as follows:

#!/bin/bash
python3 scripts/check_requirements.py requirements.txt
if [ $? -eq 1 ]
then
    echo Installing missing packages...
    pip install -r requirements.txt
fi

export accessToken=$(az account get-access-token --resource https://cognitiveservices.azure.com | jq -r .accessToken)
sed -i "s/OPENAI_API_KEY=.*/OPENAI_API_KEY=$accessToken/" ./.env

python3 -m autogpt $@
read -p "Press any key to continue..."

Specifically, note the lines to export the token and run sed.

Additional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment