Skip to content

Commit

Permalink
Merge pull request #444 from betalgo/add-define-function-method-to-to…
Browse files Browse the repository at this point in the history
…ol-defination-class

added DefineFunction
  • Loading branch information
kayhantolga authored Dec 6, 2023
2 parents 984fa91 + 4a50f23 commit 3e82371
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
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
};
}

0 comments on commit 3e82371

Please sign in to comment.