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

[.Net] Stop generating Azure.AI.OpenAI.FunctionDefinition in AutoGen.SourceGenerator #3134

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task CodeSnippet5()
},
functionMap: new Dictionary<string, Func<string, Task<string>>>
{
{ this.UpperCaseFunction.Name, this.UpperCaseWrapper }, // The wrapper function for the UpperCase function
{ this.UpperCaseFunctionContract.Name, this.UpperCaseWrapper }, // The wrapper function for the UpperCase function
});

var response = await assistantAgent.SendAsync("hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using AutoGen.Core;
using AutoGen.DotnetInteractive;
using AutoGen.OpenAI;
using AutoGen.OpenAI.Extension;
using FluentAssertions;

public partial class Example07_Dynamic_GroupChat_Calculate_Fibonacci
Expand Down Expand Up @@ -138,7 +139,7 @@ public static async Task<IAgent> CreateReviewerAgentAsync()
name: "code_reviewer",
systemMessage: @"You review code block from coder",
config: gpt3Config,
functions: [functions.ReviewCodeBlockFunction],
functions: [functions.ReviewCodeBlockFunctionContract.ToOpenAIFunctionDefinition()],
functionMap: new Dictionary<string, Func<string, Task<string>>>()
{
{ nameof(ReviewCodeBlock), functions.ReviewCodeBlockWrapper },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json.Serialization;
using AutoGen.Core;
using AutoGen.LMStudio;
using AutoGen.OpenAI.Extension;
using Azure.AI.OpenAI;

namespace AutoGen.BasicSample;
Expand Down Expand Up @@ -69,8 +70,8 @@ public static async Task RunAsync()
// And ask agent to response in function call object format using few-shot example
object[] functionList =
[
SerializeFunctionDefinition(instance.GetWeatherFunction),
SerializeFunctionDefinition(instance.GoogleSearchFunction)
SerializeFunctionDefinition(instance.GetWeatherFunctionContract.ToOpenAIFunctionDefinition()),
SerializeFunctionDefinition(instance.GetWeatherFunctionContract.ToOpenAIFunctionDefinition())
];
var functionListString = JsonSerializer.Serialize(functionList, new JsonSerializerOptions { WriteIndented = true });
var lmAgent = new LMStudioAgent(
Expand Down Expand Up @@ -98,12 +99,12 @@ You are a helpful AI assistant
{
var arguments = JsonSerializer.Serialize(functionCall.Arguments);
// invoke function wrapper
if (functionCall.Name == instance.GetWeatherFunction.Name)
if (functionCall.Name == instance.GetWeatherFunctionContract.Name)
{
var result = await instance.GetWeatherWrapper(arguments);
return new TextMessage(Role.Assistant, result);
}
else if (functionCall.Name == instance.GoogleSearchFunction.Name)
else if (functionCall.Name == instance.GetWeatherFunctionContract.Name)
{
var result = await instance.GoogleSearchWrapper(arguments);
return new TextMessage(Role.Assistant, result);
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Core/Function/FunctionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FunctionContract
/// <summary>
/// The name of the function.
/// </summary>
public string? Name { get; set; }
public string Name { get; set; } = null!;

/// <summary>
/// The description of the function.
Expand Down
Loading
Loading