Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Made improvements to the experimental Realtime API. Please note this features area is currently under rapid development and not all changes may be reflected here. (commit_hash)
- Several types have been renamed for consistency and clarity.
- `ConversationRateLimitsUpdate` (previously `ConversationRateLimitsUpdatedUpdate`) now includes named `RequestDetails` and `TokenDetails` properties, mapping to the corresponding named items in the underlying `rate_limits` command payload.
- Serialization and deserialization of `ConversationToolChoice` literal values (such as `"required"`) is fixed

### Other Changes

Expand Down
9 changes: 5 additions & 4 deletions api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2755,10 +2755,11 @@ public class ConversationToolChoice : IJsonModel<ConversationToolChoice>, IPersi
BinaryData IPersistableModel<ConversationToolChoice>.Write(ModelReaderWriterOptions options);
}
public enum ConversationToolChoiceKind {
Auto = 0,
None = 1,
Required = 2,
Function = 3
Unknown = 0,
Auto = 1,
None = 2,
Required = 3,
Function = 4
}
public readonly partial struct ConversationToolKind : IEquatable<ConversationToolKind> {
private readonly object _dummy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public ConversationToolChoice ToolChoice
get => ConversationToolChoice.FromBinaryData(_internalToolChoice);
set
{
_internalToolChoice = ModelReaderWriter.Write(value);
_internalToolChoice = value is not null
? ModelReaderWriter.Write(value)
: null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static void SerializeConversationToolChoice(ConversationToolChoice inst
}
else
{
writer.WriteStringValue(instance.Kind.ToString());
writer.WriteStringValue(instance.Kind.ToSerialString());
}
}

Expand All @@ -50,7 +50,7 @@ internal static ConversationToolChoice DeserializeConversationToolChoice(JsonEle
return choiceObject switch
{
InternalRealtimeToolChoiceFunctionObject => new(ConversationToolChoiceKind.Function, choiceObject),
_ => null,
_ => new(ConversationToolChoiceKind.Unknown, choiceObject),
};
}
return null;
Expand Down
4 changes: 4 additions & 0 deletions src/Custom/RealtimeConversation/ConversationToolChoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ internal ConversationToolChoice(ConversationToolChoiceKind choiceKind, InternalR
Kind = choiceKind;
_objectToolChoice = objectToolChoice;
}

internal ConversationToolChoice() : this(ConversationToolChoiceKind.Unknown, null)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ namespace OpenAI.RealtimeConversation;
[CodeGenModel("RealtimeToolChoiceLiteral")]
public enum ConversationToolChoiceKind
{
Unknown,
[CodeGenMember("Auto")]
Auto,
[CodeGenMember("None")]
None,
[CodeGenMember("Required")]
Required,
[CodeGenMember("Function")]
Function,
}
29 changes: 29 additions & 0 deletions tests/RealtimeConversation/ConversationSmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ public class ConversationSmokeTests : ConversationTestFixtureBase
public ConversationSmokeTests(bool isAsync) : base(isAsync)
{ }

[Test]
public void ToolChoiceSerializationInSessionOptionsWorks()
{
foreach((ConversationToolChoice toolChoice, string expected) in new (ConversationToolChoice, string)[]
{
(null, "{}"),
(ConversationToolChoice.CreateNoneToolChoice(), @"{""tool_choice"":""none""}"),
(ConversationToolChoice.CreateAutoToolChoice(), @"{""tool_choice"":""auto""}"),
(ConversationToolChoice.CreateRequiredToolChoice(), @"{""tool_choice"":""required""}"),
(ConversationToolChoice.CreateFunctionToolChoice("foo"), @"{""function"":{""name"":""foo""}")
})
{
ConversationSessionOptions options = new()
{
ToolChoice = toolChoice,
};
Assert.That(ModelReaderWriter.Write(options).ToString(), Does.Contain(expected));
}

ConversationToolChoice mrwToolChoice = ModelReaderWriter.Read<ConversationToolChoice>(
BinaryData.FromString("""
{
"type":"some_manual_type"
}
"""));
Assert.That(mrwToolChoice.Kind, Is.EqualTo(ConversationToolChoiceKind.Unknown));
Assert.That(ModelReaderWriter.Write(mrwToolChoice).ToString(), Does.Contain(@"""type"":""some_manual_type"""));
}

[Test]
public void ItemCreation()
{
Expand Down
Loading