From 4a50f230c0fd65edba0355baeff423bdb31aa02b Mon Sep 17 00:00:00 2001 From: Tolga Kayhan Date: Wed, 6 Dec 2023 21:23:58 +0000 Subject: [PATCH] added DefineFunction --- OpenAI.Playground/Program.cs | 4 ++-- OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs | 4 ++-- OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/OpenAI.Playground/Program.cs b/OpenAI.Playground/Program.cs index 76f98c4c..7a060322 100644 --- a/OpenAI.Playground/Program.cs +++ b/OpenAI.Playground/Program.cs @@ -44,8 +44,8 @@ await ChatCompletionTestHelper.RunSimpleChatCompletionTest(sdk); //await ChatCompletionTestHelper.RunSimpleCompletionStreamTest(sdk); -//await ChatCompletionTestHelper.RunChatFunctionCallTest(sdk); -//await ChatCompletionTestHelper.RunChatFunctionCallTestAsStream(sdk); +await ChatCompletionTestHelper.RunChatFunctionCallTest(sdk); +await ChatCompletionTestHelper.RunChatFunctionCallTestAsStream(sdk); //await FineTuningJobTestHelper.RunCaseStudyIsTheModelMakingUntrueStatements(sdk); // Vision //await VisionTestHelper.RunSimpleVisionTest(sdk); diff --git a/OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs b/OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs index 6db2892e..5f22657a 100644 --- a/OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs +++ b/OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs @@ -130,7 +130,7 @@ public static async Task RunChatFunctionCallTest(IOpenAIService sdk) ChatMessage.FromSystem("Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."), ChatMessage.FromUser("Give me a weather report for Chicago, USA, for the next 5 days.") }, - Tools = new List { new() { Function = fn1 }, new() { Function = fn2 }, new() { Function = fn3 }, new() { Function = fn4 }, new() { Function = fn4 } }, + Tools = new List { ToolDefinition.DefineFunction(fn1), ToolDefinition.DefineFunction(fn2) ,ToolDefinition.DefineFunction(fn3) ,ToolDefinition.DefineFunction(fn4) }, // optionally, to force a specific function: //ToolChoice = ToolChoice.FunctionChoice("get_current_weather"), // or auto tool choice: @@ -233,7 +233,7 @@ public static async Task RunChatFunctionCallTestAsStream(IOpenAIService sdk) // or to test array functions, use this instead: // ChatMessage.FromUser("The combination is: One. Two. Three. Four. Five."), }, - Tools = new List { new() { Function = fn1 }, new() { Function = fn2 }, new() { Function = fn3 }, new() { Function = fn4 }, new() { Function = fn4 } }, + Tools = new List { ToolDefinition.DefineFunction(fn1), ToolDefinition.DefineFunction(fn2), ToolDefinition.DefineFunction(fn3), ToolDefinition.DefineFunction(fn4) }, // optionally, to force a specific function: ToolChoice = ToolChoice.FunctionChoice("get_current_weather"), // or auto tool choice: diff --git a/OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs b/OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs index d7fcb896..5a1cf9b8 100644 --- a/OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs +++ b/OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs @@ -40,4 +40,10 @@ public object? FunctionCalculated return Function ?? FunctionsAsObject; } } + + public static ToolDefinition DefineFunction(FunctionDefinition function) => new() + { + Type = StaticValues.CompletionStatics.ToolType.Function, + Function = function + }; } \ No newline at end of file