Skip to content

Commit bf3f0ed

Browse files
authored
Add support for retrieving File Search result content in Run Steps and other fixes (#294)
### Features added - OpenAI.Assistants: - Added a `Content` property to `RunStepFileSearchResult` ([`step_details.tool_calls.file_search.results.content` in the REST API](https://platform.openai.com/docs/api-reference/run-steps/step-object)). - When using an Assistant with the File Search tool, you can use this property to retrieve the contents of the File Search results that were used by the model. - Added `FileSearchRankingOptions` and `FileSearchResults` properties to `RunStepDetailsUpdate`. ### Breaking Changes in Preview APIs - OpenAI.RealtimeConversation: - Renamed the `From*()` factory methods on `ConversationContentPart` to `Create*Part()` for consistency. - Removed an extraneous `toolCallId` parameter from `ConversationItem.CreateSystemMessage()`. - OpenAI.Assistants: - Renamed `RunStepType` to `RunStepKind`. - Changed `RunStepKind` from an "extensible enum" to a regular enum. - Renamed the `ToolCallId` property of `RunStepToolCall` to `Id`. - Renamed the `ToolKind` property of `RunStepToolCall` to `Kind`. - Replaced the `FileSearchRanker` and `FileSearchScoreThreshold` properties of `RunStepToolCall` with a new `FileSearchRankingOptions` property that contains both values to make it clearer how they are related. ### Bugs fixed - OpenAI.RealtimeConversation: - Fixed serialization issues with `ConversationItem` creation of system and assistant messages.
1 parent 448181b commit bf3f0ed

File tree

88 files changed

+1318
-796
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1318
-796
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Release History
22

3+
## 2.1.0-beta.3 (Unreleased)
4+
5+
### Features added
6+
7+
- OpenAI.Assistants:
8+
- Added a `Content` property to `RunStepFileSearchResult` ([`step_details.tool_calls.file_search.results.content` in the REST API](https://platform.openai.com/docs/api-reference/run-steps/step-object)). (commit_hash)
9+
- When using an Assistant with the File Search tool, you can use this property to retrieve the contents of the File Search results that were used by the model.
10+
- Added `FileSearchRankingOptions` and `FileSearchResults` properties to `RunStepDetailsUpdate`. (commit_hash)
11+
12+
### Breaking Changes in Preview APIs
13+
14+
- OpenAI.RealtimeConversation:
15+
- Renamed the `From*()` factory methods on `ConversationContentPart` to `Create*Part()` for consistency. (commit_hash)
16+
- Removed an extraneous `toolCallId` parameter from `ConversationItem.CreateSystemMessage()`. (commit_hash)
17+
- OpenAI.Assistants:
18+
- Renamed `RunStepType` to `RunStepKind`. (commit_hash)
19+
- Changed `RunStepKind` from an "extensible enum" to a regular enum. (commit_hash)
20+
- Renamed the `ToolCallId` property of `RunStepToolCall` to `Id`. (commit_hash)
21+
- Renamed the `ToolKind` property of `RunStepToolCall` to `Kind`. (commit_hash)
22+
- Replaced the `FileSearchRanker` and `FileSearchScoreThreshold` properties of `RunStepToolCall` with a new `FileSearchRankingOptions` property that contains both values to make it clearer how they are related. (commit_hash)
23+
24+
### Bugs fixed
25+
26+
- OpenAI.RealtimeConversation:
27+
- Fixed serialization issues with `ConversationItem` creation of system and assistant messages. (commit_hash)
28+
329
## 2.1.0-beta.2 (2024-11-04)
430

531
### Features added

api/OpenAI.netstandard2.0.cs

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,12 @@ public class RunStep : IJsonModel<RunStep>, IPersistableModel<RunStep> {
666666
public DateTimeOffset? ExpiredAt { get; }
667667
public DateTimeOffset? FailedAt { get; }
668668
public string Id { get; }
669+
public RunStepKind Kind { get; }
669670
public RunStepError LastError { get; }
670671
public IReadOnlyDictionary<string, string> Metadata { get; }
671672
public string RunId { get; }
672673
public RunStepStatus Status { get; }
673674
public string ThreadId { get; }
674-
public RunStepType Type { get; }
675675
public RunStepTokenUsage Usage { get; }
676676
RunStep IJsonModel<RunStep>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
677677
void IJsonModel<RunStep>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
@@ -723,6 +723,8 @@ public class RunStepDetailsUpdate : StreamingUpdate {
723723
public string CodeInterpreterInput { get; }
724724
public IReadOnlyList<RunStepUpdateCodeInterpreterOutput> CodeInterpreterOutputs { get; }
725725
public string CreatedMessageId { get; }
726+
public FileSearchRankingOptions FileSearchRankingOptions { get; }
727+
public IReadOnlyList<RunStepFileSearchResult> FileSearchResults { get; }
726728
public string FunctionArguments { get; }
727729
public string FunctionName { get; }
728730
public string FunctionOutput { get; }
@@ -756,6 +758,7 @@ public class RunStepError : IJsonModel<RunStepError>, IPersistableModel<RunStepE
756758
public override readonly string ToString();
757759
}
758760
public class RunStepFileSearchResult : IJsonModel<RunStepFileSearchResult>, IPersistableModel<RunStepFileSearchResult> {
761+
public IReadOnlyList<RunStepFileSearchResultContent> Content { get; }
759762
public string FileId { get; }
760763
public string FileName { get; }
761764
public float Score { get; }
@@ -765,6 +768,22 @@ public class RunStepFileSearchResult : IJsonModel<RunStepFileSearchResult>, IPer
765768
string IPersistableModel<RunStepFileSearchResult>.GetFormatFromOptions(ModelReaderWriterOptions options);
766769
BinaryData IPersistableModel<RunStepFileSearchResult>.Write(ModelReaderWriterOptions options);
767770
}
771+
public class RunStepFileSearchResultContent : IJsonModel<RunStepFileSearchResultContent>, IPersistableModel<RunStepFileSearchResultContent> {
772+
public RunStepFileSearchResultContentKind Kind { get; }
773+
public string Text { get; }
774+
RunStepFileSearchResultContent IJsonModel<RunStepFileSearchResultContent>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
775+
void IJsonModel<RunStepFileSearchResultContent>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
776+
RunStepFileSearchResultContent IPersistableModel<RunStepFileSearchResultContent>.Create(BinaryData data, ModelReaderWriterOptions options);
777+
string IPersistableModel<RunStepFileSearchResultContent>.GetFormatFromOptions(ModelReaderWriterOptions options);
778+
BinaryData IPersistableModel<RunStepFileSearchResultContent>.Write(ModelReaderWriterOptions options);
779+
}
780+
public enum RunStepFileSearchResultContentKind {
781+
Text = 0
782+
}
783+
public enum RunStepKind {
784+
CreatedMessage = 0,
785+
ToolCall = 1
786+
}
768787
public readonly partial struct RunStepStatus : IEquatable<RunStepStatus> {
769788
private readonly object _dummy;
770789
private readonly int _dummyPrimitive;
@@ -797,41 +816,23 @@ public class RunStepTokenUsage : IJsonModel<RunStepTokenUsage>, IPersistableMode
797816
public abstract class RunStepToolCall : IJsonModel<RunStepToolCall>, IPersistableModel<RunStepToolCall> {
798817
public string CodeInterpreterInput { get; }
799818
public IReadOnlyList<RunStepCodeInterpreterOutput> CodeInterpreterOutputs { get; }
800-
public FileSearchRanker? FileSearchRanker { get; }
819+
public FileSearchRankingOptions FileSearchRankingOptions { get; }
801820
public IReadOnlyList<RunStepFileSearchResult> FileSearchResults { get; }
802-
public float? FileSearchScoreThreshold { get; }
803821
public string FunctionArguments { get; }
804822
public string FunctionName { get; }
805823
public string FunctionOutput { get; }
806-
public string ToolCallId { get; }
807-
public RunStepToolCallKind ToolKind { get; }
824+
public string Id { get; }
825+
public RunStepToolCallKind Kind { get; }
808826
RunStepToolCall IJsonModel<RunStepToolCall>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
809827
void IJsonModel<RunStepToolCall>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
810828
RunStepToolCall IPersistableModel<RunStepToolCall>.Create(BinaryData data, ModelReaderWriterOptions options);
811829
string IPersistableModel<RunStepToolCall>.GetFormatFromOptions(ModelReaderWriterOptions options);
812830
BinaryData IPersistableModel<RunStepToolCall>.Write(ModelReaderWriterOptions options);
813831
}
814832
public enum RunStepToolCallKind {
815-
Unknown = 0,
816-
CodeInterpreter = 1,
817-
FileSearch = 2,
818-
Function = 3
819-
}
820-
public readonly partial struct RunStepType : IEquatable<RunStepType> {
821-
private readonly object _dummy;
822-
private readonly int _dummyPrimitive;
823-
public RunStepType(string value);
824-
public static RunStepType MessageCreation { get; }
825-
public static RunStepType ToolCalls { get; }
826-
public readonly bool Equals(RunStepType other);
827-
[EditorBrowsable(EditorBrowsableState.Never)]
828-
public override readonly bool Equals(object obj);
829-
[EditorBrowsable(EditorBrowsableState.Never)]
830-
public override readonly int GetHashCode();
831-
public static bool operator ==(RunStepType left, RunStepType right);
832-
public static implicit operator RunStepType(string value);
833-
public static bool operator !=(RunStepType left, RunStepType right);
834-
public override readonly string ToString();
833+
CodeInterpreter = 0,
834+
FileSearch = 1,
835+
Function = 2
835836
}
836837
public class RunStepUpdate : StreamingUpdate<RunStep> {
837838
}
@@ -1456,8 +1457,8 @@ public class ChatFunctionChoice : IJsonModel<ChatFunctionChoice>, IPersistableMo
14561457
public override readonly string ToString();
14571458
}
14581459
public class ChatInputTokenUsageDetails : IJsonModel<ChatInputTokenUsageDetails>, IPersistableModel<ChatInputTokenUsageDetails> {
1459-
public int? AudioTokenCount { get; }
1460-
public int? CachedTokenCount { get; }
1460+
public int AudioTokenCount { get; }
1461+
public int CachedTokenCount { get; }
14611462
ChatInputTokenUsageDetails IJsonModel<ChatInputTokenUsageDetails>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
14621463
void IJsonModel<ChatInputTokenUsageDetails>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
14631464
ChatInputTokenUsageDetails IPersistableModel<ChatInputTokenUsageDetails>.Create(BinaryData data, ModelReaderWriterOptions options);
@@ -1528,7 +1529,7 @@ public enum ChatMessageRole {
15281529
Function = 4
15291530
}
15301531
public class ChatOutputTokenUsageDetails : IJsonModel<ChatOutputTokenUsageDetails>, IPersistableModel<ChatOutputTokenUsageDetails> {
1531-
public int? AudioTokenCount { get; }
1532+
public int AudioTokenCount { get; }
15321533
public int ReasoningTokenCount { get; }
15331534
ChatOutputTokenUsageDetails IJsonModel<ChatOutputTokenUsageDetails>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
15341535
void IJsonModel<ChatOutputTokenUsageDetails>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
@@ -1633,8 +1634,8 @@ public class FunctionChatMessage : ChatMessage, IJsonModel<FunctionChatMessage>,
16331634
}
16341635
public static class OpenAIChatModelFactory {
16351636
public static ChatCompletion ChatCompletion(string id = null, ChatFinishReason finishReason = ChatFinishReason.Stop, ChatMessageContent content = null, string refusal = null, IEnumerable<ChatToolCall> toolCalls = null, ChatMessageRole role = ChatMessageRole.System, ChatFunctionCall functionCall = null, IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = null, IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = null, DateTimeOffset createdAt = default, string model = null, string systemFingerprint = null, ChatTokenUsage usage = null);
1636-
public static ChatInputTokenUsageDetails ChatInputTokenUsageDetails(int? audioTokenCount = null, int? cachedTokenCount = null);
1637-
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = 0, int? audioTokenCount = null);
1637+
public static ChatInputTokenUsageDetails ChatInputTokenUsageDetails(int audioTokenCount = 0, int cachedTokenCount = 0);
1638+
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = 0, int audioTokenCount = 0);
16381639
public static ChatTokenLogProbabilityDetails ChatTokenLogProbabilityDetails(string token = null, float logProbability = 0, ReadOnlyMemory<byte>? utf8Bytes = null, IEnumerable<ChatTokenTopLogProbabilityDetails> topLogProbabilities = null);
16391640
public static ChatTokenTopLogProbabilityDetails ChatTokenTopLogProbabilityDetails(string token = null, float logProbability = 0, ReadOnlyMemory<byte>? utf8Bytes = null);
16401641
public static ChatTokenUsage ChatTokenUsage(int outputTokenCount = 0, int inputTokenCount = 0, int totalTokenCount = 0, ChatOutputTokenUsageDetails outputTokenDetails = null, ChatInputTokenUsageDetails inputTokenDetails = null);
@@ -2169,15 +2170,7 @@ public static class OpenAIModelsModelFactory {
21692170
}
21702171
}
21712172
namespace OpenAI.Moderations {
2172-
[Flags]
2173-
public enum ModerationApplicableInputKinds {
2174-
None = 0,
2175-
Other = 1,
2176-
Text = 2,
2177-
Image = 4
2178-
}
21792173
public class ModerationCategory {
2180-
public ModerationApplicableInputKinds ApplicableInputKinds { get; }
21812174
public bool Flagged { get; }
21822175
public float Score { get; }
21832176
}
@@ -2228,7 +2221,7 @@ public class ModerationResultCollection : ObjectModel.ReadOnlyCollection<Moderat
22282221
BinaryData IPersistableModel<ModerationResultCollection>.Write(ModelReaderWriterOptions options);
22292222
}
22302223
public static class OpenAIModerationsModelFactory {
2231-
public static ModerationCategory ModerationCategory(bool flagged = false, float score = 0, ModerationApplicableInputKinds applicableInputKinds = ModerationApplicableInputKinds.None);
2224+
public static ModerationCategory ModerationCategory(bool flagged = false, float score = 0);
22322225
public static ModerationResult ModerationResult(bool flagged = false, ModerationCategory hate = null, ModerationCategory hateThreatening = null, ModerationCategory harassment = null, ModerationCategory harassmentThreatening = null, ModerationCategory selfHarm = null, ModerationCategory selfHarmIntent = null, ModerationCategory selfHarmInstructions = null, ModerationCategory sexual = null, ModerationCategory sexualMinors = null, ModerationCategory violence = null, ModerationCategory violenceGraphic = null, ModerationCategory illicit = null, ModerationCategory illicitViolent = null);
22332226
public static ModerationResultCollection ModerationResultCollection(string id = null, string model = null, IEnumerable<ModerationResult> items = null);
22342227
}
@@ -2259,10 +2252,10 @@ public enum ConversationContentModalities {
22592252
public abstract class ConversationContentPart : IJsonModel<ConversationContentPart>, IPersistableModel<ConversationContentPart> {
22602253
public string AudioTranscript { get; }
22612254
public string Text { get; }
2262-
public static ConversationContentPart FromInputAudioTranscript(string transcript = null);
2263-
public static ConversationContentPart FromInputText(string text);
2264-
public static ConversationContentPart FromOutputAudioTranscript(string transcript = null);
2265-
public static ConversationContentPart FromOutputText(string text);
2255+
public static ConversationContentPart CreateInputAudioTranscriptPart(string transcript = null);
2256+
public static ConversationContentPart CreateInputTextPart(string text);
2257+
public static ConversationContentPart CreateOutputAudioTranscriptPart(string transcript = null);
2258+
public static ConversationContentPart CreateOutputTextPart(string text);
22662259
public static implicit operator ConversationContentPart(string text);
22672260
ConversationContentPart IJsonModel<ConversationContentPart>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
22682261
void IJsonModel<ConversationContentPart>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
@@ -2395,7 +2388,7 @@ public abstract class ConversationItem : IJsonModel<ConversationItem>, IPersista
23952388
public static ConversationItem CreateAssistantMessage(IEnumerable<ConversationContentPart> contentItems);
23962389
public static ConversationItem CreateFunctionCall(string name, string callId, string arguments);
23972390
public static ConversationItem CreateFunctionCallOutput(string callId, string output);
2398-
public static ConversationItem CreateSystemMessage(string toolCallId, IEnumerable<ConversationContentPart> contentItems);
2391+
public static ConversationItem CreateSystemMessage(IEnumerable<ConversationContentPart> contentItems);
23992392
public static ConversationItem CreateUserMessage(IEnumerable<ConversationContentPart> contentItems);
24002393
ConversationItem IJsonModel<ConversationItem>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
24012394
void IJsonModel<ConversationItem>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);

examples/Assistants/Example04_AllTheTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ CollectionResult<ThreadMessage> messages
180180
Console.WriteLine($"Run step: {step.Status}");
181181
foreach (RunStepToolCall toolCall in step.Details.ToolCalls)
182182
{
183-
Console.WriteLine($" --> Tool call: {toolCall.ToolKind}");
183+
Console.WriteLine($" --> Tool call: {toolCall.Kind}");
184184
foreach (RunStepCodeInterpreterOutput output in toolCall.CodeInterpreterOutputs)
185185
{
186186
Console.WriteLine($" --> Output: {output.ImageFileId}");

examples/OpenAI.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
1818
<PackageReference Include="NUnit" Version="3.13.2" />
1919
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
2121
<PackageReference Include="Moq" Version="[4.18.2]" />
2222
</ItemGroup>
2323
</Project>

0 commit comments

Comments
 (0)