Skip to content

Commit cf8244d

Browse files
feat(client): add close method (#164)
1 parent 4fcd0fc commit cf8244d

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,17 @@ interface OpenAIClient {
3939
fun batches(): BatchService
4040

4141
fun uploads(): UploadService
42+
43+
/**
44+
* Closes this client, relinquishing any underlying resources.
45+
*
46+
* This is purposefully not inherited from [AutoCloseable] because the client is long-lived and
47+
* usually should not be synchronously closed via try-with-resources.
48+
*
49+
* It's also usually not necessary to call this method at all. the default HTTP client
50+
* automatically releases threads and connections if they remain idle, but if you are writing an
51+
* application that needs to aggressively release unused resources, then you may call this
52+
* method.
53+
*/
54+
fun close()
4255
}

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,17 @@ interface OpenAIClientAsync {
3939
fun batches(): BatchServiceAsync
4040

4141
fun uploads(): UploadServiceAsync
42+
43+
/**
44+
* Closes this client, relinquishing any underlying resources.
45+
*
46+
* This is purposefully not inherited from [AutoCloseable] because the client is long-lived and
47+
* usually should not be synchronously closed via try-with-resources.
48+
*
49+
* It's also usually not necessary to call this method at all. the default HTTP client
50+
* automatically releases threads and connections if they remain idle, but if you are writing an
51+
* application that needs to aggressively release unused resources, then you may call this
52+
* method.
53+
*/
54+
fun close()
4255
}

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ constructor(
104104
override fun batches(): BatchServiceAsync = batches
105105

106106
override fun uploads(): UploadServiceAsync = uploads
107+
108+
override fun close() = clientOptions.httpClient.close()
107109
}

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ constructor(
9696
override fun batches(): BatchService = batches
9797

9898
override fun uploads(): UploadService = uploads
99+
100+
override fun close() = clientOptions.httpClient.close()
99101
}

0 commit comments

Comments
 (0)