Skip to content

Commit f13af6d

Browse files
committed
fix list responses not being nullable for empty lists
1 parent a1b3c86 commit f13af6d

File tree

9 files changed

+70
-24
lines changed

9 files changed

+70
-24
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
22

33
group = "com.cjcrafter"
4-
version = "2.0.2"
4+
version = "2.0.2-SNAPSHOT"
55

66
plugins {
77
`java-library`

examples/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.3")
1515
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
1616

17-
implementation("ch.qos.logback:logback-classic:1.4.11")
17+
implementation("ch.qos.logback:logback-classic:1.4.12")
1818

1919
// https://mvnrepository.com/artifact/org.mariuszgromada.math/MathParser.org-mXparser
2020
// Used for tool tests

src/main/kotlin/com/cjcrafter/openai/assistants/ListAssistantResponse.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@ package com.cjcrafter.openai.assistants
22

33
import com.fasterxml.jackson.annotation.JsonProperty
44

5+
/**
6+
* A data class which represents a response from the OpenAI API containing a list of [Assistant]s.
7+
*
8+
* When the list is empty, [firstId] and [lastId] will be `null`.
9+
*
10+
* @property data The list of assistants
11+
* @property firstId The ID of the first [Assistant] in the list, or null
12+
* @property lastId The ID of the last [Assistant] in the list, or null
13+
* @property hasMore Whether there are more [Assistant]s to retrieve from the API
14+
*/
515
data class ListAssistantResponse(
616
@JsonProperty(required = true) val data: List<Assistant>,
7-
@JsonProperty("first_id", required = true) val firstId: String,
8-
@JsonProperty("last_id", required = true) val lastId: String,
17+
@JsonProperty("first_id") val firstId: String?,
18+
@JsonProperty("last_id") val lastId: String?,
919
@JsonProperty("has_more", required = true) val hasMore: Boolean,
1020
)

src/main/kotlin/com/cjcrafter/openai/files/ListFilesResponse.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
66
* Represents a response from the [list files](https://platform.openai.com/docs/api-reference/files)
77
* endpoint.
88
*
9+
* @property hasMore Whether there are more files to retrieve from the API.
910
* @property data The list of files.
1011
*/
1112
data class ListFilesResponse(

src/main/kotlin/com/cjcrafter/openai/threads/message/ListMessageFilesResponse.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import com.fasterxml.jackson.annotation.JsonProperty
55
/**
66
* A data class which represents a response from the OpenAI API containing a list of [MessageFile]s.
77
*
8+
* When the list is empty, [firstId] and [lastId] will be `null`.
9+
*
810
* @property data The list of [MessageFile]s
9-
* @property firstId The ID of the first [MessageFile] in the list
10-
* @property lastId The ID of the last [MessageFile] in the list
11+
* @property firstId The ID of the first [MessageFile] in the list, or null
12+
* @property lastId The ID of the last [MessageFile] in the list, or null
1113
* @property hasMore Whether there are more [MessageFile]s to retrieve from the API
1214
*/
1315
data class ListMessageFilesResponse(
1416
@JsonProperty(required = true) val data: List<MessageFile>,
15-
@JsonProperty("first_id", required = true) val firstId: String,
16-
@JsonProperty("last_id", required = true) val lastId: String,
17+
@JsonProperty("first_id") val firstId: String?,
18+
@JsonProperty("last_id") val lastId: String?,
1719
@JsonProperty("has_more", required = true) val hasMore: Boolean,
1820
)
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.cjcrafter.openai.threads.message
22

3-
import com.cjcrafter.openai.threads.Thread
43
import com.fasterxml.jackson.annotation.JsonProperty
54

65
/**
7-
* Represents a response from the [ListThreadMessagesRequest]. This contains a
8-
* list of [ThreadMessage]s. If you are trying to get **every** message in a
9-
* [Thread], you might need to make multiple requests.
6+
* A data class which represents a response from the OpenAI API containing a list of [ThreadMessage]s.
7+
*
8+
* If the list is empty, [firstId] and [lastId] will be `null`.
109
*
1110
* @property data The list of thread messages
12-
* @property firstId The id of the first message in the list
13-
* @property lastId The id of the last message in the list
11+
* @property firstId The id of the first message in the list, or null
12+
* @property lastId The id of the last message in the list, or null
1413
* @property hasMore Whether there are more messages to retrieve
1514
*/
1615
data class ListThreadMessagesResponse(
1716
@JsonProperty(required = true) val data: List<ThreadMessage>,
18-
@JsonProperty("first_id", required = true) val firstId: String,
19-
@JsonProperty("last_id", required = true) val lastId: String,
17+
@JsonProperty("first_id") val firstId: String?,
18+
@JsonProperty("last_id") val lastId: String?,
2019
@JsonProperty("has_more", required = true) val hasMore: Boolean,
2120
)

src/main/kotlin/com/cjcrafter/openai/threads/runs/CreateRunRequest.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,51 @@ data class CreateRunRequest(
2222
var metadata: Map<String, String>? = null,
2323
) {
2424

25+
/**
26+
* Builder for [CreateRunRequest].
27+
*/
2528
@OpenAIDslMarker
2629
class Builder internal constructor() {
30+
2731
private var assistantId: String? = null
2832
private var model: String? = null
2933
private var instructions: String? = null
3034
private var tools: MutableList<Tool>? = null
3135
private var metadata: MutableMap<String, String>? = null
3236

37+
/**
38+
* Sets the assistant to use for the run. Shorthand for [assistantId].
39+
*/
3340
fun assistant(assistant: Assistant) = apply { this.assistantId = assistant.id }
41+
42+
/**
43+
* Sets the assistant to use for the run.
44+
*/
3445
fun assistantId(assistantId: String) = apply { this.assistantId = assistantId }
46+
47+
/**
48+
* Sets the model to override the assistant's default model.
49+
*/
3550
fun model(model: String) = apply { this.model = model }
51+
52+
/**
53+
* Sets the instructions to override the assistant's default instructions.
54+
*/
3655
fun instructions(instructions: String) = apply { this.instructions = instructions }
56+
57+
/**
58+
* Sets the tools to override the assistant's default tools.
59+
*/
3760
fun tools(tools: MutableList<Tool>) = apply { this.tools = tools }
61+
62+
/**
63+
* Sets the metadata to attach to the [Run].
64+
*/
3865
fun metadata(metadata: MutableMap<String, String>) = apply { this.metadata = metadata }
3966

67+
/**
68+
* Builds the [CreateRunRequest].
69+
*/
4070
fun build() = CreateRunRequest(
4171
assistantId = assistantId ?: throw IllegalStateException("assistantId must be set"),
4272
model = model,

src/main/kotlin/com/cjcrafter/openai/threads/runs/ListRunStepsResponse.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import com.fasterxml.jackson.annotation.JsonProperty
55
/**
66
* A data class which represents a response from the OpenAI API containing a list of [RunStep]s.
77
*
8+
* When the list is empty, [firstId] and [lastId] will be `null`.
9+
*
810
* @property data The list of [RunStep]s
9-
* @property firstId The ID of the first [RunStep] in the list
10-
* @property lastId The ID of the last [RunStep] in the list
11+
* @property firstId The ID of the first [RunStep] in the list, or null
12+
* @property lastId The ID of the last [RunStep] in the list, or null
1113
* @property hasMore Whether there are more [RunStep]s to retrieve from the API
1214
*/
1315
data class ListRunStepsResponse(
1416
@JsonProperty(required = true) val data: List<RunStep>,
15-
@JsonProperty("first_id", required = true) val firstId: String,
16-
@JsonProperty("last_id", required = true) val lastId: String,
17+
@JsonProperty("first_id") val firstId: String?,
18+
@JsonProperty("last_id") val lastId: String?,
1719
@JsonProperty("has_more", required = true) val hasMore: Boolean,
1820
)

src/main/kotlin/com/cjcrafter/openai/threads/runs/ListRunsResponse.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import com.fasterxml.jackson.annotation.JsonProperty
55
/**
66
* A data class which represents a response from the OpenAI API containing a list of [Run]s.
77
*
8+
* When the list is empty, [firstId] and [lastId] will be `null`.
9+
*
810
* @property data The list of [Run]s
9-
* @property firstId The ID of the first [Run] in the list
10-
* @property lastId The ID of the last [Run] in the list
11+
* @property firstId The ID of the first [Run] in the list, or null
12+
* @property lastId The ID of the last [Run] in the list, or null
1113
* @property hasMore Whether there are more [Run]s to retrieve from the API
1214
*/
1315
data class ListRunsResponse(
1416
@JsonProperty(required = true) val data: List<Run>,
15-
@JsonProperty("first_id", required = true) val firstId: String,
16-
@JsonProperty("last_id", required = true) val lastId: String,
17+
@JsonProperty("first_id") val firstId: String?,
18+
@JsonProperty("last_id") val lastId: String?,
1719
@JsonProperty("has_more", required = true) val hasMore: Boolean,
1820
)

0 commit comments

Comments
 (0)