-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chat): add stream options (#363)
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
# Unreleased | ||
|
||
### Added | ||
- **chat**: add stream options (#363) | ||
|
||
# 3.8.1 | ||
> Published 28 Jun 2024 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/StreamOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.aallam.openai.api.chat | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Options for streaming response. | ||
*/ | ||
@Serializable | ||
public data class StreamOptions( | ||
/** | ||
* If set, an additional chunk will be streamed before the data: `[DONE]` message. | ||
* The usage field on this chunk shows the token usage statistics for the entire request, and the choices field will | ||
* always be an empty array. All other chunks will also include a usage field, but with a null value. | ||
*/ | ||
@SerialName("include_usage") public val includeUsage: Boolean? = null, | ||
) | ||
|
||
/** | ||
* Create a new [StreamOptions] instance. | ||
*/ | ||
public fun streamOptions(block: StreamOptionsBuilder.() -> Unit): StreamOptions { | ||
return StreamOptionsBuilder().apply(block).build() | ||
} | ||
|
||
/** | ||
* Builder for [StreamOptions]. | ||
*/ | ||
public class StreamOptionsBuilder { | ||
|
||
/** | ||
* If set, an additional chunk will be streamed before the data: `[DONE]` message. | ||
* The usage field on this chunk shows the token usage statistics for the entire request, and the choices field will | ||
* always be an empty array. All other chunks will also include a usage field, but with a null value. | ||
*/ | ||
public var includeUsage: Boolean? = null | ||
|
||
/** | ||
* Build the [StreamOptions] instance. | ||
*/ | ||
public fun build(): StreamOptions = StreamOptions( | ||
includeUsage = includeUsage, | ||
) | ||
} |