-
Notifications
You must be signed in to change notification settings - Fork 887
Replace AzureOpenAIClient with OpenAIClient using BearerTokenPolicy #2783
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
base: main
Are you sure you want to change the base?
Conversation
… Batch 1 Co-authored-by: stephentoub <[email protected]>
… Batch 2 Co-authored-by: stephentoub <[email protected]>
Co-authored-by: stephentoub <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates from AzureOpenAIClient to the base OpenAIClient class with appropriate authentication policies, aligning with the recommended authentication pattern for Azure AI services. This is a non-breaking change that standardizes the authentication approach across the codebase.
Key Changes:
- Token-based authentication now uses
OpenAIClientwithBearerTokenPolicywrappingAzureCliCredentialorDefaultAzureCredential - Key-based authentication now uses
OpenAIClientwithApiKeyCredentialinstead ofAzureKeyCredential - All endpoints are updated to include the
/openai/v1route suffix
Reviewed changes
Copilot reviewed 67 out of 67 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TestHelper.cs | Updated test helper to use OpenAIClient with BearerTokenPolicy and ApiKeyCredential |
| dotnet/src/Microsoft.Agents.AI.Purview/README.md | Updated documentation examples with new authentication pattern |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md | Updated documentation examples with new client instantiation |
| dotnet/samples/Purview/AgentWithPurview/Program.cs | Migrated Purview sample to use OpenAIClient |
| dotnet/samples/M365Agent/Program.cs | Updated M365 agent to use new authentication |
| dotnet/samples/HostedAgents/* | Updated all hosted agent samples with new client pattern |
| dotnet/samples/GettingStarted/Workflows/* | Migrated all workflow samples to OpenAIClient |
| dotnet/samples/GettingStarted/ModelContextProtocol/* | Updated MCP samples with new authentication |
| dotnet/samples/GettingStarted/DevUI/* | Updated DevUI samples to use OpenAIClient |
| dotnet/samples/GettingStarted/DeclarativeAgents/* | Migrated declarative agent samples |
| dotnet/samples/GettingStarted/Agents/* | Updated all agent step samples (01-19) with new pattern |
| dotnet/samples/GettingStarted/AgentWithRAG/* | Updated RAG samples with OpenAIClient |
| dotnet/samples/GettingStarted/AgentWithMemory/* | Migrated memory samples to new authentication |
| dotnet/samples/GettingStarted/AgentProviders/* | Updated provider samples with OpenAIClient |
| dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs | Updated observability sample with new client |
| dotnet/samples/GettingStarted/AGUI/* | Migrated all AGUI samples to new pattern |
| dotnet/samples/GettingStarted/A2A/* | Updated A2A sample with OpenAIClient |
| dotnet/samples/AzureFunctions/* | Updated all Azure Functions samples (01-07) with new authentication |
| dotnet/samples/AGUIWebChat/* | Migrated web chat sample and documentation |
| dotnet/samples/AGUIClientServer/* | Updated client-server samples with OpenAIClient |
| dotnet/README.md | Updated main documentation with new authentication example |
dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TestHelper.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/AzureFunctions/05_AgentOrchestration_HITL/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs
Outdated
Show resolved
Hide resolved
|
@copilot, please address all of the feedback |
…le naming Co-authored-by: stephentoub <[email protected]>
Addressed all feedback in commit 9ea27f9:
|
Motivation and Context
All Azure OpenAI usage (except OpenAI Assistants) should use the base
OpenAIClientwithBearerTokenPolicyinstead of the derivedAzureOpenAIClient. This aligns with the recommended authentication pattern for Azure AI services.Description
Replaced all
AzureOpenAIClientinstantiations across samples, tests, and documentation withOpenAIClientusing appropriate authentication:Token-based authentication (AzureCliCredential/DefaultAzureCredential):
Key-based authentication:
Files updated (67 total):
Code review improvements:
OpenAIClientOptionsinto a variable in AzureFunctions samples to avoid duplication in ternary expressionsTrimEnd('/')to endpoint construction in TestHelper.cs to prevent malformed URLs with double slashesazureOpenAIClienttoopenAIClientin Agent_Step14_Middleware sampleContribution Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.