Skip to content

Commit

Permalink
a few more test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
trrwilson committed Nov 16, 2024
1 parent 1ed4eed commit 8657442
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .dotnet.azure/sdk/openai/Azure.AI.OpenAI/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "dotnet.azure/openai/Azure.AI.OpenAI",
"Tag": "dotnet.azure/openai/Azure.AI.OpenAI_1ee73d3b71"
"Tag": "dotnet.azure/openai/Azure.AI.OpenAI_9c6496e308"
}
18 changes: 2 additions & 16 deletions .dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/AssistantTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,12 @@ public async Task StreamingToolCall()
});
Validate(assistant);

Stopwatch stopwatch = Stopwatch.StartNew();
void Print(string message) => Console.WriteLine($"[{stopwatch.ElapsedMilliseconds,6}] {message}");

Print(" >>> Beginning call ... ");

ThreadCreationOptions thirdOpt = new()
{
InitialMessages = { new(MessageRole.User, ["What should I wear outside right now?"]), },
};
AsyncCollectionResult<StreamingUpdate> asyncResults = client.CreateThreadAndRunStreamingAsync(assistant.Id, thirdOpt);

Print(" >>> Starting enumeration ...");

ThreadRun run = null;

do
Expand All @@ -205,25 +198,19 @@ public async Task StreamingToolCall()
List<ToolOutput> toolOutputs = new();
await foreach (StreamingUpdate update in asyncResults)
{
string message = update.UpdateKind.ToString();

if (update is RunUpdate runUpdate)
{
message += $" run_id:{runUpdate.Value.Id}";
run = runUpdate.Value;
}
if (update is RequiredActionUpdate requiredActionUpdate)
{
Assert.That(requiredActionUpdate.FunctionName, Is.EqualTo(getWeatherTool.FunctionName));
Assert.That(requiredActionUpdate.GetThreadRun().Status, Is.EqualTo(RunStatus.RequiresAction));
message += $" {requiredActionUpdate.FunctionName}";
toolOutputs.Add(new(requiredActionUpdate.ToolCallId, "warm and sunny"));
}
if (update is MessageContentUpdate contentUpdate)
{
message += $" {contentUpdate.Text}";
}
Print(message);
}
if (toolOutputs.Count > 0)
{
Expand Down Expand Up @@ -471,7 +458,6 @@ public async Task FunctionToolsWork(TestStrictSchemaMode schemaMode)
AdditionalInstructions = "Call provided tools when appropriate.",
});
Validate(run);
Console.WriteLine($" Run status right after creation: {run.Status}");

// TODO FIXME: The underlying OpenAI code doesn't consider the "requires_action" status to be terminal even though it is.
// Work around this here
Expand Down Expand Up @@ -607,11 +593,11 @@ This file describes the favorite foods of several people.
numThreads++;
foreach (MessageContent content in message.Content)
{
Console.WriteLine(content.Text);
hasCake |= content.Text?.ToLowerInvariant().Contains("cake") == true;
foreach (TextAnnotation annotation in content.TextAnnotations)
{
Console.WriteLine($" --> From file: {annotation.InputFileId}, replacement: {annotation.TextToReplace}");
Assert.That(annotation.InputFileId, Is.Not.Null.And.Not.Empty);
Assert.That(annotation.TextToReplace, Is.Not.Null.And.Not.Empty);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,18 @@ protected void Cleanup()
});
RequestOptions requestOptions = new() { ErrorOptions = ClientErrorBehaviors.NoThrow, };

void WriteIfNotSuppressed(string message)
{
if (Environment.GetEnvironmentVariable("AOAI_SUPPRESS_TRAFFIC_DUMP") != "true")
{
Console.WriteLine(message);
}
}

OpenAIFileClient fileClient = topLevelCleanupClient.GetOpenAIFileClient();
foreach (string fileId in _fileIdsToDelete)
{
Console.WriteLine($"Cleanup: {fileId} -> {fileClient.DeleteFile(fileId, requestOptions)?.GetRawResponse().Status}");
WriteIfNotSuppressed($"Cleanup: {fileId} -> {fileClient.DeleteFile(fileId, requestOptions)?.GetRawResponse().Status}");
}
_fileIdsToDelete.Clear();

Expand All @@ -659,23 +667,23 @@ protected void Cleanup()
VectorStoreClient vectorStoreClient = topLevelCleanupClient.GetVectorStoreClient();
foreach ((string threadId, string messageId) in _threadIdsWithMessageIdsToDelete)
{
Console.WriteLine($"Cleanup: {messageId} -> {client.DeleteMessage(threadId, messageId, requestOptions)?.GetRawResponse().Status}");
WriteIfNotSuppressed($"Cleanup: {messageId} -> {client.DeleteMessage(threadId, messageId, requestOptions)?.GetRawResponse().Status}");
}
foreach (string assistantId in _assistantIdsToDelete)
{
Console.WriteLine($"Cleanup: {assistantId} -> {client.DeleteAssistant(assistantId, requestOptions)?.GetRawResponse().Status}");
WriteIfNotSuppressed($"Cleanup: {assistantId} -> {client.DeleteAssistant(assistantId, requestOptions)?.GetRawResponse().Status}");
}
foreach (string threadId in _threadIdsToDelete)
{
Console.WriteLine($"Cleanup: {threadId} -> {client.DeleteThread(threadId, requestOptions)?.GetRawResponse().Status}");
WriteIfNotSuppressed($"Cleanup: {threadId} -> {client.DeleteThread(threadId, requestOptions)?.GetRawResponse().Status}");
}
foreach ((string vectorStoreId, string fileId) in _vectorStoreFileAssociationsToRemove)
{
Console.WriteLine($"Cleanup: {vectorStoreId}<->{fileId} => {vectorStoreClient.RemoveFileFromStore(vectorStoreId, fileId, requestOptions)?.GetRawResponse().Status}");
WriteIfNotSuppressed($"Cleanup: {vectorStoreId}<->{fileId} => {vectorStoreClient.RemoveFileFromStore(vectorStoreId, fileId, requestOptions)?.GetRawResponse().Status}");
}
foreach (string vectorStoreId in _vectorStoreIdsToDelete)
{
Console.WriteLine($"Cleanup: {vectorStoreId} => {vectorStoreClient.DeleteVectorStore(vectorStoreId, requestOptions)?.GetRawResponse().Status}");
WriteIfNotSuppressed($"Cleanup: {vectorStoreId} => {vectorStoreClient.DeleteVectorStore(vectorStoreId, requestOptions)?.GetRawResponse().Status}");
}
_threadIdsWithMessageIdsToDelete.Clear();
_assistantIdsToDelete.Clear();
Expand Down

0 comments on commit 8657442

Please sign in to comment.