Hello @Saket Arora
Thanks for reaching out to us, I think you are looking for this document - https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.openai.assistants-readme?view=azure-dotnet-preview
You can follow above document to implement your code but please be aware that this is only the beta version.
A quick sample for your is here, please adjust it according to your need -
using Azure;
using Azure.AI.OpenAI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
var client = new OpenAIClient(new OpenAIClientOptions
{
ApiKey = new AzureKeyCredential(apiKey),
Endpoint = endpoint
});
// Create a vector store
string vectorStoreName = "Financial Statements";
VectorStore vectorStore = await client.VectorStores.CreateAsync(vectorStoreName);
Console.WriteLine($"Created vector store with ID: {vectorStore.Id}");
// Prepare files for upload
string[] filePaths = new string[] { "mydirectory/myfile1.pdf", "mydirectory/myfile2.txt" };
List<Stream> fileStreams = new List<Stream>();
foreach (var filePath in filePaths)
{
FileStream fileStream = new FileStream(filePath, FileMode.Open);
fileStreams.Add(fileStream);
}
// Upload files and poll for completion
FileBatch fileBatch = await client.VectorStores.UploadAndPollFileBatchAsync(
vectorStoreId: vectorStore.Id,
files: fileStreams);
// Output status and file counts
Console.WriteLine($"File batch status: {fileBatch.Status}");
Console.WriteLine($"File counts: {fileBatch.FileCounts}");
// Dispose file streams
foreach (var fileStream in fileStreams)
{
fileStream.Dispose();
}
}
}
More samples from official doc for your reference - https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.openai.assistants-readme?view=azure-dotnet-preview#usage
I hope this helps!
Regards,
Yutong
-Please kindly accept the answer if you feel helpful to support the community, thanks a lot.