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
2 changes: 1 addition & 1 deletion .github/workflows/live-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run live tests
run: dotnet test ./tests/OpenAI.Tests.csproj
--configuration Release
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Conversation&TestCategory!=MCP&TestCategory!=Manual"
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Containers&TestCategory!=Conversation&TestCategory!=MCP&TestCategory!=Manual"
--logger "trx;LogFilePrefix=live"
--results-directory ${{github.workspace}}/artifacts/test-results
${{ env.version_suffix_args}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Run Live Tests
run: dotnet test ./tests/OpenAI.Tests.csproj
--configuration Release
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Conversation&TestCategory!=MCP&TestCategory!=Manual"
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Containers&TestCategory!=Conversation&TestCategory!=MCP&TestCategory!=Manual"
--logger "trx;LogFilePrefix=live"
--results-directory ${{ github.workspace }}/artifacts/test-results
${{ env.version_suffix_args }}
Expand Down
52 changes: 0 additions & 52 deletions tests/Responses/ResponsesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,6 @@ private void Validate<T>(T input) where T : class
}
}

[Test]
public async Task FileSearch()
{
OpenAIFileClient fileClient = GetTestClient<OpenAIFileClient>(TestScenario.Files);
OpenAIFile testFile = await fileClient.UploadFileAsync(
BinaryData.FromString("""
Travis's favorite food is pizza.
"""),
"test_favorite_foods.txt",
FileUploadPurpose.UserData);
Validate(testFile);

VectorStoreClient vscClient = GetTestClient<VectorStoreClient>(TestScenario.VectorStores);
VectorStore vectorStore = await vscClient.CreateVectorStoreAsync(
new VectorStoreCreationOptions()
{
FileIds = { testFile.Id },
});
Validate(vectorStore);

OpenAIResponseClient client = GetTestClient();

OpenAIResponse response = await client.CreateResponseAsync(
"Using the file search tool, what's Travis's favorite food?",
new ResponseCreationOptions()
{
Tools =
{
ResponseTool.CreateFileSearchTool(vectorStoreIds: [vectorStore.Id]),
}
});
Assert.That(response.OutputItems?.Count, Is.EqualTo(2));
FileSearchCallResponseItem fileSearchCall = response.OutputItems[0] as FileSearchCallResponseItem;
Assert.That(fileSearchCall, Is.Not.Null);
Assert.That(fileSearchCall?.Status, Is.EqualTo(FileSearchCallStatus.Completed));
Assert.That(fileSearchCall?.Queries, Has.Count.GreaterThan(0));
MessageResponseItem message = response.OutputItems[1] as MessageResponseItem;
Assert.That(message, Is.Not.Null);
ResponseContentPart messageContentPart = message.Content?.FirstOrDefault();
Assert.That(messageContentPart, Is.Not.Null);
Assert.That(messageContentPart.Text, Does.Contain("pizza"));
Assert.That(messageContentPart.OutputTextAnnotations, Is.Not.Null.And.Not.Empty);
FileCitationMessageAnnotation annotation = messageContentPart.OutputTextAnnotations[0] as FileCitationMessageAnnotation;
Assert.That(annotation.FileId, Is.EqualTo(testFile.Id));
Assert.That(annotation.Index, Is.GreaterThan(0));

await foreach (ResponseItem inputItem in client.GetResponseInputItemsAsync(response.Id))
{
Console.WriteLine(ModelReaderWriter.Write(inputItem).ToString());
}
}

[Test]
public async Task ComputerToolWithScreenshotRoundTrip()
{
Expand Down
70 changes: 70 additions & 0 deletions tests/Responses/ResponsesToolTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using NUnit.Framework;
using OpenAI.Files;
using OpenAI.Responses;
using OpenAI.Tests.Utility;
using OpenAI.VectorStores;
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -335,5 +338,72 @@ public async Task MCPToolWithDisallowedTools()
Assert.That(response.OutputItems.OfType<McpToolCallItem>().ToList(), Has.Count.EqualTo(0));
}

[Test]
public async Task FileSearch()
{
OpenAIFileClient fileClient = GetTestClient<OpenAIFileClient>(TestScenario.Files);
OpenAIFile testFile = await fileClient.UploadFileAsync(
BinaryData.FromString("""
Travis's favorite food is pizza.
"""),
"test_favorite_foods.txt",
FileUploadPurpose.UserData);
Validate(testFile);

VectorStoreClient vscClient = GetTestClient<VectorStoreClient>(TestScenario.VectorStores);
VectorStore vectorStore = await vscClient.CreateVectorStoreAsync(
new VectorStoreCreationOptions()
{
FileIds = { testFile.Id },
});
Validate(vectorStore);

OpenAIResponseClient client = GetTestClient();

OpenAIResponse response = await client.CreateResponseAsync(
"Using the file search tool, what's Travis's favorite food?",
new ResponseCreationOptions()
{
Tools =
{
ResponseTool.CreateFileSearchTool(vectorStoreIds: [vectorStore.Id]),
}
});
Assert.That(response.OutputItems?.Count, Is.EqualTo(2));
FileSearchCallResponseItem fileSearchCall = response.OutputItems[0] as FileSearchCallResponseItem;
Assert.That(fileSearchCall, Is.Not.Null);
Assert.That(fileSearchCall?.Status, Is.EqualTo(FileSearchCallStatus.Completed));
Assert.That(fileSearchCall?.Queries, Has.Count.GreaterThan(0));
MessageResponseItem message = response.OutputItems[1] as MessageResponseItem;
Assert.That(message, Is.Not.Null);
ResponseContentPart messageContentPart = message.Content?.FirstOrDefault();
Assert.That(messageContentPart, Is.Not.Null);
Assert.That(messageContentPart.Text, Does.Contain("pizza"));
Assert.That(messageContentPart.OutputTextAnnotations, Is.Not.Null.And.Not.Empty);
FileCitationMessageAnnotation annotation = messageContentPart.OutputTextAnnotations[0] as FileCitationMessageAnnotation;
Assert.That(annotation.FileId, Is.EqualTo(testFile.Id));
Assert.That(annotation.Index, Is.GreaterThan(0));

await foreach (ResponseItem inputItem in client.GetResponseInputItemsAsync(response.Id))
{
Console.WriteLine(ModelReaderWriter.Write(inputItem).ToString());
}
}

private List<string> FileIdsToDelete = [];
private List<string> VectorStoreIdsToDelete = [];

private void Validate<T>(T input) where T : class
{
if (input is OpenAIFile file)
{
FileIdsToDelete.Add(file.Id);
}
if (input is VectorStore vectorStore)
{
VectorStoreIdsToDelete.Add(vectorStore.Id);
}
}

private static OpenAIResponseClient GetTestClient(string overrideModel = null) => GetTestClient<OpenAIResponseClient>(TestScenario.Responses, overrideModel);
}