Skip to content

Commit 11800a3

Browse files
authored
feat: add RequestOptions (#296)
1 parent ccc6e83 commit 11800a3

File tree

29 files changed

+559
-140
lines changed

29 files changed

+559
-140
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased
2+
3+
### Added
4+
- add `RequestOptions` (#296)
5+
16
## 3.6.3
27
> Published 13 Jan 2024
38

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kotlin.js.compiler=ir
55

66
# Lib
77
GROUP=com.aallam.openai
8-
VERSION_NAME=3.6.3
8+
VERSION_NAME=3.7.0-SNAPSHOT
99

1010
# OSS
1111
SONATYPE_HOST=DEFAULT

openai-client/src/commonMain/kotlin/com.aallam.openai.client/Assistants.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.aallam.openai.api.assistant.Assistant
55
import com.aallam.openai.api.assistant.AssistantFile
66
import com.aallam.openai.api.assistant.AssistantId
77
import com.aallam.openai.api.assistant.AssistantRequest
8+
import com.aallam.openai.api.core.RequestOptions
89
import com.aallam.openai.api.core.SortOrder
910
import com.aallam.openai.api.file.FileId
1011

@@ -20,31 +21,35 @@ public interface Assistants {
2021
* @param request the request to create an assistant.
2122
*/
2223
@BetaOpenAI
23-
public suspend fun assistant(request: AssistantRequest): Assistant
24+
public suspend fun assistant(request: AssistantRequest, requestOptions: RequestOptions? = null): Assistant
2425

2526
/**
2627
* Retrieves an assistant.
2728
*
2829
* @param id the ID of the assistant to retrieve.
2930
*/
3031
@BetaOpenAI
31-
public suspend fun assistant(id: AssistantId): Assistant?
32+
public suspend fun assistant(id: AssistantId, requestOptions: RequestOptions? = null): Assistant?
3233

3334
/**
3435
* Update an assistant.
3536
*
3637
* @param id rhe ID of the assistant to modify.
3738
*/
3839
@BetaOpenAI
39-
public suspend fun assistant(id: AssistantId, request: AssistantRequest): Assistant
40+
public suspend fun assistant(
41+
id: AssistantId,
42+
request: AssistantRequest,
43+
requestOptions: RequestOptions? = null
44+
): Assistant
4045

4146
/**
4247
* Delete an assistant.
4348
*
4449
* @param id ID of the assistant to delete.
4550
*/
4651
@BetaOpenAI
47-
public suspend fun delete(id: AssistantId): Boolean
52+
public suspend fun delete(id: AssistantId, requestOptions: RequestOptions? = null): Boolean
4853

4954
/**
5055
* Returns a list of assistants.
@@ -65,6 +70,7 @@ public interface Assistants {
6570
order: SortOrder? = null,
6671
after: AssistantId? = null,
6772
before: AssistantId? = null,
73+
requestOptions: RequestOptions? = null
6874
): List<Assistant>
6975

7076
/**
@@ -75,7 +81,11 @@ public interface Assistants {
7581
* Useful for tools like retrieval and code interpreter that can access files.
7682
*/
7783
@BetaOpenAI
78-
public suspend fun createFile(assistantId: AssistantId, fileId: FileId): AssistantFile
84+
public suspend fun createFile(
85+
assistantId: AssistantId,
86+
fileId: FileId,
87+
requestOptions: RequestOptions? = null
88+
): AssistantFile
7989

8090
/**
8191
* Retrieves an [AssistantFile].
@@ -84,16 +94,21 @@ public interface Assistants {
8494
* @param fileId the ID of the file we're getting.
8595
*/
8696
@BetaOpenAI
87-
public suspend fun file(assistantId: AssistantId, fileId: FileId): AssistantFile
97+
public suspend fun file(
98+
assistantId: AssistantId,
99+
fileId: FileId,
100+
requestOptions: RequestOptions? = null
101+
): AssistantFile
88102

89103
/**
90104
* Delete an assistant file.
91105
*
92106
* @param assistantId the ID of the assistant that the file belongs to.
93107
* @param fileId the ID of the file to delete.
108+
* @param requestOptions request options.
94109
*/
95110
@BetaOpenAI
96-
public suspend fun delete(assistantId: AssistantId, fileId: FileId): Boolean
111+
public suspend fun delete(assistantId: AssistantId, fileId: FileId, requestOptions: RequestOptions? = null): Boolean
97112

98113
/**
99114
* Returns a list of assistant files.
@@ -108,6 +123,7 @@ public interface Assistants {
108123
* @param before a cursor for use in pagination. Before is an object ID that defines your place in the list.
109124
* For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can
110125
* include `before = FileId("obj_foo")` in order to fetch the previous page of the list.
126+
* @param requestOptions request options.
111127
*/
112128
@BetaOpenAI
113129
public suspend fun files(
@@ -116,5 +132,6 @@ public interface Assistants {
116132
order: SortOrder? = null,
117133
after: FileId? = null,
118134
before: FileId? = null,
135+
requestOptions: RequestOptions? = null
119136
): List<AssistantFile>
120137
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.aallam.openai.client
22

33
import com.aallam.openai.api.audio.*
4+
import com.aallam.openai.api.core.RequestOptions
45

56
/**
67
* Learn how to turn audio into text.
@@ -9,16 +10,28 @@ public interface Audio {
910

1011
/**
1112
* Transcribes audio into the input language.
13+
*
14+
* @param request transcription request.
15+
* @param requestOptions request options.
1216
*/
13-
public suspend fun transcription(request: TranscriptionRequest): Transcription
17+
public suspend fun transcription(
18+
request: TranscriptionRequest,
19+
requestOptions: RequestOptions? = null
20+
): Transcription
1421

1522
/**
1623
* Translates audio into English.
24+
*
25+
* @param request translation request.
26+
* @param requestOptions request options.
1727
*/
18-
public suspend fun translation(request: TranslationRequest): Translation
28+
public suspend fun translation(request: TranslationRequest, requestOptions: RequestOptions? = null): Translation
1929

2030
/**
2131
* Generates audio from the input text.
32+
*
33+
* @param request speech request.
34+
* @param requestOptions request options.
2235
*/
23-
public suspend fun speech(request: SpeechRequest): ByteArray
36+
public suspend fun speech(request: SpeechRequest, requestOptions: RequestOptions? = null): ByteArray
2437
}

openai-client/src/commonMain/kotlin/com.aallam.openai.client/Chat.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.aallam.openai.client
33
import com.aallam.openai.api.chat.ChatCompletion
44
import com.aallam.openai.api.chat.ChatCompletionChunk
55
import com.aallam.openai.api.chat.ChatCompletionRequest
6+
import com.aallam.openai.api.core.RequestOptions
67
import kotlinx.coroutines.flow.Flow
78

89
/**
@@ -12,11 +13,23 @@ public interface Chat {
1213

1314
/**
1415
* Creates a completion for the chat message.
16+
*
17+
* @param request completion request.
18+
* @param requestOptions request options.
1519
*/
16-
public suspend fun chatCompletion(request: ChatCompletionRequest): ChatCompletion
20+
public suspend fun chatCompletion(
21+
request: ChatCompletionRequest,
22+
requestOptions: RequestOptions? = null
23+
): ChatCompletion
1724

1825
/**
1926
* Stream variant of [chatCompletion].
27+
*
28+
* @param request completion request.
29+
* @param requestOptions request options.
2030
*/
21-
public fun chatCompletions(request: ChatCompletionRequest): Flow<ChatCompletionChunk>
31+
public fun chatCompletions(
32+
request: ChatCompletionRequest,
33+
requestOptions: RequestOptions? = null
34+
): Flow<ChatCompletionChunk>
2235
}

openai-client/src/commonMain/kotlin/com.aallam.openai.client/Embeddings.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.aallam.openai.client
22

3+
import com.aallam.openai.api.core.RequestOptions
34
import com.aallam.openai.api.embedding.EmbeddingRequest
45
import com.aallam.openai.api.embedding.EmbeddingResponse
56

@@ -10,6 +11,9 @@ public interface Embeddings {
1011

1112
/**
1213
* Creates an embedding vector representing the input text.
14+
*
15+
* @param request embedding request.
16+
* @param requestOptions request options.
1317
*/
14-
public suspend fun embeddings(request: EmbeddingRequest): EmbeddingResponse
18+
public suspend fun embeddings(request: EmbeddingRequest, requestOptions: RequestOptions? = null): EmbeddingResponse
1519
}
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.aallam.openai.client
22

3+
import com.aallam.openai.api.core.RequestOptions
34
import com.aallam.openai.api.file.File
4-
import com.aallam.openai.api.file.FileUpload
55
import com.aallam.openai.api.file.FileId
6+
import com.aallam.openai.api.file.FileUpload
67

78
/**
89
* Files are used to upload documents that can be used across features like [Answers], [Searches], and [Classifications]
@@ -12,26 +13,40 @@ public interface Files {
1213
/**
1314
* Upload a file that contains document(s) to be used across various endpoints/features.
1415
* Currently, the size of all the files uploaded by one organization can be up to 1 GB.
16+
*
17+
* @param request file upload request.
18+
* @param requestOptions request options.
1519
*/
16-
public suspend fun file(request: FileUpload): File
20+
public suspend fun file(request: FileUpload, requestOptions: RequestOptions? = null): File
1721

1822
/**
1923
* Returns a list of files that belong to the user's organization.
24+
*
25+
* @param requestOptions request options.
2026
*/
21-
public suspend fun files(): List<File>
27+
public suspend fun files(requestOptions: RequestOptions? = null): List<File>
2228

2329
/**
2430
* Returns information about a specific file.
31+
*
32+
* @param fileId the ID of the file to retrieve.
33+
* @param requestOptions request options.
2534
*/
26-
public suspend fun file(fileId: FileId): File?
35+
public suspend fun file(fileId: FileId, requestOptions: RequestOptions? = null): File?
2736

2837
/**
2938
* Delete a file. Only owners of organizations can delete files currently.
39+
*
40+
* @param fileId the ID of the file to delete.
41+
* @param requestOptions request options.
3042
*/
31-
public suspend fun delete(fileId: FileId): Boolean
43+
public suspend fun delete(fileId: FileId, requestOptions: RequestOptions? = null): Boolean
3244

3345
/**
3446
* Returns the contents of the specified [fileId].
47+
*
48+
* @param fileId the ID of the file to download.
49+
* @param requestOptions request options.
3550
*/
36-
public suspend fun download(fileId: FileId): ByteArray
51+
public suspend fun download(fileId: FileId, requestOptions: RequestOptions? = null): ByteArray
3752
}
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.aallam.openai.client
22

33
import com.aallam.openai.api.core.PaginatedList
4-
import com.aallam.openai.api.finetuning.*
4+
import com.aallam.openai.api.core.RequestOptions
5+
import com.aallam.openai.api.finetuning.FineTuningId
6+
import com.aallam.openai.api.finetuning.FineTuningJob
7+
import com.aallam.openai.api.finetuning.FineTuningJobEvent
8+
import com.aallam.openai.api.finetuning.FineTuningRequest
59

610
/**
711
* Manage fine-tuning jobs to tailor a model to your specific training data.
@@ -11,42 +15,53 @@ public interface FineTuning {
1115
/**
1216
* Creates a job that fine-tunes a specified model from a given dataset.
1317
*
14-
* Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
18+
* The response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
19+
*
20+
* @param request fine-tuning request.
21+
* @param requestOptions request options.
1522
*/
16-
public suspend fun fineTuningJob(request: FineTuningRequest): FineTuningJob
23+
public suspend fun fineTuningJob(request: FineTuningRequest, requestOptions: RequestOptions? = null): FineTuningJob
1724

1825
/**
1926
* List your organization's fine-tuning jobs.
2027
*
2128
* @param after Identifier for the last job from the previous pagination request.
2229
* @param limit Number of fine-tuning jobs to retrieve.
30+
* @param requestOptions request options.
2331
*/
24-
public suspend fun fineTuningJobs(after: String? = null, limit: Int? = null): List<FineTuningJob>
32+
public suspend fun fineTuningJobs(
33+
after: String? = null,
34+
limit: Int? = null,
35+
requestOptions: RequestOptions? = null
36+
): List<FineTuningJob>
2537

2638
/**
2739
* Get info about a fine-tuning job.
2840
*
2941
* @param id The ID of the fine-tuning job.
42+
* @param requestOptions request options.
3043
*/
31-
public suspend fun fineTuningJob(id: FineTuningId): FineTuningJob?
44+
public suspend fun fineTuningJob(id: FineTuningId, requestOptions: RequestOptions? = null): FineTuningJob?
3245

3346
/**
3447
* Immediately cancel a fine-tune job.
3548
*
3649
* @param id The ID of the fine-tuning job to cancel.
50+
* @param requestOptions request options.
3751
*/
38-
public suspend fun cancel(id: FineTuningId): FineTuningJob?
52+
public suspend fun cancel(id: FineTuningId, requestOptions: RequestOptions? = null): FineTuningJob?
3953

4054
/**
4155
* Get status updates for a fine-tuning job.
4256
*
4357
* @param id The ID of the fine-tuning job to get events for.
4458
* @param after Identifier for the last event from the previous pagination request.
4559
* @param limit Number of events to retrieve.
60+
* @param requestOptions request options.
4661
*/
4762
public suspend fun fineTuningEvents(
4863
id: FineTuningId,
4964
after: String? = null,
50-
limit: Int? = null
65+
limit: Int? = null, requestOptions: RequestOptions? = null
5166
): PaginatedList<FineTuningJobEvent>
5267
}

0 commit comments

Comments
 (0)