-
Notifications
You must be signed in to change notification settings - Fork 841
Support DisplayNameAttribute for name resolution in AI libraries #6942
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
Conversation
Co-authored-by: eiriktsarpalis <[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 adds support for using DisplayNameAttribute to specify the name of AI functions created via AIFunctionFactory, addressing issue #6941. This allows developers to define function names alongside their method definitions using attributes, rather than having to specify names separately during factory creation.
Key changes:
- Modified
AIFunctionFactory.csto check forDisplayNameAttributewhen resolving function names - Added comprehensive test coverage for the new functionality including precedence rules
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs | Updated name resolution logic to check for DisplayNameAttribute between explicit name parameter and fallback to method name |
| test/Libraries/Microsoft.Extensions.AI.Tests/Functions/AIFunctionFactoryTest.cs | Added test method with multiple test cases covering DisplayNameAttribute functionality and precedence rules |
Co-authored-by: eiriktsarpalis <[email protected]>
Co-authored-by: eiriktsarpalis <[email protected]>
|
@copilot, please search the repo for Description Attribute. Anywhere it's being referenced, there's likely a nearby place that should be updated for Display Name as well. For example in AIFunctionFactoryOptions, ChatResponse Format, etc |
…ities Co-authored-by: stephentoub <[email protected]>
I've added DisplayNameAttribute support to the following locations where DescriptionAttribute is used:
The changes maintain the same priority order across all locations:
Added comprehensive tests for all three locations and all tests pass (352 AI tests, 1,048 AI.Abstractions tests). |
Co-authored-by: stephentoub <[email protected]>
stephentoub
left a comment
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.
@copilot, please fix the analyzer warnings:
Build FAILED.
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(431,21): error S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. (https://rules.sonarsource.com/csharp/RSPEC-1186) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net9.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(432,9): error S108: Either remove or fill this block of code. (https://rules.sonarsource.com/csharp/RSPEC-108) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net9.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(449,21): error S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. (https://rules.sonarsource.com/csharp/RSPEC-1186) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net9.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(450,9): error S108: Either remove or fill this block of code. (https://rules.sonarsource.com/csharp/RSPEC-108) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net9.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(431,21): error S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. (https://rules.sonarsource.com/csharp/RSPEC-1186) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net8.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(432,9): error S108: Either remove or fill this block of code. (https://rules.sonarsource.com/csharp/RSPEC-108) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net8.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(449,21): error S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. (https://rules.sonarsource.com/csharp/RSPEC-1186) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net8.0]
/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs(450,9): error S108: Either remove or fill this block of code. (https://rules.sonarsource.com/csharp/RSPEC-108) [/mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj::TargetFramework=net8.0]
0 Warning(s)
8 Error(s)
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
Summary of Changes
This PR implements support for the
DisplayNameAttributeto define names throughout the AI libraries, as requested in the issue.Changes Made:
DisplayNameAttributebefore falling back to method name. Updated documentation fornameparameters to mentionDisplayNameAttribute.DisplayNameAttributesupport for schema names when creating response formats from typesDisplayNameAttributesupport for method titles in JSON schema creationNameproperty to mentionDisplayNameAttributePriority Chain:
The resolution priority for names is now consistently (across all locations):
name,schemaName,title)Tests:
Example Usage:
Security Summary:
The changes are minimal and safe:
Original prompt
Fixes #6941
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow