Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ public async Task CanCreateGetAndDeleteVectorStores()
deleted = await client.DeleteVectorStoreAsync(vectorStore.Id);
Assert.That(deleted, Is.True);

vectorStore = await client.CreateVectorStoreAsync(new VectorStoreCreationOptions()
var options = new VectorStoreCreationOptions();
foreach (var file in testFiles)
{
FileIds = testFiles.Select(file => file.Id).ToList()
});
options.FileIds.Add(file.Id);
}
vectorStore = await client.CreateVectorStoreAsync(options);
Validate(vectorStore);
Assert.Multiple(() =>
{
Expand Down
1 change: 1 addition & 0 deletions .dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Removed `ChatMessageContentPart`'s `ToString` overload. (commit_hash)
- Removed the common `ListOrder` enum from the top-level `OpenAI` namespace in favor of individual enums in their corresponding sub-namespace. (commit_hash)
- Renamed the `PageSize` property to `PageSizeLimit`. (commit_hash)
- Removed setter from collection properties.

### Bugs Fixed

Expand Down
8 changes: 4 additions & 4 deletions .dotnet/api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public class AssistantCreationOptions : IJsonModel<AssistantCreationOptions>, IP
BinaryData IPersistableModel<AssistantCreationOptions>.Write(ModelReaderWriterOptions options);
}
public class AssistantModificationOptions : IJsonModel<AssistantModificationOptions>, IPersistableModel<AssistantModificationOptions> {
public IList<ToolDefinition> DefaultTools { get; set; }
public IList<ToolDefinition> DefaultTools { get; }
Copy link
Copy Markdown
Owner

@joseharriaga joseharriaga Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Shivangi! After this change:

  • AssistantModificationOptions.DefaultTools
  • CodeInterpreterToolResources.FileIds
  • FileSearchToolResources.VectorStoreIds
  • VectorStoreCreationOptions.FileIds

The only collection properties left that have a setter are the following:

  • MessageCreationOptions.Attachments
  • AssistantCreationOptions.Metadata
  • AssistantModificationOptions.Metadata
  • MessageCreationOptions.Metadata
  • MessageModificationOptions.Metadata
  • RunModificationOptions.Metadata
  • ThreadCreationOptions.Metadata
  • ThreadModificationOptions.Metadata
  • VectoreStoreCreationOptions.Metadata
  • VectorStoreModificationOptions.Metadata

Paging in @trrwilson because we talked about something related a while ago. The properties above are getting a setter from the generator because they are explicitly specified as nullable in the TypeSpec (which itself comes from the swagger spec). Now, in basically every part of the REST API that I have encountered so far, setting a nullable property to null does not imply anything special and it's equivalent to not setting it at all. Assuming null doesn't mean anything special here either, I wonder if we should add a simple change to customize these properties to remove the setter in favor of consistency and a simpler API.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShivangiReja : I have approved this PR, and you can merge it. If we decide to revise these other properties, they can go in a separate PR. 😊

public string Description { get; set; }
public string Instructions { get; set; }
public IDictionary<string, string> Metadata { get; set; }
Expand Down Expand Up @@ -344,7 +344,7 @@ public class CodeInterpreterToolDefinition : ToolDefinition, IJsonModel<CodeInte
BinaryData IPersistableModel<CodeInterpreterToolDefinition>.Write(ModelReaderWriterOptions options);
}
public class CodeInterpreterToolResources : IJsonModel<CodeInterpreterToolResources>, IPersistableModel<CodeInterpreterToolResources> {
public IList<string> FileIds { get; set; }
public IList<string> FileIds { get; }
CodeInterpreterToolResources IJsonModel<CodeInterpreterToolResources>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
void IJsonModel<CodeInterpreterToolResources>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
CodeInterpreterToolResources IPersistableModel<CodeInterpreterToolResources>.Create(BinaryData data, ModelReaderWriterOptions options);
Expand All @@ -361,7 +361,7 @@ public class FileSearchToolDefinition : ToolDefinition, IJsonModel<FileSearchToo
}
public class FileSearchToolResources : IJsonModel<FileSearchToolResources>, IPersistableModel<FileSearchToolResources> {
public IList<VectorStoreCreationHelper> NewVectorStores { get; }
public IList<string> VectorStoreIds { get; set; }
public IList<string> VectorStoreIds { get; }
FileSearchToolResources IJsonModel<FileSearchToolResources>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
void IJsonModel<FileSearchToolResources>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
FileSearchToolResources IPersistableModel<FileSearchToolResources>.Create(BinaryData data, ModelReaderWriterOptions options);
Expand Down Expand Up @@ -2319,7 +2319,7 @@ public class VectorStoreCollectionOptions {
public class VectorStoreCreationOptions : IJsonModel<VectorStoreCreationOptions>, IPersistableModel<VectorStoreCreationOptions> {
public FileChunkingStrategy ChunkingStrategy { get; set; }
public VectorStoreExpirationPolicy ExpirationPolicy { get; set; }
public IList<string> FileIds { get; set; }
public IList<string> FileIds { get; }
public IDictionary<string, string> Metadata { get; set; }
public string Name { get; set; }
VectorStoreCreationOptions IJsonModel<VectorStoreCreationOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class AssistantModificationOptions
/// There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
/// </summary>
[CodeGenMember("Tools")]
public IList<ToolDefinition> DefaultTools { get; set; } = new ChangeTrackingList<ToolDefinition>();
public IList<ToolDefinition> DefaultTools { get; } = new ChangeTrackingList<ToolDefinition>();

// CUSTOM: reuse common request/response models for tool resources. Note that modification operations use the
// response models (which do not contain resource initialization helpers).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class CodeInterpreterToolResources
public IList<string> FileIds
{
get => _fileIds;
set
internal set
{
_fileIds = new ChangeTrackingList<string>();
foreach (string fileId in value)
Expand Down
2 changes: 1 addition & 1 deletion .dotnet/src/Custom/Assistants/FileSearchToolResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class FileSearchToolResources
public IList<string> VectorStoreIds
{
get => _vectorStoreIds;
set
internal set
{
_vectorStoreIds = new ChangeTrackingList<string>();
foreach (string item in value)
Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/VectorStores/VectorStoreCreationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ namespace OpenAI.VectorStores;
[CodeGenModel("CreateVectorStoreRequest")]
public partial class VectorStoreCreationOptions
{
/// <summary> A list of [File](/docs/api-reference/files) IDs that the vector store should use. Useful for tools like `file_search` that can access files. </summary>
public IList<string> FileIds { get; set; }

/// <summary> Gets or sets the policy that controls when the new vector store will be automatically deleted. </summary>
[CodeGenMember("ExpiresAfter")]
public VectorStoreExpirationPolicy ExpirationPolicy { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions .dotnet/src/Generated/Models/VectorStoreCreationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal VectorStoreCreationOptions(IList<string> fileIds, string name, VectorSt
Metadata = metadata;
SerializedAdditionalRawData = serializedAdditionalRawData;
}

public IList<string> FileIds { get; }
public string Name { get; set; }
public IDictionary<string, string> Metadata { get; set; }
}
Expand Down
20 changes: 14 additions & 6 deletions .dotnet/tests/Assistants/VectorStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ public void CanCreateGetAndDeleteVectorStores()
Assert.That(deleted, Is.True);
_vectorStoresToDelete.RemoveAt(_vectorStoresToDelete.Count - 1);

vectorStore = client.CreateVectorStore(new VectorStoreCreationOptions()
var options = new VectorStoreCreationOptions();
foreach (var file in testFiles)
{
FileIds = testFiles.Select(file => file.Id).ToList()
});
options.FileIds.Add(file.Id);
}
vectorStore = client.CreateVectorStore(options);

Validate(vectorStore);
Assert.Multiple(() =>
{
Expand Down Expand Up @@ -324,11 +327,16 @@ public async Task CanApplyChunkingStrategy(ChunkingStrategyKind strategyKind)
Assert.That(inputStaticStrategy.OverlappingTokenCount, Is.EqualTo(250));
}

VectorStore vectorStore = await client.CreateVectorStoreAsync(new VectorStoreCreationOptions()
var options = new VectorStoreCreationOptions()
{
FileIds = testFiles.Select(file => file.Id).ToList(),
ChunkingStrategy = chunkingStrategy,
});
};
foreach (var file in testFiles)
{
options.FileIds.Add(file.Id);
}
VectorStore vectorStore = client.CreateVectorStore(options);

Validate(vectorStore);
Assert.That(vectorStore.FileCounts.Total, Is.EqualTo(5));

Expand Down