@@ -3,21 +3,29 @@ package com.cjcrafter.openai.chat
33import com.google.gson.JsonObject
44
55/* *
6- * Holds the data for 1 generated text completion. For most use cases, only 1
7- * [ChatChoice] is generated.
6+ * The OpenAI API returns a list of [ChatChoice]. Each chat choice has a
7+ * generated message ([ChatChoice.message]) and a finish reason
8+ * ([ChatChoice.finishReason]). For most use cases, you only need the generated
9+ * message.
10+ *
11+ * By default, only 1 [ChatChoice] is generated (since [ChatRequest.n] == 1).
12+ * When you increase `n`, more options are generated. The more options you
13+ * generate, the more tokens you use. In general, it is best to **ONLY**
14+ * generate 1 response, and to let the user regenerate the response.
815 *
916 * @param index The index in the array... 0 if [ChatRequest.n]=1.
1017 * @param message The generated text.
1118 * @param finishReason Why did the bot stop generating tokens?
19+ * @see FinishReason
1220 */
13- class ChatChoice (val index : Int , val message : ChatMessage , val finishReason : String ) {
21+ class ChatChoice (val index : Int , val message : ChatMessage , val finishReason : FinishReason ? ) {
1422
1523 /* *
1624 * JSON constructor for internal use.
1725 */
1826 constructor (json: JsonObject ) : this (
1927 json[" index" ].asInt,
2028 ChatMessage (json[" message" ].asJsonObject),
21- json[" finish_reason" ].toString( )
29+ if ( json[" finish_reason" ].isJsonNull) null else FinishReason .valueOf(json[ " finish_reason " ].asString.uppercase() )
2230 )
2331}
0 commit comments