forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.Net] Fix microsoft#2687 by adding global:: keyword in generated code (
microsoft#2689) * add tests * remove approved file * update * update approve file
- Loading branch information
1 parent
23e8d27
commit 7214921
Showing
9 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rator.Tests/ApprovalTests/FunctionCallTemplateTests.TestFunctionCallTemplate.approved.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//---------------------- | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// </auto-generated> | ||
//---------------------- | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using System; | ||
using AutoGen.Core; | ||
using AutoGen.OpenAI.Extension; | ||
|
||
namespace AutoGen.SourceGenerator.Tests | ||
{ | ||
public partial class FunctionExamples | ||
{ | ||
|
||
private class AddAsyncSchema | ||
{ | ||
[JsonPropertyName(@"a")] | ||
public System.Int32 a {get; set;} | ||
[JsonPropertyName(@"b")] | ||
public System.Int32 b {get; set;} | ||
} | ||
|
||
public System.Threading.Tasks.Task`1[System.String] AddAsyncWrapper(string arguments) | ||
{ | ||
var schema = JsonSerializer.Deserialize<AddAsyncSchema>( | ||
arguments, | ||
new JsonSerializerOptions | ||
{ | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
}); | ||
|
||
return AddAsync(schema.a, schema.b); | ||
} | ||
|
||
public FunctionContract AddAsyncFunctionContract | ||
{ | ||
get => new FunctionContract | ||
{ | ||
Name = @"AddAsync", | ||
Description = @"Add two numbers.", | ||
ReturnType = typeof(System.Threading.Tasks.Task`1[System.String]), | ||
Parameters = new [] | ||
{ | ||
new FunctionParameterContract | ||
{ | ||
Name = @"a", | ||
Description = @"The first number.", | ||
ParameterType = typeof(System.Int32), | ||
IsRequired = true, | ||
}, | ||
new FunctionParameterContract | ||
{ | ||
Name = @"b", | ||
Description = @"The second number.", | ||
ParameterType = typeof(System.Int32), | ||
IsRequired = true, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
public global::Azure.AI.OpenAI.FunctionDefinition AddAsyncFunction | ||
{ | ||
get => this.AddAsyncFunctionContract.ToOpenAIFunctionDefinition(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
dotnet/test/AutoGen.SourceGenerator.Tests/FunctionCallTemplateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// FunctionCallTemplateTests.cs | ||
|
||
using ApprovalTests; | ||
using ApprovalTests.Namers; | ||
using ApprovalTests.Reporters; | ||
using AutoGen.SourceGenerator.Template; | ||
using Xunit; | ||
|
||
namespace AutoGen.SourceGenerator.Tests; | ||
|
||
public class FunctionCallTemplateTests | ||
{ | ||
[Fact] | ||
[UseReporter(typeof(DiffReporter))] | ||
[UseApprovalSubdirectory("ApprovalTests")] | ||
public void TestFunctionCallTemplate() | ||
{ | ||
var functionExample = new FunctionExamples(); | ||
var function = functionExample.AddAsyncFunctionContract; | ||
var functionCallTemplate = new FunctionCallTemplate() | ||
{ | ||
ClassName = function.ClassName, | ||
NameSpace = function.Namespace, | ||
FunctionContracts = [new SourceGeneratorFunctionContract() | ||
{ | ||
Name = function.Name, | ||
Description = function.Description, | ||
ReturnType = function.ReturnType!.ToString(), | ||
ReturnDescription = function.ReturnDescription, | ||
Parameters = function.Parameters!.Select(p => new SourceGeneratorParameterContract() | ||
{ | ||
Name = p.Name, | ||
Description = p.Description, | ||
Type = p.ParameterType!.ToString(), | ||
IsOptional = !p.IsRequired, | ||
JsonType = p.ParameterType!.ToString(), | ||
}).ToArray() | ||
}] | ||
}; | ||
|
||
var actual = functionCallTemplate.TransformText(); | ||
|
||
Approvals.Verify(actual); | ||
} | ||
} |