Skip to content

Commit

Permalink
fix: tests after strict property removal
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Dec 9, 2024
1 parent 4ca0d1d commit 3d7e68d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ public void ItInitializesOpenAIFunctionReturnParameterCorrectly(string? descript
Assert.Same(schema, functionParameter.Schema);
}

[InlineData(null, false)]
[InlineData(true, false)]
[InlineData(false, false)]
[InlineData(null, true)]
[InlineData(true, true)]
[InlineData(false, true)]
[Theory]
public void ItSetsTheStrictModeAccordingToAllowance(bool? allowed, bool strict)
{
OpenAIFunction sut = new KernelFunctionMetadata("foo") { Strict = strict }.ToOpenAIFunction(allowed);
Assert.Equal((allowed ?? true) && strict, sut.Strict);
}

[Fact]
public void ItCanConvertToFunctionDefinitionWithNoPluginName()
{
Expand All @@ -78,21 +65,19 @@ public void ItCanConvertToFunctionDefinitionWithNoPluginName()
public void ItCanConvertToFunctionDefinitionWithNullParameters(bool strict)
{
// Arrange
OpenAIFunction sut = new("plugin", "function", "description", null, null, strict);
OpenAIFunction sut = new("plugin", "function", "description", null, null);

// Act
var result = sut.ToFunctionDefinition();
var result = sut.ToFunctionDefinition(strict);

// Assert
if (strict)
{
Assert.Equal("{\"type\":\"object\",\"required\":[],\"properties\":{},\"additionalProperties\":false}", result.FunctionParameters.ToString());
Assert.True(sut.Strict);
}
else
{
Assert.Equal("{\"type\":\"object\",\"required\":[],\"properties\":{}}", result.FunctionParameters.ToString());
Assert.False(sut.Strict);
}
}

Expand All @@ -105,9 +90,9 @@ public void SetsParametersToRequiredWhenStrict(bool strict)
{
new ("foo", "bar", false, typeof(string), null),
};
OpenAIFunction sut = new("plugin", "function", "description", parameters, null, strict);
OpenAIFunction sut = new("plugin", "function", "description", parameters, null);

var result = sut.ToFunctionDefinition();
var result = sut.ToFunctionDefinition(strict);

Assert.Equal(strict, result.FunctionSchemaIsStrict);
if (strict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,23 @@ public void AutoInvokeKernelFunctionsReturnsCorrectKernelFunctionsInstance()
Assert.Equal(DefaultMaximumAutoInvokeAttempts, behavior.MaximumAutoInvokeAttempts);
}

[InlineData(true)]
[InlineData(false)]
[Theory]
public void EnableFunctionsReturnsEnabledFunctionsInstance(bool strict)
[Fact]
public void EnableFunctionsReturnsEnabledFunctionsInstance()
{
// Arrange & Act
List<OpenAIFunction> functions = [new("Plugin", "Function", "description", [], null, strict)];
List<OpenAIFunction> functions = [new("Plugin", "Function", "description", [], null)];
var behavior = ToolCallBehavior.EnableFunctions(functions);

// Assert
Assert.IsType<EnabledFunctions>(behavior);
Assert.Contains($"{nameof(EnabledFunctions)}(autoInvoke:{behavior.MaximumAutoInvokeAttempts != 0})", behavior.ToString());
}

[InlineData(true)]
[InlineData(false)]
[Theory]
public void RequireFunctionReturnsRequiredFunctionInstance(bool strict)
[Fact]
public void RequireFunctionReturnsRequiredFunctionInstance()
{
// Arrange & Act
var behavior = ToolCallBehavior.RequireFunction(new("Plugin", "Function", "description", [], null, strict));
var behavior = ToolCallBehavior.RequireFunction(new("Plugin", "Function", "description", [], null));

// Assert
Assert.IsType<RequiredFunction>(behavior);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public void CopyConstructorCopiesPropertiesValues()
{ "method", "POST" },
{ "path", "/api/v1" },
}),
Strict = true,
PluginName = "plugin",
Name = "funcA",
};
Expand All @@ -231,7 +230,6 @@ public void CopyConstructorCopiesPropertiesValues()
Assert.Equal(original.Parameters, copy.Parameters);
Assert.Equal(original.PluginName, copy.PluginName);
Assert.Equal(original.ReturnParameter, copy.ReturnParameter);
Assert.Equal(original.Strict, copy.Strict);
}

private static void ValidFunctionName() { }
Expand Down

0 comments on commit 3d7e68d

Please sign in to comment.