openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/customize-openairesponsescontext-attribute

Branches

Tags

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

Clone

HTTPS

Download ZIP

OpenAI/src/Custom/Chat/Messages/SystemChatMessage.Serialization.cs

35lines · modecode

1using Microsoft.TypeSpec.Generator.Customizations;
2using System.ClientModel.Primitives;
3using System.Text.Json;
4
5namespace OpenAI.Chat;
6
7[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Chat.SystemChatMessage>.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))]
8public partial class SystemChatMessage : IJsonModel<SystemChatMessage>
9{
10 void IJsonModel<SystemChatMessage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
11 => CustomSerializationHelpers.SerializeInstance(this, SerializeSystemChatMessage, writer, options);
12
13 internal static void SerializeSystemChatMessage(SystemChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
14 => instance.WriteCore(writer, options);
15
16 internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
17 {
18#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
19 if (Patch.Contains("$"u8))
20 {
21 writer.WriteRawValue(Patch.GetJson("$"u8));
22 return;
23 }
24#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
25
26 writer.WriteStartObject();
27 WriteRoleProperty(writer, options);
28 WriteContentProperty(writer, options);
29 writer.WriteOptionalProperty("name"u8, ParticipantName, options);
30#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
31 Patch.WriteTo(writer);
32#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
33 writer.WriteEndObject();
34 }
35}