Skip to content

Commit 3d1121a

Browse files
committed
Add support for File Search result content
1 parent 448181b commit 3d1121a

File tree

86 files changed

+1303
-776
lines changed

Some content is hidden

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

86 files changed

+1303
-776
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: 36 additions & 35 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);
@@ -2259,10 +2260,10 @@ public enum ConversationContentModalities {
22592260
public abstract class ConversationContentPart : IJsonModel<ConversationContentPart>, IPersistableModel<ConversationContentPart> {
22602261
public string AudioTranscript { get; }
22612262
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);
2263+
public static ConversationContentPart CreateInputAudioTranscriptPart(string transcript = null);
2264+
public static ConversationContentPart CreateInputTextPart(string text);
2265+
public static ConversationContentPart CreateOutputAudioTranscriptPart(string transcript = null);
2266+
public static ConversationContentPart CreateOutputTextPart(string text);
22662267
public static implicit operator ConversationContentPart(string text);
22672268
ConversationContentPart IJsonModel<ConversationContentPart>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
22682269
void IJsonModel<ConversationContentPart>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
@@ -2395,7 +2396,7 @@ public abstract class ConversationItem : IJsonModel<ConversationItem>, IPersista
23952396
public static ConversationItem CreateAssistantMessage(IEnumerable<ConversationContentPart> contentItems);
23962397
public static ConversationItem CreateFunctionCall(string name, string callId, string arguments);
23972398
public static ConversationItem CreateFunctionCallOutput(string callId, string output);
2398-
public static ConversationItem CreateSystemMessage(string toolCallId, IEnumerable<ConversationContentPart> contentItems);
2399+
public static ConversationItem CreateSystemMessage(IEnumerable<ConversationContentPart> contentItems);
23992400
public static ConversationItem CreateUserMessage(IEnumerable<ConversationContentPart> contentItems);
24002401
ConversationItem IJsonModel<ConversationItem>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
24012402
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>

src/Custom/Assistants/AssistantClient.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,50 +1142,50 @@ public virtual AsyncCollectionResult<RunStep> GetRunStepsAsync(
11421142
}
11431143

11441144
/// <summary>
1145-
/// Rehydrates a page collection holding <see cref="RunStep"/> instances from a page token.
1145+
/// Gets a page collection holding <see cref="RunStep"/> instances associated with a <see cref="ThreadRun"/>.
11461146
/// </summary>
1147-
/// <param name="firstPageToken"> Page token corresponding to the first page of the collection to rehydrate. </param>
1147+
/// <param name="threadId"> The ID of the thread associated with the run. </param>
1148+
/// <param name="runId"> The ID of the run to list run steps from. </param>
1149+
/// <param name="options"></param>
11481150
/// <param name="cancellationToken">A token that can be used to cancel this method call.</param>
11491151
/// <returns> A collection of <see cref="RunStep"/>. </returns>
1150-
public virtual AsyncCollectionResult<RunStep> GetRunStepsAsync(
1151-
ContinuationToken firstPageToken,
1152+
public virtual CollectionResult<RunStep> GetRunSteps(
1153+
string threadId,
1154+
string runId,
1155+
RunStepCollectionOptions options = default,
11521156
CancellationToken cancellationToken = default)
11531157
{
1154-
Argument.AssertNotNull(firstPageToken, nameof(firstPageToken));
1158+
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
1159+
Argument.AssertNotNullOrEmpty(runId, nameof(runId));
11551160

1156-
RunStepCollectionPageToken pageToken = RunStepCollectionPageToken.FromToken(firstPageToken);
1157-
AsyncCollectionResult result = GetRunStepsAsync(pageToken?.ThreadId, pageToken?.RunId, pageToken?.Limit, pageToken?.Order, pageToken?.After, pageToken?.Before, cancellationToken.ToRequestOptions());
1161+
CollectionResult result = GetRunSteps(threadId, runId, options?.PageSizeLimit, options?.Order?.ToString(), options?.AfterId, options?.BeforeId, cancellationToken.ToRequestOptions());
11581162

1159-
if (result is not AsyncCollectionResult<RunStep> collection)
1163+
if (result is not CollectionResult<RunStep> collection)
11601164
{
1161-
throw new InvalidOperationException("Failed to cast protocol return type to expected collection type 'AsyncCollectionResult<RunStep>'.");
1165+
throw new InvalidOperationException("Failed to cast protocol return type to expected collection type 'CollectionResult<RunStep>'.");
11621166
}
11631167

11641168
return collection;
11651169
}
11661170

11671171
/// <summary>
1168-
/// Gets a page collection holding <see cref="RunStep"/> instances associated with a <see cref="ThreadRun"/>.
1172+
/// Rehydrates a page collection holding <see cref="RunStep"/> instances from a page token.
11691173
/// </summary>
1170-
/// <param name="threadId"> The ID of the thread associated with the run. </param>
1171-
/// <param name="runId"> The ID of the run to list run steps from. </param>
1172-
/// <param name="options"></param>
1174+
/// <param name="firstPageToken"> Page token corresponding to the first page of the collection to rehydrate. </param>
11731175
/// <param name="cancellationToken">A token that can be used to cancel this method call.</param>
11741176
/// <returns> A collection of <see cref="RunStep"/>. </returns>
1175-
public virtual CollectionResult<RunStep> GetRunSteps(
1176-
string threadId,
1177-
string runId,
1178-
RunStepCollectionOptions options = default,
1177+
public virtual AsyncCollectionResult<RunStep> GetRunStepsAsync(
1178+
ContinuationToken firstPageToken,
11791179
CancellationToken cancellationToken = default)
11801180
{
1181-
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
1182-
Argument.AssertNotNullOrEmpty(runId, nameof(runId));
1181+
Argument.AssertNotNull(firstPageToken, nameof(firstPageToken));
11831182

1184-
CollectionResult result = GetRunSteps(threadId, runId, options?.PageSizeLimit, options?.Order?.ToString(), options?.AfterId, options?.BeforeId, cancellationToken.ToRequestOptions());
1183+
RunStepCollectionPageToken pageToken = RunStepCollectionPageToken.FromToken(firstPageToken);
1184+
AsyncCollectionResult result = GetRunStepsAsync(pageToken?.ThreadId, pageToken?.RunId, pageToken?.Limit, pageToken?.Order, pageToken?.After, pageToken?.Before, cancellationToken.ToRequestOptions());
11851185

1186-
if (result is not CollectionResult<RunStep> collection)
1186+
if (result is not AsyncCollectionResult<RunStep> collection)
11871187
{
1188-
throw new InvalidOperationException("Failed to cast protocol return type to expected collection type 'CollectionResult<RunStep>'.");
1188+
throw new InvalidOperationException("Failed to cast protocol return type to expected collection type 'AsyncCollectionResult<RunStep>'.");
11891189
}
11901190

11911191
return collection;

src/Custom/Assistants/GeneratorStubs.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public readonly partial struct RunErrorCode { }
3434
[CodeGenModel("RunObjectIncompleteDetails")]
3535
public partial class RunIncompleteDetails { }
3636

37-
[Experimental("OPENAI001")]
38-
[CodeGenModel("RunStepObjectType")]
39-
public readonly partial struct RunStepType { }
40-
4137
[Experimental("OPENAI001")]
4238
[CodeGenModel("RunStepObjectStatus")]
4339
public readonly partial struct RunStepStatus { }
@@ -53,3 +49,4 @@ public readonly partial struct RunStepErrorCode { }
5349
[Experimental("OPENAI001")]
5450
[CodeGenModel("RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsObject")]
5551
public partial class RunStepCodeInterpreterOutput { }
52+

0 commit comments

Comments
 (0)