-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evgenii Khoroshev
committed
Nov 15, 2023
1 parent
216012d
commit c93dd92
Showing
7 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Text.Json.Serialization; | ||
using OpenAI.Extensions; | ||
|
||
namespace OpenAI.Chat; | ||
|
||
public class Annotation | ||
{ | ||
[JsonPropertyName("type")] | ||
[JsonConverter(typeof(JsonStringEnumConverter<AnnotationType>))] | ||
public AnnotationType Type { get; set; } | ||
|
||
/// <summary> | ||
/// The text in the message content that needs to be replaced. | ||
/// </summary> | ||
[JsonPropertyName("text")] | ||
public string Text { get; set; } | ||
|
||
/// <summary> | ||
/// A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. | ||
/// Generated when the assistant uses the "retrieval" tool to search files. | ||
/// </summary> | ||
[JsonPropertyName("file_citation")] | ||
public FileCitation FileCitation { get; set; } | ||
|
||
/// <summary> | ||
/// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. | ||
/// </summary> | ||
[JsonPropertyName("file_path")] | ||
public FilePath FilePath { get; set; } | ||
|
||
[JsonPropertyName("start_index")] | ||
public int StartIndex { get; set; } | ||
|
||
[JsonPropertyName("end_index")] | ||
public int EndIndex { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace OpenAI.Chat; | ||
|
||
public enum AnnotationType | ||
{ | ||
[EnumMember(Value = "file_citation")] | ||
FileCitation, | ||
[EnumMember(Value = "file_path")] | ||
FilePath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenAI.Chat; | ||
|
||
public class FileCitation | ||
{ | ||
/// <summary> | ||
/// The ID of the specific File the citation is from. | ||
/// </summary> | ||
[JsonPropertyName("file_id")] | ||
public string FileId { get; set; } | ||
|
||
/// <summary> | ||
/// The specific quote in the file. | ||
/// </summary> | ||
[JsonPropertyName("file_id")] | ||
public string Quote { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenAI.Chat; | ||
|
||
public class FilePath | ||
{ | ||
/// <summary> | ||
/// The ID of the file that was generated. | ||
/// </summary> | ||
[JsonPropertyName("file_id")] | ||
public string FileId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using OpenAI.Chat; | ||
|
||
namespace OpenAI.ThreadMessages; | ||
|
||
public class ThreadMessage | ||
{ | ||
/// <summary> | ||
/// The identifier, which can be referenced in API endpoints. | ||
/// </summary> | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// The object type, which is always thread. | ||
/// </summary> | ||
[JsonPropertyName("object")] | ||
public string Object { get; set; } = "thread.message"; | ||
|
||
/// <summary> | ||
/// The Unix timestamp (in seconds) for when the thread was created. | ||
/// </summary> | ||
/// <returns></returns> | ||
[JsonPropertyName("created_at")] | ||
public int CreatedAt { get; set; } | ||
|
||
/// <summary> | ||
/// The thread ID that this message belongs to. | ||
/// </summary> | ||
[JsonPropertyName("thread_id")] | ||
public string ThreadId { get; set; } | ||
|
||
/// <summary> | ||
/// The entity that produced the message. One of user or assistant. | ||
/// </summary> | ||
/// <returns></returns> | ||
[JsonPropertyName("role")] | ||
public ThreadRole Role { get; set; } | ||
|
||
/// <summary> | ||
/// The content of the message in array of text and/or images. | ||
/// </summary> | ||
[JsonPropertyName("content")] | ||
public ThreadMessageContent[] Content { get; set; } | ||
|
||
/// <summary> | ||
/// If applicable, the ID of the assistant that authored this message. | ||
/// </summary> | ||
/// <returns></returns> | ||
[JsonPropertyName("assistant_id")] | ||
public string AssistantId { get; set; } | ||
|
||
/// <summary> | ||
/// If applicable, the ID of the run associated with the authoring of this message. | ||
/// </summary> | ||
/// <returns></returns> | ||
[JsonPropertyName("run_id")] | ||
public string RunId { get; set; } | ||
|
||
/// <summary> | ||
/// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can access files. A maximum of 10 files can be attached to a message. | ||
/// </summary> | ||
[JsonPropertyName("file_ids")] | ||
public string[] FileIds { get; set; } | ||
|
||
/// <summary> | ||
/// Set of 16 key-value pairs that can be attached to an object. | ||
/// This can be useful for storing additional information about the object in a structured format. | ||
/// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. | ||
/// </summary> | ||
[JsonPropertyName("metadata")] | ||
public Dictionary<string, object> Metadata { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Text.Json.Serialization; | ||
using OpenAI.Extensions; | ||
|
||
namespace OpenAI.Chat; | ||
|
||
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>))] | ||
public ContentType Type { get; private set; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("text")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
public ThreadMessageContentText Text { get; private set; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("image_url")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
public ImageUrl ImageUrl { get; private set; } | ||
} | ||
|
||
public class ThreadMessageContentText | ||
{ | ||
/// <summary> | ||
/// The data that makes up the text. | ||
/// </summary> | ||
/// <returns></returns> | ||
[JsonPropertyName("value")] | ||
public string Value { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
[JsonPropertyName("annotations")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
public object[] Annotations { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace OpenAI.ThreadMessages; | ||
|
||
public enum ThreadRole | ||
{ | ||
User, | ||
Assistant | ||
} |