Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Khoroshev committed Nov 16, 2023
1 parent ce45755 commit abf854c
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 86 deletions.
2 changes: 1 addition & 1 deletion OpenAI-DotNet-Tests/OpenAI-DotNet-Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
<SignAssembly>false</SignAssembly>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet-Tests/TestFixture_11_Assistants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Test_01_CreateAssistant()
},
Tools = new List<AssistantTool>
{
new(AssistantToolType.Retrieval)
AssistantTool.Retrieval
},
FileIds = new List<string> { assistantFileId }
};
Expand Down
11 changes: 6 additions & 5 deletions OpenAI-DotNet-Tests/TestFixture_14_ThreadMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using OpenAI.Chat;
using OpenAI.Files;
Expand Down Expand Up @@ -44,20 +45,20 @@ public async Task Test_01_CreateThreadMessage()

Assert.IsNotNull(created);
Assert.AreEqual("thread.message", created.Object);
Assert.AreEqual(ThreadRole.User, created.Role);
Assert.AreEqual(Role.User, created.Role);
Assert.AreEqual(thread.Id, created.ThreadId);

Assert.IsNotNull(created.Content);
Assert.AreEqual(1, created.Content.Length);
Assert.AreEqual(1, created.Content.Count);
Assert.AreEqual(ContentType.Text, created.Content[0].Type);
Assert.AreEqual("Test content", created.Content[0].Text.Value);

Assert.IsNotEmpty(created.FileIds);
Assert.AreEqual(1, created.FileIds.Length);
Assert.AreEqual(1, created.FileIds.Count);
Assert.AreEqual(file.Id, created.FileIds[0]);

Assert.IsNotNull(created.Metadata);
Assert.Contains("test", created.Metadata.Keys);
Assert.Contains("test", created.Metadata.Keys.ToList());
Assert.AreEqual("value", created.Metadata["test"]);
}

Expand Down Expand Up @@ -103,7 +104,7 @@ public async Task Test_03_ModifyThreadMessage()

Assert.IsNotNull(modified);
Assert.IsNotNull(modified.Metadata);
Assert.Contains("test", modified.Metadata.Keys);
Assert.Contains("test", modified.Metadata.Keys.ToList());
Assert.AreEqual("value", modified.Metadata["test"]);
}

Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet-Tests/TestFixture_15_TheadRuns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public async Task Test_06_SubmitToolOutput()
["required"] = new JsonArray { "location", "unit" }
});

var functionTool = new AssistantTool(function);
var functionTool = AssistantTool.ForFunction(function);
var request = new CreateThreadRunRequest(assistant.Id)
{
Tools = new [] { functionTool }
Expand Down
14 changes: 5 additions & 9 deletions OpenAI-DotNet/Assistants/AssistantTool.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
using System.Text.Json.Serialization;
using OpenAI.Chat;
using OpenAI.Extensions;

namespace OpenAI.Assistants
{
public sealed class AssistantTool
{
public AssistantTool() { }

public AssistantTool(AssistantToolType type)
public AssistantTool(string type)
{
Type = type;
}

public AssistantTool(Function function)
{
Type = AssistantToolType.Function;
Function = function;
}
public static AssistantTool CodeInterpreter => new ("code_interpreter");
public static AssistantTool Retrieval => new ("retrieval");
public static AssistantTool ForFunction(Function function) => new("function") { Function = function };

[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter<AssistantToolType>))]
public AssistantToolType Type { get; set; }
public string Type { get; set; }

[JsonPropertyName("function")]
public Function Function { get; set; }
Expand Down
14 changes: 0 additions & 14 deletions OpenAI-DotNet/Assistants/AssistantToolType.cs

This file was deleted.

9 changes: 5 additions & 4 deletions OpenAI-DotNet/Threads/ThreadMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using OpenAI.Chat;

namespace OpenAI.Threads
{
Expand Down Expand Up @@ -46,14 +47,14 @@ public sealed class ThreadMessage
/// <returns></returns>
[JsonInclude]
[JsonPropertyName("role")]
public ThreadRole Role { get; private set; }
public Role Role { get; private set; }

/// <summary>
/// The content of the message in array of text and/or images.
/// </summary>
[JsonInclude]
[JsonPropertyName("content")]
public ThreadMessageContent[] Content { get; private set; }
public IReadOnlyList<ThreadMessageContent> Content { get; private set; }

/// <summary>
/// If applicable, the ID of the assistant that authored this message.
Expand All @@ -76,7 +77,7 @@ public sealed class ThreadMessage
/// </summary>
[JsonInclude]
[JsonPropertyName("file_ids")]
public string[] FileIds { get; private set; }
public IReadOnlyList<string> FileIds { get; private set; }

/// <summary>
/// Set of 16 key-value pairs that can be attached to an object.
Expand All @@ -85,6 +86,6 @@ public sealed class ThreadMessage
/// </summary>
[JsonInclude]
[JsonPropertyName("metadata")]
public Dictionary<string, string> Metadata { get; private set; }
public IReadOnlyDictionary<string, string> Metadata { get; private set; }
}
}
38 changes: 0 additions & 38 deletions OpenAI-DotNet/Threads/ThreadMessageContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ namespace OpenAI.Threads
{
public sealed class ThreadMessageContent
{
public ThreadMessageContent() { }

public ThreadMessageContent(ContentType type, string input)
{
Type = type;

switch (Type)
{
case ContentType.Text:
Text = new ThreadMessageContentText
{
Value = input
};
break;

case ContentType.ImageUrl:
ImageUrl = new ImageUrl(input);
break;
}
}

[JsonInclude]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter<ContentType>))]
Expand All @@ -42,21 +21,4 @@ public ThreadMessageContent(ContentType type, string input)
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public ImageUrl ImageUrl { get; private set; }
}

public sealed class ThreadMessageContentText
{
/// <summary>
/// The data that makes up the text.
/// </summary>
/// <returns></returns>
[JsonPropertyName("value")]
public string Value { get; set; }

/// <summary>
/// Annotations
/// </summary>
[JsonPropertyName("annotations")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Annotation[] Annotations { get; set; }
}
}
24 changes: 24 additions & 0 deletions OpenAI-DotNet/Threads/ThreadMessageContentText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OpenAI.Threads
{
public sealed class ThreadMessageContentText
{
/// <summary>
/// The data that makes up the text.
/// </summary>
/// <returns></returns>
[JsonInclude]
[JsonPropertyName("value")]
public string Value { get; private set; }

/// <summary>
/// Annotations
/// </summary>
[JsonInclude]
[JsonPropertyName("annotations")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IReadOnlyList<Annotation> Annotations { get; private set; }
}
}
13 changes: 0 additions & 13 deletions OpenAI-DotNet/Threads/ThreadRole.cs

This file was deleted.

0 comments on commit abf854c

Please sign in to comment.