openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/ChatCompletion.cs
90lines · modecode
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | |
| 4 | namespace OpenAI.Chat; |
| 5 | |
| 6 | /// <summary> A chat completion generated by the model. </summary> |
| 7 | [CodeGenModel("CreateChatCompletionResponse")] |
| 8 | public partial class ChatCompletion |
| 9 | { |
| 10 | private IReadOnlyList<ChatTokenLogProbabilityDetails> _contentTokenLogProbabilities; |
| 11 | private IReadOnlyList<ChatTokenLogProbabilityDetails> _refusalTokenLogProbabilities; |
| 12 | |
| 13 | // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class. |
| 14 | /// <summary> The object type, which is always `chat.completion`. </summary> |
| 15 | [CodeGenMember("Object")] |
| 16 | internal InternalCreateChatCompletionResponseObject Object { get; } = InternalCreateChatCompletionResponseObject.ChatCompletion; |
| 17 | |
| 18 | // CUSTOM: Made internal. |
| 19 | [CodeGenMember("ServiceTier")] |
| 20 | internal InternalCreateChatCompletionResponseServiceTier? ServiceTier { get; } |
| 21 | |
| 22 | // CUSTOM: Made internal. We only get back a single choice, and instead we flatten the structure for usability. |
| 23 | [CodeGenMember("Choices")] |
| 24 | internal IReadOnlyList<InternalCreateChatCompletionResponseChoice> Choices { get; } |
| 25 | |
| 26 | // CUSTOM: Renamed. |
| 27 | /// <summary> The timestamp when the chat completion was created. </summary> |
| 28 | [CodeGenMember("Created")] |
| 29 | public DateTimeOffset CreatedAt { get; } |
| 30 | |
| 31 | // CUSTOM: Flattened choice property. |
| 32 | /// <summary> |
| 33 | /// The reason the model stopped generating tokens. This will be: |
| 34 | /// <list> |
| 35 | /// <item> |
| 36 | /// <see cref="ChatFinishReason.Stop"/> if the model hit a natural stop point or a provided stop sequence |
| 37 | /// </item> |
| 38 | /// <item> |
| 39 | /// <see cref="ChatFinishReason.Length"/> if the maximum number of tokens specified in the request was reached |
| 40 | /// </item> |
| 41 | /// <item> |
| 42 | /// <see cref="ChatFinishReason.ContentFilter"/> if content was omitted due to a flag from our content filters |
| 43 | /// </item> |
| 44 | /// <item> |
| 45 | /// <see cref="ChatFinishReason.ToolCalls"/> if the model called a tool |
| 46 | /// </item> |
| 47 | /// <item> |
| 48 | /// <see cref="ChatFinishReason.FunctionCall"/> (obsolte) if the model called a function |
| 49 | /// </item> |
| 50 | /// </list> |
| 51 | /// </summary> |
| 52 | public ChatFinishReason FinishReason => Choices[0].FinishReason; |
| 53 | |
| 54 | // CUSTOM: Flattened choice logprobs property. |
| 55 | /// <summary> The message content tokens with log probability information. </summary> |
| 56 | public IReadOnlyList<ChatTokenLogProbabilityDetails> ContentTokenLogProbabilities => |
| 57 | _contentTokenLogProbabilities |
| 58 | ??= Choices[0].Logprobs?.Content |
| 59 | ?? new ChangeTrackingList<ChatTokenLogProbabilityDetails>(); |
| 60 | |
| 61 | // CUSTOM: Flattened choice logprobs property. |
| 62 | /// <summary> The message refusal tokens with log probability information. </summary> |
| 63 | public IReadOnlyList<ChatTokenLogProbabilityDetails> RefusalTokenLogProbabilities => |
| 64 | _refusalTokenLogProbabilities |
| 65 | ??= Choices[0].Logprobs?.Refusal |
| 66 | ?? new ChangeTrackingList<ChatTokenLogProbabilityDetails>(); |
| 67 | |
| 68 | // CUSTOM: Flattened choice message property. |
| 69 | /// <summary> The role of the author of this message. </summary> |
| 70 | public ChatMessageRole Role => Choices[0].Message.Role; |
| 71 | |
| 72 | // CUSTOM: Flattened choice message property. |
| 73 | /// <summary> The contents of the message. </summary> |
| 74 | public ChatMessageContent Content => Choices[0].Message.Content; |
| 75 | |
| 76 | // CUSTOM: Flattened choice message property. |
| 77 | /// <summary> The tool calls generated by the model, such as function calls. </summary> |
| 78 | public IReadOnlyList<ChatToolCall> ToolCalls => Choices[0].Message.ToolCalls; |
| 79 | |
| 80 | // CUSTOM: Flattened choice message property. |
| 81 | /// <summary> The refusal message generated by the model. </summary> |
| 82 | public string Refusal => Choices[0].Message.Refusal; |
| 83 | |
| 84 | // CUSTOM: Flattened choice message property. |
| 85 | [Obsolete($"This property is obsolete. Please use {nameof(ToolCalls)} instead.")] |
| 86 | public ChatFunctionCall FunctionCall => Choices[0].Message.FunctionCall; |
| 87 | |
| 88 | /// <summary> The audio response generated by the model. </summary> |
| 89 | public ChatOutputAudio OutputAudio => Choices[0].Message.Audio; |
| 90 | } |
| 91 | |