openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
achandmsft-patch-1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/Chat/Internal/InternalChatCompletionMessageToolCallFunction.Serialization.cs

30lines · modecode

1using System;
2using System.ClientModel.Primitives;
3using System.Runtime.CompilerServices;
4using System.Text.Json;
5
6namespace OpenAI.Chat;
7
8internal partial class InternalChatCompletionMessageToolCallFunction : IJsonModel<InternalChatCompletionMessageToolCallFunction>
9{
10 // CUSTOM: Replaced the call to WriteRawValue() for a call to WriteStringValue() because even though this property
11 // is supposed to be a JSON object, the REST API handles it as a string given that there is no guarantee that it
12 // actually is valid JSON.
13 [MethodImpl(MethodImplOptions.AggressiveInlining)]
14 private void SerializeArgumentsValue(Utf8JsonWriter writer, ModelReaderWriterOptions options)
15 {
16 string value = Arguments.ToMemory().IsEmpty
17 ? string.Empty
18 : Arguments.ToString();
19 writer.WriteStringValue(value);
20 }
21
22 // CUSTOM: Replaced the call to GetRawText() for a call to GetString() because otherwise the starting and ending
23 // quotes of the string are included in the BinaryData. While this is actually a string in the REST API, we want to
24 // handle it as JSON binary data instead.
25 [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 private static void DeserializeArgumentsValue(JsonProperty property, ref BinaryData arguments, ModelReaderWriterOptions options = null)
27 {
28 arguments = BinaryData.FromString(property.Value.GetString());
29 }
30}