Skip to content

Commit

Permalink
Document the usage of the AAD auth. microsoft#2880
Browse files Browse the repository at this point in the history
Added the document for the usage of AAD !
  • Loading branch information
prithvi2226 committed Jun 14, 2024
1 parent f36b658 commit 10e2a71
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 43 deletions.
44 changes: 22 additions & 22 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
"visualstudioexptteam.vscodeintellicode",
"GitHub.copilot"
],
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"terminal.integrated.defaultProfile.linux": "bash"
}
}
},
"dockerFile": "Dockerfile",
"updateContentCommand": "pip install -e . pre-commit && pre-commit install"
}
{
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
"visualstudioexptteam.vscodeintellicode",
"GitHub.copilot"
],
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"terminal.integrated.defaultProfile.linux": "bash"
}
}
},
"dockerFile": "Dockerfile",
"updateContentCommand": "pip install -e . pre-commit && pre-commit install"
}
42 changes: 21 additions & 21 deletions .devcontainer/studio/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
"visualstudioexptteam.vscodeintellicode"
],
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"terminal.integrated.defaultProfile.linux": "bash"
}
}
},
"dockerFile": "Dockerfile",
"updateContentCommand": "cd samples/apps/autogen-studio && pip install -e . && sudo npm install -g gatsby-cli && cd frontend && yarn install && yarn build"
}
{
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
"visualstudioexptteam.vscodeintellicode"
],
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"terminal.integrated.defaultProfile.linux": "bash"
}
}
},
"dockerFile": "Dockerfile",
"updateContentCommand": "cd samples/apps/autogen-studio && pip install -e . && sudo npm install -g gatsby-cli && cd frontend && yarn install && yarn build"
}
104 changes: 104 additions & 0 deletions website/docs/topics/llm_configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,110 @@
"In AutoGen, agents use LLMs as key components to understand and react. To configure an agent's access to LLMs, you can specify an `llm_config` argument in its constructor. For example, the following snippet shows a configuration that uses `gpt-4`:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using Azure Active Directory (AAD) Authentication\n",
"\n",
"Azure Active Directory (AAD) provides secure access to resources and applications. Follow the steps below to configure AAD authentication for the Microsoft Autogen.\n",
"\n",
"#### Prerequisites\n",
"- An Azure account with AAD configured.\n",
"- Appropriate permissions to register an application in AAD.\n",
"\n",
"#### Step 1: Register an Application in AAD\n",
"1. Navigate to the [Azure portal](https://portal.azure.com/).\n",
"2. Go to `Azure Active Directory` > `App registrations`.\n",
"3. Click on `New registration`.\n",
"4. Enter a name for your application.\n",
"5. Set the `Redirect URI` (optional).\n",
"6. Click `Register`.\n",
"\n",
"#### Step 2: Configure API Permissions\n",
"1. After registration, go to `API permissions`.\n",
"2. Click `Add a permission`.\n",
"3. Select `Microsoft Graph` and then `Delegated permissions`.\n",
"4. Add the necessary permissions (e.g., `User.Read`).\n",
"\n",
"#### Step 3: Obtain Client ID and Tenant ID\n",
"1. Go to `Overview` of your registered application.\n",
"2. Note down the `Application (client) ID` and `Directory (tenant) ID`.\n",
"\n",
"#### Step 4: Configure Your Application\n",
"Use the obtained `Client ID` and `Tenant ID` in your application configuration. Here’s an example of how to do this in your configuration file:\n",
"```\n",
"aad_config = {\n",
" \"client_id\": \"YOUR_CLIENT_ID\",\n",
" \"tenant_id\": \"YOUR_TENANT_ID\",\n",
" \"authority\": \"https://login.microsoftonline.com/YOUR_TENANT_ID\",\n",
" \"scope\": [\"https://graph.microsoft.com/.default\"],\n",
"}\n",
"```\n",
"#### Step 5: Authenticate and Acquire Tokens\n",
"Use the following code to authenticate and acquire tokens:\n",
"\n",
"```\n",
"from msal import ConfidentialClientApplication\n",
"\n",
"app = ConfidentialClientApplication(\n",
" client_id=aad_config[\"client_id\"],\n",
" client_credential=\"YOUR_CLIENT_SECRET\",\n",
" authority=aad_config[\"authority\"]\n",
")\n",
"\n",
"result = app.acquire_token_for_client(scopes=aad_config[\"scope\"])\n",
"\n",
"if \"access_token\" in result:\n",
" print(\"Token acquired\")\n",
"else:\n",
" print(\"Error acquiring token:\", result.get(\"error\"))\n",
"```\n",
"\n",
"#### Step 6: Configure Azure OpenAI with AAD Auth in AutoGen\n",
"To use AAD authentication with Azure OpenAI in AutoGen, configure the `llm_config` with the necessary parameters.\n",
"\n",
"Here is an example configuration:\n",
"\n",
"```\n",
"llm_config = {\n",
" \"config_list\": [\n",
" {\n",
" \"model\": \"gpt-4\",\n",
" \"base_url\": \"YOUR_BASE_URL\",\n",
" \"api_type\": \"azure\",\n",
" \"api_version\": \"2024-02-01\",\n",
" \"max_tokens\": 1000,\n",
" \"azure_ad_token_provider\": \"DEFAULT\"\n",
" }\n",
" ]\n",
"}\n",
"```\n",
"\n",
"In this configuration:\n",
"- `model`: The Azure OpenAI deployment name.\n",
"- `base_url`: The base URL of the Azure OpenAI endpoint.\n",
"- `api_type`: Should be set to \"azure\".\n",
"- `api_version`: The API version to use.\n",
"- `azure_ad_token_provider`: Set to \"DEFAULT\" to use the default token provider.\n",
"\n",
"#### Example of Initializing an Assistant Agent with AAD Auth\n",
"```\n",
"import autogen\n",
"\n",
"# Initialize the assistant agent with the AAD authenticated config\n",
"assistant = autogen.AssistantAgent(name=\"assistant\", llm_config=llm_config)\n",
"```\n",
"\n",
"#### Troubleshooting\n",
"If you encounter issues, check the following:\n",
"- Ensure your `Client ID` and `Tenant ID` are correct.\n",
"- Verify the permissions granted to your application.\n",
"- Check network connectivity and Azure service status.\n",
"\n",
"This documentation provides a complete guide to configure and use AAD authentication with Azure OpenAI in the AutoGen.\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down

0 comments on commit 10e2a71

Please sign in to comment.