Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ packages
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
.nuget/
!src/[Pp]ackages
!eng/[Pp]ackages

Expand Down
Binary file added .nuget/nuget.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ private ReflectionAIFunctionDescriptor(DescriptorKey key, JsonSerializerOptions

ReturnParameterMarshaller = GetReturnParameterMarshaller(key, serializerOptions, out Type? returnType);
Method = key.Method;
Name = key.Name ?? GetFunctionName(key.Method);
Name = key.Name ?? key.Method.GetCustomAttribute<DisplayNameAttribute>(inherit: true)?.DisplayName ?? GetFunctionName(key.Method);
Description = key.Description ?? key.Method.GetCustomAttribute<DescriptionAttribute>(inherit: true)?.Description ?? string.Empty;
JsonSerializerOptions = serializerOptions;
ReturnJsonSchema = returnType is null || key.ExcludeResultSchema ? null : AIJsonUtilities.CreateJsonSchema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,39 @@ public void Metadata_DerivedFromLambda()
p => Assert.Equal("This is B", p.GetCustomAttribute<DescriptionAttribute>()?.Description));
}

[Fact]
public void Metadata_DisplayNameAttribute()
{
// Test DisplayNameAttribute on a delegate method
Func<string> funcWithDisplayName = [DisplayName("get_user_id")] () => "test";
AIFunction func = AIFunctionFactory.Create(funcWithDisplayName);
Assert.Equal("get_user_id", func.Name);
Assert.Empty(func.Description);

// Test DisplayNameAttribute with DescriptionAttribute
Func<string> funcWithBoth = [DisplayName("my_function")][Description("A test function")] () => "test";
func = AIFunctionFactory.Create(funcWithBoth);
Assert.Equal("my_function", func.Name);
Assert.Equal("A test function", func.Description);

// Test that explicit name parameter takes precedence over DisplayNameAttribute
func = AIFunctionFactory.Create(funcWithDisplayName, name: "explicit_name");
Assert.Equal("explicit_name", func.Name);

// Test DisplayNameAttribute with options
func = AIFunctionFactory.Create(funcWithDisplayName, new AIFunctionFactoryOptions());
Assert.Equal("get_user_id", func.Name);

// Test that options.Name takes precedence over DisplayNameAttribute
func = AIFunctionFactory.Create(funcWithDisplayName, new AIFunctionFactoryOptions { Name = "options_name" });
Assert.Equal("options_name", func.Name);

// Test function without DisplayNameAttribute falls back to method name
Func<string> funcWithoutDisplayName = () => "test";
func = AIFunctionFactory.Create(funcWithoutDisplayName);
Assert.Contains("Metadata_DisplayNameAttribute", func.Name); // Will contain the lambda method name
}

[Fact]
public void AIFunctionFactoryCreateOptions_ValuesPropagateToAIFunction()
{
Expand Down
Loading