Package-level declarations

Types

Link copied to clipboard
data class ChatChoice(val index: Int, val message: ChatMessage, val finishReason: FinishReason)

The OpenAI API returns a list of ChatChoice. Each choice has a generated message (ChatChoice.message) and a finish reason (ChatChoice.finishReason). For most use cases, you only need the generated message.

Link copied to clipboard
data class ChatChoiceChunk(val index: Int, var delta: ChatMessageDelta? = null, var finishReason: FinishReason?)

The OpenAI API returns a list of ChatChoiceChunk. The "new content" is saved to the delta property. To access everything that is currently generated, use message.

Link copied to clipboard
data class ChatMessage @JvmOverloads constructor(var role: ChatUser, var content: String?, var toolCalls: List<ToolCall>? = null, var toolCallId: String? = null)

ChatGPT's biggest innovation is its conversation memory. To remember the conversation, we need to map each message to who sent it. This data class wraps a message with the user who sent the message.

Link copied to clipboard
data class ChatRequest
Link copied to clipboard
data class ChatResponse(val id: String, val created: Long, val choices: List<ChatChoice>, val usage: ChatUsage)

The ChatResponse contains all the data returned by the OpenAI Chat API. For most use cases, ChatResponse.get (passing 0 to the index argument) is all you need.

Link copied to clipboard
data class ChatResponseChunk(val id: String, val created: Long, val choices: List<ChatChoiceChunk>)

The ChatResponseChunk contains all the data returned by the OpenAI Chat API. For most use cases, ChatResponseChunk.get (passing 0 to the index argument) is all you need.

Link copied to clipboard
Link copied to clipboard
data class ChatUsage(val promptTokens: Int, val completionTokens: Int, val totalTokens: Int)

Holds how many tokens that were used by your API request. Use these tokens to calculate how much money you have spent on each request.

Link copied to clipboard

ChatGPT's biggest innovation is its conversational memory. To remember the conversation, we need to map each message to who sent it. This enum stores the 3 possible users.

Functions

Link copied to clipboard

Creates a ChatRequest using the ChatRequest.Builder using Kotlin DSL.

Link copied to clipboard