Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #2880: Document the usage of the AAD auth #2941

Merged
merged 27 commits into from
Aug 2, 2024
Merged
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
10e2a71
Document the usage of the AAD auth. #2880
prithvi2226 Jun 14, 2024
1342c1a
Merge branch 'main' into patchwork
prithvi2226 Jun 14, 2024
fcc9280
Merge branch 'main' into patchwork
prithvi2226 Jun 14, 2024
25ce3c4
Merge branch 'main' into patchwork
prithvi2226 Jun 14, 2024
e455103
Merge branch 'main' into patchwork
prithvi2226 Jun 15, 2024
6676acf
Merge branch 'main' into patchwork
prithvi2226 Jun 18, 2024
6f253c5
Merge branch 'main' into patchwork
thinkall Jun 19, 2024
58240e5
Merge branch 'main' into patchwork
prithvi2226 Jun 19, 2024
fab52bf
Merge branch 'main' into patchwork
sonichi Jun 21, 2024
8373968
Update website/docs/topics/llm_configuration.ipynb
prithvi2226 Jun 26, 2024
394561b
Merge branch 'main' into patchwork
prithvi2226 Jun 26, 2024
e7d9f98
Updated Location and Link to Azure OpenAI documentation
prithvi2226 Jun 26, 2024
737f54e
Merge branch 'main' into patchwork
prithvi2226 Jun 26, 2024
b4cd016
Merge branch 'main' into patchwork
prithvi2226 Jun 27, 2024
6fbe478
Merge branch 'main' into patchwork
prithvi2226 Jun 28, 2024
cbb941b
Merge branch 'main' into patchwork
prithvi2226 Jul 1, 2024
1db2002
Merge branch 'main' into patchwork
prithvi2226 Jul 2, 2024
762cb2e
Merge branch 'main' into patchwork
prithvi2226 Jul 3, 2024
0004b36
Merge branch 'main' into patchwork
prithvi2226 Jul 3, 2024
26117c5
Merge branch 'main' into patchwork
prithvi2226 Jul 4, 2024
3eac646
Update AutoTX Link on Gallery.json (#3082)
prithvi2226 Jul 4, 2024
a86d0fd
Merge branch 'patchwork' of https://github.com/prithvi2226/autogen in…
prithvi2226 Jul 4, 2024
cd38794
Making the required changes
prithvi2226 Jul 5, 2024
e2efe2a
Revert "Making the required changes"
prithvi2226 Jul 5, 2024
0772fb9
Update llm_configuration.ipynb
prithvi2226 Jul 6, 2024
79dbb7b
Merge branch 'main' into patchwork
prithvi2226 Jul 6, 2024
7708c17
Merge branch 'main' into patchwork
thinkall Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
prithvi2226 marked this conversation as resolved.
Show resolved Hide resolved
"\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
Loading