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

added DefineFunction #444

Merged
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
4 changes: 2 additions & 2 deletions OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToolDefinition> { new() { Function = fn1 }, new() { Function = fn2 }, new() { Function = fn3 }, new() { Function = fn4 }, new() { Function = fn4 } },
Tools = new List<ToolDefinition> { 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:
Expand Down Expand Up @@ -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<ToolDefinition> { new() { Function = fn1 }, new() { Function = fn2 }, new() { Function = fn3 }, new() { Function = fn4 }, new() { Function = fn4 } },
Tools = new List<ToolDefinition> { 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:
Expand Down
6 changes: 6 additions & 0 deletions OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public object? FunctionCalculated
return Function ?? FunctionsAsObject;
}
}

public static ToolDefinition DefineFunction(FunctionDefinition function) => new()
{
Type = StaticValues.CompletionStatics.ToolType.Function,
Function = function
};
}