openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Chat/ChatCompletion.cs

63lines · modecode

1using System;
2using System.Collections.Generic;
3
4namespace OpenAI.Chat;
5
6[CodeGenModel("CreateChatCompletionResponse")]
7public partial class ChatCompletion
8{
9 private IReadOnlyList<ChatTokenLogProbabilityInfo> _contentTokenLogProbabilities;
10
11 // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class.
12 /// <summary> The object type, which is always `chat.completion`. </summary>
13 [CodeGenMember("Object")]
14 private InternalCreateChatCompletionResponseObject Object { get; } = InternalCreateChatCompletionResponseObject.ChatCompletion;
15
16 // CUSTOM: Made internal. We only get back a single choice, and instead we flatten the structure for usability.
17 /// <summary> A list of chat completion choices. Can be more than one if `n` is greater than 1. </summary>
18 [CodeGenMember("Choices")]
19 internal IReadOnlyList<InternalCreateChatCompletionResponseChoice> Choices { get; }
20
21 // CUSTOM: Renamed.
22 /// <summary> The Unix timestamp (in seconds) of when the chat completion was created. </summary>
23 [CodeGenMember("Created")]
24 public DateTimeOffset CreatedAt { get; }
25
26 // CUSTOM: Flattened choice property.
27 /// <summary>
28 /// The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
29 /// `length` if the maximum number of tokens specified in the request was reached,
30 /// `content_filter` if content was omitted due to a flag from our content filters,
31 /// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
32 /// </summary>
33 public ChatFinishReason FinishReason => Choices[0].FinishReason;
34
35 // CUSTOM: Flattened choice logprobs property.
36 /// <summary>
37 /// Log probability information.
38 /// </summary>
39 public IReadOnlyList<ChatTokenLogProbabilityInfo> ContentTokenLogProbabilities => (Choices[0].Logprobs != null)
40 ? Choices[0].Logprobs.Content
41 : _contentTokenLogProbabilities ??= new ChangeTrackingList<ChatTokenLogProbabilityInfo>();
42
43 // CUSTOM: Flattened choice message property.
44 /// <summary>
45 /// The role of the author of this message.
46 /// </summary>
47 public ChatMessageRole Role => Choices[0].Message.Role;
48
49 // CUSTOM: Flattened choice message property.
50 /// <summary>
51 /// The contents of the message.
52 /// </summary>
53 public IReadOnlyList<ChatMessageContentPart> Content => Choices[0].Message.Content;
54
55 // CUSTOM: Flattened choice message property.
56 /// <summary>
57 /// The tool calls.
58 /// </summary>
59 public IReadOnlyList<ChatToolCall> ToolCalls => Choices[0].Message.ToolCalls;
60
61 // CUSTOM: Flattened choice message property.
62 public ChatFunctionCall FunctionCall => Choices[0].Message.FunctionCall;
63}
64