Skip to content

Commit

Permalink
OpenAI-DotNet 8.0.2 (#329)
Browse files Browse the repository at this point in the history
- Fixed Thread.Message.Attachement serialization
- Fixed CreateAssistantRequest to properly copy all override assistant properties
- Fixed some objects that are chunked, were not properly being appended to the final object
- Added FileSearchOptions to Tool.FileSearch
- Added some additional constructor overloads for CodeInterpreterResources
- Added some additional constructor overloads for VectorStoreRequest
- Thread.DeleteAsync and Assistant.DeleteAsync now fetch the latest before deleting when deleteToolResources is also requested
- Refactored the way Function handles reflected invocations for both synchronous and asynchronous calls
  - Function.InvokeAsync will now properly also call synchronous invocations in the tool call collection
- Refactored Threads/Assistant Unit Tests
  • Loading branch information
StephenHodgson authored Jun 15, 2024
1 parent 41eac5c commit 8294a63
Show file tree
Hide file tree
Showing 26 changed files with 716 additions and 460 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/Publish-Nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ concurrency:

env:
DOTNET_VERSION: ${{ github.event.inputs.dotnet-version || '6.0.x' }}
PACKAGE_VERSION: ''

jobs:
build:
if: ${{ !github.event_name == 'pull_request' || !github.event.pull_request.draft }}
env:
PACKAGE_VERSION: ''
COVERAGE_FILE_PATH: ''
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -73,11 +75,18 @@ jobs:
report_individual_runs: true
compare_to_earlier_commit: false

- name: Determine Coverage File Path
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
shell: bash
run: |
COVERAGE_FILE_PATH=$(find ./test-results -name 'coverage.cobertura.xml' | head -n 1)
echo "COVERAGE_FILE_PATH=$COVERAGE_FILE_PATH" >> $GITHUB_ENV
- name: Code Coverage Summary Report
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: test-results/**/coverage.cobertura.xml
filename: ${{ env.COVERAGE_FILE_PATH }}
badge: true
format: 'markdown'
output: 'both'
Expand Down Expand Up @@ -131,6 +140,7 @@ jobs:
with:
name: OpenAI-DotNet.${{ env.PACKAGE_VERSION }}
path: |
${{ github.workspace }}/test-results
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.symbols.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.nupkg
Expand Down
24 changes: 23 additions & 1 deletion OpenAI-DotNet-Tests/TestFixture_00_02_Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public async Task Test_02_Tool_Funcs()
Tool.FromFunc("test_func", Function),
Tool.FromFunc<string, string, string>("test_func_with_args", FunctionWithArgs),
Tool.FromFunc("test_func_weather", () => WeatherService.GetCurrentWeatherAsync("my location", WeatherService.WeatherUnit.Celsius)),
Tool.FromFunc<List<int>, string>("test_func_with_array_args", FunctionWithArrayArgs)
Tool.FromFunc<List<int>, string>("test_func_with_array_args", FunctionWithArrayArgs),
Tool.FromFunc<string, string>("test_single_return_arg", arg1 => arg1),
Tool.FromFunc("test_no_specifiers", (string arg1) => arg1)
};

var json = JsonSerializer.Serialize(tools, new JsonSerializerOptions(OpenAIClient.JsonSerializationOptions)
Expand Down Expand Up @@ -75,6 +77,26 @@ public async Task Test_02_Tool_Funcs()
var resultWithArrayArgs = toolWithArrayArgs.InvokeFunction<string>();
Assert.AreEqual("1, 2, 3, 4, 5", resultWithArrayArgs);
Console.WriteLine(resultWithArrayArgs);

var singleReturnArg = tools[4];
Assert.IsNotNull(singleReturnArg);
singleReturnArg.Function.Arguments = new JsonObject
{
["arg1"] = "arg1"
};
var resultSingleReturnArg = singleReturnArg.InvokeFunction<string>();
Assert.AreEqual("arg1", resultSingleReturnArg);
Console.WriteLine(resultSingleReturnArg);

var toolNoSpecifiers = tools[5];
Assert.IsNotNull(toolNoSpecifiers);
toolNoSpecifiers.Function.Arguments = new JsonObject
{
["arg1"] = "arg1"
};
var resultNoSpecifiers = toolNoSpecifiers.InvokeFunction<string>();
Assert.AreEqual("arg1", resultNoSpecifiers);
Console.WriteLine(resultNoSpecifiers);
}

private string Function()
Expand Down
104 changes: 49 additions & 55 deletions OpenAI-DotNet-Tests/TestFixture_02_Assistants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace OpenAI.Tests
{
internal class TestFixture_02_Assistants : AbstractTestFixture
{
private AssistantResponse testAssistant;

[Test]
public async Task Test_01_CreateAssistant()
public async Task Test_01_Assistants()
{
Assert.IsNotNull(OpenAIClient.AssistantsEndpoint);
const string testFilePath = "assistant_test_1.txt";
Expand Down Expand Up @@ -53,13 +51,54 @@ public async Task Test_01_CreateAssistant()
tools: new[] { Tool.FileSearch });
var assistant = await OpenAIClient.AssistantsEndpoint.CreateAssistantAsync(request);
Assert.IsNotNull(assistant);
Assert.AreEqual("test-assistant", assistant.Name);
Assert.AreEqual("Used for unit testing.", assistant.Description);
Assert.AreEqual("You are test assistant", assistant.Instructions);
Assert.AreEqual(Model.GPT4_Turbo.ToString(), assistant.Model);
Assert.IsNotEmpty(assistant.Metadata);
testAssistant = assistant;
Console.WriteLine($"{assistant} -> {assistant.Metadata["test"]}");

try
{
Assert.AreEqual("test-assistant", assistant.Name);
Assert.AreEqual("Used for unit testing.", assistant.Description);
Assert.AreEqual("You are test assistant", assistant.Instructions);
Assert.AreEqual(Model.GPT4_Turbo.ToString(), assistant.Model);
Assert.IsNotEmpty(assistant.Metadata);
Console.WriteLine($"{assistant} -> {assistant.Metadata["test"]}");

var modifiedAssistant = await assistant.ModifyAsync(new(
model: Model.GPT4o,
name: "Test modified",
description: "Modified description",
instructions: "You are modified test assistant",
metadata: new Dictionary<string, string>
{
["int"] = "2",
["test"] = assistant.Metadata["test"]
}));
Assert.IsNotNull(modifiedAssistant);
Assert.AreEqual("Test modified", modifiedAssistant.Name);
Assert.AreEqual("Modified description", modifiedAssistant.Description);
Assert.AreEqual("You are modified test assistant", modifiedAssistant.Instructions);
Assert.AreEqual(Model.GPT4o.ToString(), modifiedAssistant.Model);
Assert.IsTrue(modifiedAssistant.Metadata.ContainsKey("test"));
Assert.AreEqual("2", modifiedAssistant.Metadata["int"]);
Assert.AreEqual(modifiedAssistant.Metadata["test"], assistant.Metadata["test"]);
Console.WriteLine($"modified assistant -> {modifiedAssistant.Id}");

var assistantsList = await OpenAIClient.AssistantsEndpoint.ListAssistantsAsync();
Assert.IsNotNull(assistantsList);
Assert.IsNotEmpty(assistantsList.Items);

foreach (var asst in assistantsList.Items)
{
var retrievedAsst = await OpenAIClient.AssistantsEndpoint.RetrieveAssistantAsync(asst);
Assert.IsNotNull(retrievedAsst);

var updatedAsst = await retrievedAsst.UpdateAsync();
Assert.IsNotNull(updatedAsst);
}
}
finally
{
var isDeleted = await assistant.DeleteAsync(deleteToolResources: true);
Assert.IsTrue(isDeleted);
}
}
finally
{
Expand All @@ -70,50 +109,5 @@ public async Task Test_01_CreateAssistant()
}
}
}

[Test]
public async Task Test_02_ListAssistants()
{
Assert.IsNotNull(OpenAIClient.AssistantsEndpoint);
var assistantsList = await OpenAIClient.AssistantsEndpoint.ListAssistantsAsync();
Assert.IsNotNull(assistantsList);
Assert.IsNotEmpty(assistantsList.Items);

foreach (var assistant in assistantsList.Items)
{
var retrieved = await OpenAIClient.AssistantsEndpoint.RetrieveAssistantAsync(assistant);
Assert.IsNotNull(retrieved);
Console.WriteLine($"{retrieved} -> {retrieved.CreatedAt}");
}
}

[Test]
public async Task Test_03_ModifyAssistants()
{
Assert.IsNotNull(testAssistant);
Assert.IsNotNull(OpenAIClient.AssistantsEndpoint);
var assistant = await testAssistant.ModifyAsync(new(
model: Model.GPT4o,
name: "Test modified",
description: "Modified description",
instructions: "You are modified test assistant"));
Assert.IsNotNull(assistant);
Assert.AreEqual("Test modified", assistant.Name);
Assert.AreEqual("Modified description", assistant.Description);
Assert.AreEqual("You are modified test assistant", assistant.Instructions);
Assert.AreEqual(Model.GPT4o.ToString(), assistant.Model);
Assert.IsTrue(assistant.Metadata.ContainsKey("test"));
Console.WriteLine($"modified assistant -> {assistant.Id}");
}

[Test]
public async Task Test_05_DeleteAssistant()
{
Assert.IsNotNull(testAssistant);
Assert.IsNotNull(OpenAIClient.AssistantsEndpoint);
var result = await testAssistant.DeleteAsync(deleteToolResources: true);
Assert.IsTrue(result);
Console.WriteLine($"deleted assistant -> {testAssistant.Id}");
}
}
}
Loading

0 comments on commit 8294a63

Please sign in to comment.