Skip to content

Commit 21f0416

Browse files
committed
fb
1 parent a8c6bc9 commit 21f0416

File tree

18 files changed

+6938
-6193
lines changed

18 files changed

+6938
-6193
lines changed

api/OpenAI.net8.0.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5593,6 +5593,7 @@ public enum MessageStatus {
55935593
[Experimental("OPENAI001")]
55945594
public class OpenAIResponse : IJsonModel<OpenAIResponse>, IPersistableModel<OpenAIResponse> {
55955595
public bool? BackgroundModeEnabled { get; }
5596+
public string ConversationId { get; }
55965597
public DateTimeOffset CreatedAt { get; }
55975598
public string EndUserId { get; }
55985599
public ResponseError Error { get; }
@@ -5611,12 +5612,14 @@ public class OpenAIResponse : IJsonModel<OpenAIResponse>, IPersistableModel<Open
56115612
public ref JsonPatch Patch { get; }
56125613
public string PreviousResponseId { get; }
56135614
public ResponseReasoningOptions ReasoningOptions { get; }
5615+
public string SafetyIdentifier { get; }
56145616
public ResponseServiceTier? ServiceTier { get; }
56155617
public ResponseStatus? Status { get; }
56165618
public float? Temperature { get; }
56175619
public ResponseTextOptions TextOptions { get; }
56185620
public ResponseToolChoice ToolChoice { get; }
56195621
public IList<ResponseTool> Tools { get; }
5622+
public int? TopLogProbabilityCount { get; }
56205623
public float? TopP { get; }
56215624
public ResponseTruncationMode? TruncationMode { get; }
56225625
public ResponseTokenUsage Usage { get; }
@@ -5673,7 +5676,7 @@ public class OpenAIResponseClient {
56735676
[Experimental("OPENAI001")]
56745677
public static class OpenAIResponsesModelFactory {
56755678
public static MessageResponseItem MessageResponseItem(string id = null, MessageRole role = MessageRole.Assistant, MessageStatus? status = null);
5676-
public static OpenAIResponse OpenAIResponse(string id = null, DateTimeOffset createdAt = default, ResponseStatus? status = null, ResponseError error = null, ResponseTokenUsage usage = null, string endUserId = null, ResponseReasoningOptions reasoningOptions = null, int? maxOutputTokenCount = null, int? maxToolCallCount = null, ResponseTextOptions textOptions = null, ResponseTruncationMode? truncationMode = null, ResponseIncompleteStatusDetails incompleteStatusDetails = null, IEnumerable<ResponseItem> outputItems = null, bool parallelToolCallsEnabled = false, ResponseToolChoice toolChoice = null, string model = null, IDictionary<string, string> metadata = null, float? temperature = null, float? topP = null, ResponseServiceTier? serviceTier = null, string previousResponseId = null, bool? backgroundModeEnabled = null, string instructions = null, IEnumerable<ResponseTool> tools = null);
5679+
public static OpenAIResponse OpenAIResponse(string id = null, DateTimeOffset createdAt = default, ResponseStatus? status = null, ResponseError error = null, ResponseTokenUsage usage = null, string endUserId = null, string safetyIdentifier = null, ResponseReasoningOptions reasoningOptions = null, int? maxOutputTokenCount = null, int? maxToolCallCount = null, ResponseTextOptions textOptions = null, ResponseTruncationMode? truncationMode = null, ResponseIncompleteStatusDetails incompleteStatusDetails = null, IEnumerable<ResponseItem> outputItems = null, bool parallelToolCallsEnabled = false, ResponseToolChoice toolChoice = null, string model = null, IDictionary<string, string> metadata = null, float? temperature = null, int? topLogProbabilityCount = null, float? topP = null, ResponseServiceTier? serviceTier = null, string previousResponseId = null, bool? backgroundModeEnabled = null, string instructions = null, IEnumerable<ResponseTool> tools = null, string conversationId = null);
56775680
public static ReasoningResponseItem ReasoningResponseItem(string id = null, string encryptedContent = null, ReasoningStatus? status = null, IEnumerable<ReasoningSummaryPart> summaryParts = null);
56785681
public static ReasoningResponseItem ReasoningResponseItem(string id = null, string encryptedContent = null, ReasoningStatus? status = null, string summaryText = null);
56795682
public static ReferenceResponseItem ReferenceResponseItem(string id = null);

api/OpenAI.netstandard2.0.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4908,6 +4908,7 @@ public enum MessageStatus {
49084908
}
49094909
public class OpenAIResponse : IJsonModel<OpenAIResponse>, IPersistableModel<OpenAIResponse> {
49104910
public bool? BackgroundModeEnabled { get; }
4911+
public string ConversationId { get; }
49114912
public DateTimeOffset CreatedAt { get; }
49124913
public string EndUserId { get; }
49134914
public ResponseError Error { get; }
@@ -4925,12 +4926,14 @@ public class OpenAIResponse : IJsonModel<OpenAIResponse>, IPersistableModel<Open
49254926
public ref JsonPatch Patch { get; }
49264927
public string PreviousResponseId { get; }
49274928
public ResponseReasoningOptions ReasoningOptions { get; }
4929+
public string SafetyIdentifier { get; }
49284930
public ResponseServiceTier? ServiceTier { get; }
49294931
public ResponseStatus? Status { get; }
49304932
public float? Temperature { get; }
49314933
public ResponseTextOptions TextOptions { get; }
49324934
public ResponseToolChoice ToolChoice { get; }
49334935
public IList<ResponseTool> Tools { get; }
4936+
public int? TopLogProbabilityCount { get; }
49344937
public float? TopP { get; }
49354938
public ResponseTruncationMode? TruncationMode { get; }
49364939
public ResponseTokenUsage Usage { get; }
@@ -4983,7 +4986,7 @@ public class OpenAIResponseClient {
49834986
}
49844987
public static class OpenAIResponsesModelFactory {
49854988
public static MessageResponseItem MessageResponseItem(string id = null, MessageRole role = MessageRole.Assistant, MessageStatus? status = null);
4986-
public static OpenAIResponse OpenAIResponse(string id = null, DateTimeOffset createdAt = default, ResponseStatus? status = null, ResponseError error = null, ResponseTokenUsage usage = null, string endUserId = null, ResponseReasoningOptions reasoningOptions = null, int? maxOutputTokenCount = null, int? maxToolCallCount = null, ResponseTextOptions textOptions = null, ResponseTruncationMode? truncationMode = null, ResponseIncompleteStatusDetails incompleteStatusDetails = null, IEnumerable<ResponseItem> outputItems = null, bool parallelToolCallsEnabled = false, ResponseToolChoice toolChoice = null, string model = null, IDictionary<string, string> metadata = null, float? temperature = null, float? topP = null, ResponseServiceTier? serviceTier = null, string previousResponseId = null, bool? backgroundModeEnabled = null, string instructions = null, IEnumerable<ResponseTool> tools = null);
4989+
public static OpenAIResponse OpenAIResponse(string id = null, DateTimeOffset createdAt = default, ResponseStatus? status = null, ResponseError error = null, ResponseTokenUsage usage = null, string endUserId = null, string safetyIdentifier = null, ResponseReasoningOptions reasoningOptions = null, int? maxOutputTokenCount = null, int? maxToolCallCount = null, ResponseTextOptions textOptions = null, ResponseTruncationMode? truncationMode = null, ResponseIncompleteStatusDetails incompleteStatusDetails = null, IEnumerable<ResponseItem> outputItems = null, bool parallelToolCallsEnabled = false, ResponseToolChoice toolChoice = null, string model = null, IDictionary<string, string> metadata = null, float? temperature = null, int? topLogProbabilityCount = null, float? topP = null, ResponseServiceTier? serviceTier = null, string previousResponseId = null, bool? backgroundModeEnabled = null, string instructions = null, IEnumerable<ResponseTool> tools = null, string conversationId = null);
49874990
public static ReasoningResponseItem ReasoningResponseItem(string id = null, string encryptedContent = null, ReasoningStatus? status = null, IEnumerable<ReasoningSummaryPart> summaryParts = null);
49884991
public static ReasoningResponseItem ReasoningResponseItem(string id = null, string encryptedContent = null, ReasoningStatus? status = null, string summaryText = null);
49894992
public static ReferenceResponseItem ReferenceResponseItem(string id = null);

specification/base/typespec/common/models.tsp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ model ModelResponsePropertiesForResponse {
285285
@maxValue(2)
286286
temperature: float32 | null;
287287

288+
/** An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. */
289+
top_logprobs?: int32 | null;
290+
288291
@doc("""
289292
An alternative to sampling with temperature, called nucleus sampling,
290293
where the model considers the results of the tokens with top_p probability
@@ -300,6 +303,10 @@ model ModelResponsePropertiesForResponse {
300303
/** A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices#end-user-ids). */
301304
user: string | null;
302305

306+
/**A stable identifier used to help detect users of your application that may be violating OpenAI's usage policies.
307+
The IDs should be a string that uniquely identifies each user. We recommend hashing their username or email address, in order to avoid sending us any identifying information. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).*/
308+
safety_identifier?: string;
309+
303310
service_tier?: ServiceTier;
304311
}
305312

specification/base/typespec/responses/models.tsp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ model Response {
168168

169169
/** Whether to allow the model to run tool calls in parallel. */
170170
parallel_tool_calls: boolean = true;
171+
172+
/** The conversation that this response belongs to. Input items and output items from this response are automatically added to this conversation. */
173+
conversation?: `ConversationParam-2` | null;
171174
}
172175

173176
model ResponseProperties {

src/Custom/Responses/Internal/GeneratorStubs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ namespace OpenAI.Responses;
121121
[CodeGenType("DotNetCustomToolCallApprovalPolicyAlways")] internal partial class InternalDotNetCustomToolCallApprovalPolicyAlways { }
122122
[CodeGenType("DotNetCustomToolCallApprovalPolicyNever")] internal partial class InternalDotNetCustomToolCallApprovalPolicyNever { }
123123
[CodeGenType("UnknownCodeInterpreterToolOutput")] internal partial class InternalUnknownCodeInterpreterToolOutput {}
124-
[CodeGenType("UnknownCodeInterpreterContainerConfiguration")] internal partial class InternalUnknownCodeInterpreterContainerConfiguration {}
124+
[CodeGenType("UnknownCodeInterpreterContainerConfiguration")] internal partial class InternalUnknownCodeInterpreterContainerConfiguration {}
125+
[CodeGenType("ConversationParam2")] internal partial class InternalConversation {}

src/Custom/Responses/OpenAIResponse.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public partial class OpenAIResponse
6262
[CodeGenMember("Model")]
6363
public string Model { get; }
6464

65+
public string ConversationId => Conversation.Id;
66+
67+
// CUSTOM: Renamed.
68+
[CodeGenMember("TopLogprobs")]
69+
public int? TopLogProbabilityCount { get; }
70+
6571
// CUSTOM: Made internal
6672
internal string Object { get; } = "response";
6773

src/Custom/Responses/OpenAIResponsesModelFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static OpenAIResponse OpenAIResponse(
1818
ResponseError error = null,
1919
ResponseTokenUsage usage = null,
2020
string endUserId = null,
21+
string safetyIdentifier = null,
2122
ResponseReasoningOptions reasoningOptions = null,
2223
int? maxOutputTokenCount = null,
2324
int? maxToolCallCount = null,
@@ -30,12 +31,14 @@ public static OpenAIResponse OpenAIResponse(
3031
string model = null,
3132
IDictionary<string, string> metadata = null,
3233
float? temperature = null,
34+
int? topLogProbabilityCount = null,
3335
float? topP = null,
3436
ResponseServiceTier? serviceTier = null,
3537
string previousResponseId = null,
3638
bool? backgroundModeEnabled = null,
3739
string instructions = null,
38-
IEnumerable<ResponseTool> tools = null)
40+
IEnumerable<ResponseTool> tools = null,
41+
string conversationId = null)
3942
{
4043
outputItems ??= new List<ResponseItem>();
4144
tools ??= new List<ResponseTool>();
@@ -44,6 +47,7 @@ public static OpenAIResponse OpenAIResponse(
4447
return new OpenAIResponse(
4548
metadata: metadata,
4649
temperature: temperature,
50+
topLogProbabilityCount: topLogProbabilityCount,
4751
topP: topP,
4852
serviceTier: serviceTier,
4953
previousResponseId: previousResponseId,
@@ -56,6 +60,7 @@ public static OpenAIResponse OpenAIResponse(
5660
error: error,
5761
usage: usage,
5862
endUserId: endUserId,
63+
safetyIdentifier: safetyIdentifier,
5964
reasoningOptions: reasoningOptions,
6065
maxOutputTokenCount: maxOutputTokenCount,
6166
maxToolCallCount: maxToolCallCount,
@@ -67,6 +72,7 @@ public static OpenAIResponse OpenAIResponse(
6772
toolChoice: toolChoice,
6873
model: model,
6974
@object: "response",
75+
conversation: new(conversationId),
7076
patch: default);
7177
}
7278

src/Generated/Models/OpenAIContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ namespace OpenAI
227227
[ModelReaderWriterBuildable(typeof(InternalComputerUsePreviewToolCallOutputItemParam))]
228228
[ModelReaderWriterBuildable(typeof(InternalContainerFileListResource))]
229229
[ModelReaderWriterBuildable(typeof(InternalContainerListResource))]
230+
[ModelReaderWriterBuildable(typeof(InternalConversation))]
230231
[ModelReaderWriterBuildable(typeof(InternalConversationItemCollectionOptions))]
231232
[ModelReaderWriterBuildable(typeof(InternalCoordinate))]
232233
[ModelReaderWriterBuildable(typeof(InternalCreateAssistantRequestToolResources))]
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System;
6+
using System.ClientModel.Primitives;
7+
using System.Text;
8+
using System.Text.Json;
9+
using OpenAI;
10+
11+
namespace OpenAI.Responses
12+
{
13+
internal partial class InternalConversation : IJsonModel<InternalConversation>
14+
{
15+
internal InternalConversation()
16+
{
17+
}
18+
19+
void IJsonModel<InternalConversation>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
20+
{
21+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
22+
if (Patch.Contains("$"u8))
23+
{
24+
writer.WriteRawValue(Patch.GetJson("$"u8));
25+
return;
26+
}
27+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
28+
29+
writer.WriteStartObject();
30+
JsonModelWriteCore(writer, options);
31+
writer.WriteEndObject();
32+
}
33+
34+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
35+
{
36+
string format = options.Format == "W" ? ((IPersistableModel<InternalConversation>)this).GetFormatFromOptions(options) : options.Format;
37+
if (format != "J")
38+
{
39+
throw new FormatException($"The model {nameof(InternalConversation)} does not support writing '{format}' format.");
40+
}
41+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
42+
if (!Patch.Contains("$.id"u8))
43+
{
44+
writer.WritePropertyName("id"u8);
45+
writer.WriteStringValue(Id);
46+
}
47+
48+
Patch.WriteTo(writer);
49+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
50+
}
51+
52+
InternalConversation IJsonModel<InternalConversation>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
53+
54+
protected virtual InternalConversation JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
55+
{
56+
string format = options.Format == "W" ? ((IPersistableModel<InternalConversation>)this).GetFormatFromOptions(options) : options.Format;
57+
if (format != "J")
58+
{
59+
throw new FormatException($"The model {nameof(InternalConversation)} does not support reading '{format}' format.");
60+
}
61+
using JsonDocument document = JsonDocument.ParseValue(ref reader);
62+
return DeserializeInternalConversation(document.RootElement, null, options);
63+
}
64+
65+
internal static InternalConversation DeserializeInternalConversation(JsonElement element, BinaryData data, ModelReaderWriterOptions options)
66+
{
67+
if (element.ValueKind == JsonValueKind.Null)
68+
{
69+
return null;
70+
}
71+
string id = default;
72+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
73+
JsonPatch patch = new JsonPatch(data is null ? ReadOnlyMemory<byte>.Empty : data.ToMemory());
74+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
75+
foreach (var prop in element.EnumerateObject())
76+
{
77+
if (prop.NameEquals("id"u8))
78+
{
79+
id = prop.Value.GetString();
80+
continue;
81+
}
82+
patch.Set([.. "$."u8, .. Encoding.UTF8.GetBytes(prop.Name)], prop.Value.GetUtf8Bytes());
83+
}
84+
return new InternalConversation(id, patch);
85+
}
86+
87+
BinaryData IPersistableModel<InternalConversation>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
88+
89+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
90+
{
91+
string format = options.Format == "W" ? ((IPersistableModel<InternalConversation>)this).GetFormatFromOptions(options) : options.Format;
92+
switch (format)
93+
{
94+
case "J":
95+
return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
96+
default:
97+
throw new FormatException($"The model {nameof(InternalConversation)} does not support writing '{options.Format}' format.");
98+
}
99+
}
100+
101+
InternalConversation IPersistableModel<InternalConversation>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
102+
103+
protected virtual InternalConversation PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
104+
{
105+
string format = options.Format == "W" ? ((IPersistableModel<InternalConversation>)this).GetFormatFromOptions(options) : options.Format;
106+
switch (format)
107+
{
108+
case "J":
109+
using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions))
110+
{
111+
return DeserializeInternalConversation(document.RootElement, data, options);
112+
}
113+
default:
114+
throw new FormatException($"The model {nameof(InternalConversation)} does not support reading '{options.Format}' format.");
115+
}
116+
}
117+
118+
string IPersistableModel<InternalConversation>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
119+
}
120+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System.ClientModel.Primitives;
6+
using System.ComponentModel;
7+
using System.Diagnostics.CodeAnalysis;
8+
using System.Text.Json.Serialization;
9+
10+
namespace OpenAI.Responses
11+
{
12+
internal partial class InternalConversation
13+
{
14+
[Experimental("SCME0001")]
15+
private JsonPatch _patch;
16+
17+
internal InternalConversation(string id)
18+
{
19+
Id = id;
20+
}
21+
22+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
23+
internal InternalConversation(string id, in JsonPatch patch)
24+
{
25+
Id = id;
26+
_patch = patch;
27+
}
28+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
29+
30+
[JsonIgnore]
31+
[EditorBrowsable(EditorBrowsableState.Never)]
32+
[Experimental("SCME0001")]
33+
public ref JsonPatch Patch => ref _patch;
34+
35+
public string Id { get; }
36+
}
37+
}

0 commit comments

Comments
 (0)