Skip to content

Remove the usage of required modifier #239

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bugs Fixed

- Addressed an issue that caused multi-page queries of fine-tuning jobs, checkpoints, and events to fail. (commit_hash)
- Removed the public default constructors from `VectorStoreExpirationPolicy` and `FunctionToolDefinition`. (commit_hash)

## 2.0.0-beta.11 (2024-09-03)

Expand Down
8 changes: 3 additions & 5 deletions .dotnet/api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,9 @@ public class FileSearchToolResources : IJsonModel<FileSearchToolResources>, IPer
BinaryData IPersistableModel<FileSearchToolResources>.Write(ModelReaderWriterOptions options);
}
public class FunctionToolDefinition : ToolDefinition, IJsonModel<FunctionToolDefinition>, IPersistableModel<FunctionToolDefinition> {
public FunctionToolDefinition();
public FunctionToolDefinition(string name);
public string Description { get; set; }
public required string FunctionName { get; set; }
public string FunctionName { get; set; }
public BinaryData Parameters { get; set; }
public bool? StrictParameterSchemaEnabled { get; set; }
FunctionToolDefinition IJsonModel<FunctionToolDefinition>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
Expand Down Expand Up @@ -2297,10 +2296,9 @@ public enum VectorStoreExpirationAnchor {
LastActiveAt = 1
}
public class VectorStoreExpirationPolicy : IJsonModel<VectorStoreExpirationPolicy>, IPersistableModel<VectorStoreExpirationPolicy> {
public VectorStoreExpirationPolicy();
public VectorStoreExpirationPolicy(VectorStoreExpirationAnchor anchor, int days);
public required VectorStoreExpirationAnchor Anchor { get; set; }
public required int Days { get; set; }
public VectorStoreExpirationAnchor Anchor { get; set; }
public int Days { get; set; }
VectorStoreExpirationPolicy IJsonModel<VectorStoreExpirationPolicy>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
void IJsonModel<VectorStoreExpirationPolicy>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
VectorStoreExpirationPolicy IPersistableModel<VectorStoreExpirationPolicy>.Create(BinaryData data, ModelReaderWriterOptions options);
Expand Down
6 changes: 2 additions & 4 deletions .dotnet/examples/Assistants/Example02_FunctionCalling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ string GetCurrentLocation()

const string GetCurrentLocationFunctionName = "get_current_location";

FunctionToolDefinition getLocationTool = new()
FunctionToolDefinition getLocationTool = new(GetCurrentLocationFunctionName)
{
FunctionName = GetCurrentLocationFunctionName,
Description = "Get the user's current location"
};

Expand All @@ -36,9 +35,8 @@ string GetCurrentWeather(string location, string unit = "celsius")

const string GetCurrentWeatherFunctionName = "get_current_weather";

FunctionToolDefinition getWeatherTool = new()
FunctionToolDefinition getWeatherTool = new(GetCurrentWeatherFunctionName)
{
FunctionName = GetCurrentWeatherFunctionName,
Description = "Get the current weather in a given location",
Parameters = BinaryData.FromString("""
{
Expand Down
6 changes: 2 additions & 4 deletions .dotnet/examples/Assistants/Example02_FunctionCallingAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ string GetCurrentLocation()

const string GetCurrentLocationFunctionName = "get_current_location";

FunctionToolDefinition getLocationTool = new()
FunctionToolDefinition getLocationTool = new(GetCurrentLocationFunctionName)
{
FunctionName = GetCurrentLocationFunctionName,
Description = "Get the user's current location"
};

Expand All @@ -36,9 +35,8 @@ string GetCurrentWeather(string location, string unit = "celsius")

const string GetCurrentWeatherFunctionName = "get_current_weather";

FunctionToolDefinition getWeatherTool = new()
FunctionToolDefinition getWeatherTool = new(GetCurrentWeatherFunctionName)
{
FunctionName = GetCurrentWeatherFunctionName,
Description = "Get the current weather in a given location",
Parameters = BinaryData.FromString("""
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public async Task Example02b_FunctionCallingStreaming()

// First, define the functions that the assistant will use in its defined tools.

FunctionToolDefinition getTemperatureTool = new()
FunctionToolDefinition getTemperatureTool = new("get_current_temperature")
{
FunctionName = "get_current_temperature",
Description = "Gets the current temperature at a specific location.",
Parameters = BinaryData.FromString("""
{
Expand All @@ -41,9 +40,8 @@ public async Task Example02b_FunctionCallingStreaming()
"""),
};

FunctionToolDefinition getRainProbabilityTool = new()
FunctionToolDefinition getRainProbabilityTool = new("get_current_rain_probability")
{
FunctionName = "get_current_rain_probability",
Description = "Gets the current forecasted probability of rain at a specific location,"
+ " represented as a percent chance in the range of 0 to 100.",
Parameters = BinaryData.FromString("""
Expand Down
3 changes: 1 addition & 2 deletions .dotnet/examples/Assistants/Example04_AllTheTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ static string GetNameOfFamilyMember(string relation)
_ => throw new ArgumentException(relation, nameof(relation))
};

FunctionToolDefinition getNameOfFamilyMemberTool = new()
FunctionToolDefinition getNameOfFamilyMemberTool = new(nameof(GetNameOfFamilyMember))
{
FunctionName = nameof(GetNameOfFamilyMember),
Description = "Provided a family relation type like 'father' or 'mother', "
+ "gets the name of the related person from the user.",
Parameters = BinaryData.FromString("""
Expand Down
11 changes: 1 addition & 10 deletions .dotnet/src/Custom/Assistants/FunctionToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class FunctionToolDefinition : ToolDefinition
private readonly InternalFunctionDefinition _internalFunction;

/// <inheritdoc cref="InternalFunctionDefinition.Name"/>
public required string FunctionName
public string FunctionName
{
get => _internalFunction.Name;
set => _internalFunction.Name = value;
Expand Down Expand Up @@ -52,15 +52,6 @@ public FunctionToolDefinition(string name)
_internalFunction = new(null, name, null, null, null);
}

/// <summary>
/// Creates a new instance of <see cref="FunctionToolDefinition"/>.
/// </summary>
public FunctionToolDefinition()
: base("function")
{
_internalFunction = new InternalFunctionDefinition();
}

[SetsRequiredMembers]
internal FunctionToolDefinition(string type, IDictionary<string, BinaryData> serializedAdditionalRawData, InternalFunctionDefinition function)
: base(type, serializedAdditionalRawData)
Expand Down
10 changes: 2 additions & 8 deletions .dotnet/src/Custom/VectorStores/VectorStoreExpirationPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public partial class VectorStoreExpirationPolicy
private int _days;

/// <summary> Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at`. </summary>
public required VectorStoreExpirationAnchor Anchor
public VectorStoreExpirationAnchor Anchor
{
get => _anchor;
set => _anchor = value;
}

/// <summary> The number of days after the anchor time that the vector store will expire. </summary>
public required int Days
public int Days
{
get => _days;
set => _days = value;
Expand All @@ -44,12 +44,6 @@ public VectorStoreExpirationPolicy(VectorStoreExpirationAnchor anchor, int days)
Anchor = anchor;
}

/// <summary> Initializes a new instance of <see cref="VectorStoreExpirationPolicy"/>. </summary>
public VectorStoreExpirationPolicy()
{
SerializedAdditionalRawData = new ChangeTrackingDictionary<string, BinaryData>();
}

/// <summary> Initializes a new instance of <see cref="VectorStoreExpirationPolicy"/>. </summary>
/// <param name="anchor"> Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at`. </param>
/// <param name="days"> The number of days after the anchor time that the vector store will expire. </param>
Expand Down
6 changes: 2 additions & 4 deletions .dotnet/tests/Assistants/AssistantTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,8 @@ public void FunctionToolsWork()
{
Tools =
{
new FunctionToolDefinition()
new FunctionToolDefinition("get_favorite_food_for_day_of_week")
{
FunctionName = "get_favorite_food_for_day_of_week",
Description = "gets the user's favorite food for a given day of the week, like Tuesday",
Parameters = BinaryData.FromObjectAsJson(new
{
Expand Down Expand Up @@ -498,9 +497,8 @@ AsyncCollectionResult<StreamingUpdate> streamingResult
public async Task StreamingToolCall()
{
AssistantClient client = GetTestClient();
FunctionToolDefinition getWeatherTool = new()
FunctionToolDefinition getWeatherTool = new("get_current_weather")
{
FunctionName = "get_current_weather",
Description = "Gets the user's current weather",
};
Assistant assistant = await client.CreateAssistantAsync("gpt-4o-mini", new()
Expand Down
6 changes: 1 addition & 5 deletions .dotnet/tests/Assistants/VectorStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public void CanCreateGetAndDeleteVectorStores()
{
FileIds = { testFiles[0].Id },
Name = "test vector store",
ExpirationPolicy = new VectorStoreExpirationPolicy()
{
Anchor = VectorStoreExpirationAnchor.LastActiveAt,
Days = 3,
},
ExpirationPolicy = new VectorStoreExpirationPolicy(VectorStoreExpirationAnchor.LastActiveAt, 3),
Metadata =
{
["test-key"] = "test-value",
Expand Down
Loading