Skip to content

Commit 4063d43

Browse files
committed
fix: code review adjustments
1 parent 8992ab7 commit 4063d43

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

guides/Features.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ var yChat: YChat {
8787

8888
do {
8989
let result = try await yChat.completion()
90+
.setModel(input: "text-davinci-003")
9091
.setInput(input: "Say this is a test.")
9192
.setMaxTokens(tokens: 1024)
92-
.set // you can set more parameters
93+
.setTemperature(temperature: 1.0)
94+
.setTopP(topP: 1.0)
95+
.saveHistory(isSaveHistory: false)
9396
.execute()
9497
} catch {
9598
// catch any error that may occurs on api call.
@@ -105,9 +108,12 @@ val yChat by lazy {
105108

106109
try {
107110
val result = yChat.completion()
111+
.setModel("text-davinci-003")
108112
.setInput("Say this is a test.")
109113
.setMaxTokens(1024)
110-
.set // you can set more parameters
114+
.setTemperature(1.0)
115+
.setTopP(1.0)
116+
.saveHistory(false)
111117
.execute()
112118
} catch (e: exception) {
113119
// catch any error that may occurs on api call.
@@ -127,12 +133,15 @@ var yChat: YChat {
127133

128134
do {
129135
let result = try await yChat.chatCompletions()
136+
.setModel(model: "gpt-3.5-turbo")
130137
.setMaxTokens(tokens: 1024)
138+
.setMaxResults(results: 1)
139+
.setTemperature(temperature: 1.0)
140+
.setTopP(topP: 1.0)
131141
.addMessage(
132142
role: "assistant",
133143
content: "You are a helpful assistant that only answers questions related to fitness"
134144
)
135-
.set // you can set more parameters
136145
.execute(content: "What is the best exercise for building muscle?")
137146
} catch {
138147
// catch any error that may occurs on api call.
@@ -148,12 +157,15 @@ val yChat by lazy {
148157

149158
try {
150159
val result = yChat.chatCompletions()
160+
.setModel("gpt-3.5-turbo")
151161
.setMaxTokens(1024)
162+
.setMaxResults(1)
163+
.setTemperature(1.0)
164+
.setTopP(1.0)
152165
.addMessage(
153166
role = "assistant",
154167
content = "You are a helpful assistant that only answers questions related to fitness"
155168
)
156-
.set // you can set more parameters
157169
.execute("What is the best exercise for building muscle?")
158170
} catch (e: exception) {
159171
// catch any error that may occurs on api call.
@@ -173,9 +185,9 @@ var yChat: YChat {
173185

174186
do {
175187
let result = try await yChat.imageGenerations()
176-
.setResults(results: 2)
188+
.setResults(results: 1)
177189
.setSize(size: "1024x1024")
178-
.set // you can set more parameters
190+
.setResponseFormat(responseFormat: "url")
179191
.execute(prompt: "ocean")
180192
} catch {
181193
// catch any error that may occurs on api call.
@@ -191,9 +203,9 @@ val yChat by lazy {
191203

192204
try {
193205
val result = yChat.imageGenerations()
194-
.setResults(2)
206+
.setResults(1)
195207
.setSize("1024x1024")
196-
.set // you can set more parameters
208+
.setResponseFormat("url")
197209
.execute("ocean")
198210
} catch (e: exception) {
199211
// catch any error that may occurs on api call.
@@ -215,7 +227,9 @@ do {
215227
let result = try await yChat.edits()
216228
.setInput(input: "What day of the wek is it?")
217229
.setResults(result: 1)
218-
.set // you can set more parameters
230+
.setModel(model: "text-davinci-edit-001")
231+
.setTemperature(temperature: 1.0)
232+
.setTopP(topP: 1.0)
219233
.execute(instruction: "Fix the spelling mistakes")
220234
} catch {
221235
// catch any error that may occurs on api call.
@@ -233,7 +247,9 @@ try {
233247
val result = yChat.edits()
234248
.setInput("What day of the wek is it?")
235249
.setResults(1)
236-
.set // you can set more parameters
250+
.setModel("text-davinci-edit-001")
251+
.setTemperature(1.0)
252+
.setTopP(1.0)
237253
.execute("Fix the spelling mistakes")
238254
} catch (e: exception) {
239255
// catch any error that may occurs on api call.
@@ -260,9 +276,11 @@ let audioData = try! Data(contentsOf: audioFileUrl)
260276

261277
do {
262278
let result = try await yChat.audioTranscriptions()
263-
.setTemperature(temperature: 0.4)
279+
.setModel(model: "whisper-1")
280+
.setPrompt(prompt: "")
264281
.setResponseFormat(format: "json")
265-
.set // you can set more parameters
282+
.setTemperature(temperature: 0.4)
283+
.setLanguage(language: "en")
266284
.execute(filename: "audio.m4a", audioFile: audioData)
267285
} catch {
268286
// catch any error that may occurs on api call.
@@ -281,9 +299,11 @@ val byteArray = inputStream.readBytes()
281299

282300
try {
283301
val result = yChat.audioTranscriptions()
284-
.setTemperature(0.4)
302+
.setModel("whisper-1")
303+
.setPrompt("")
285304
.setResponseFormat("json")
286-
.set // you can set more parameters
305+
.setTemperature(0.4)
306+
.setLanguage("en")
287307
.execute("audio.m4a", byteArray)
288308
} catch (e: exception) {
289309
// catch any error that may occurs on api call.

sample/jvm/src/main/java/co/yml/ychat/jvm/services/YChatService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public AIModel getModel(String id) throws Exception {
6969

7070
public String getAudioTranscription(MultipartFile multipartFile) throws Exception {
7171
final CompletableFuture<String> future = new CompletableFuture<>();
72-
String filename = Optional.ofNullable(multipartFile.getOriginalFilename()).orElse("");
72+
String filename = Optional.ofNullable(multipartFile.getOriginalFilename())
73+
.orElseThrow(() -> new IllegalStateException("Filename not found"));
7374
byte[] bytes = multipartFile.getBytes();
7475
ychat.audioTranscriptions().execute(filename, bytes, new CompletionCallbackResult<>(future));
7576
return future.get();

ychat/src/commonMain/kotlin/co/yml/ychat/data/api/impl/ChatGptApiImpl.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,61 @@ internal class ChatGptApiImpl(private val apiExecutor: ApiExecutor) : ChatGptApi
2222

2323
override suspend fun completion(paramsDto: CompletionParamsDto): ApiResult<CompletionDto> {
2424
return apiExecutor
25-
.setEndpoint("v1/completions")
25+
.setEndpoint("$VERSION/completions")
2626
.setHttpMethod(HttpMethod.Post)
2727
.setBody(paramsDto)
2828
.execute()
2929
}
3030

3131
override suspend fun chatCompletions(paramsDto: ChatCompletionParamsDto): ApiResult<ChatCompletionsDto> {
3232
return apiExecutor
33-
.setEndpoint("v1/chat/completions")
33+
.setEndpoint("$VERSION/chat/completions")
3434
.setHttpMethod(HttpMethod.Post)
3535
.setBody(paramsDto)
3636
.execute()
3737
}
3838

3939
override suspend fun imageGenerations(paramsDto: ImageGenerationsParamsDto): ApiResult<ImageGenerationsDto> {
4040
return apiExecutor
41-
.setEndpoint("v1/images/generations")
41+
.setEndpoint("$VERSION/images/generations")
4242
.setHttpMethod(HttpMethod.Post)
4343
.setBody(paramsDto)
4444
.execute()
4545
}
4646

4747
override suspend fun edits(paramsDto: EditsParamsDto): ApiResult<EditsDto> {
4848
return apiExecutor
49-
.setEndpoint("v1/edits")
49+
.setEndpoint("$VERSION/edits")
5050
.setHttpMethod(HttpMethod.Post)
5151
.setBody(paramsDto)
5252
.execute()
5353
}
5454

5555
override suspend fun models(): ApiResult<ModelListDto> {
5656
return apiExecutor
57-
.setEndpoint("v1/models")
57+
.setEndpoint("$VERSION/models")
5858
.setHttpMethod(HttpMethod.Get)
5959
.execute()
6060
}
6161

6262
override suspend fun model(id: String): ApiResult<ModelDto> {
6363
return apiExecutor
64-
.setEndpoint("v1/models/$id")
64+
.setEndpoint("$VERSION/models/$id")
6565
.setHttpMethod(HttpMethod.Get)
6666
.execute()
6767
}
6868

6969
override suspend fun audioTranscriptions(audioParamsDto: AudioParamsDto): ApiResult<AudioResultDto> {
7070
val byteArray = audioParamsDto.byteArray.toByteArray()
7171
val apiBuilder = apiExecutor
72-
.setEndpoint("v1/audio/transcriptions")
72+
.setEndpoint("$VERSION/audio/transcriptions")
7373
.setHttpMethod(HttpMethod.Post)
7474
.addFormPart("file", audioParamsDto.filename, byteArray)
7575
audioParamsDto.getMap().forEach { apiBuilder.addFormPart(it.key, it.value) }
7676
return apiBuilder.execute()
7777
}
78+
79+
companion object {
80+
private const val VERSION = "v1"
81+
}
7882
}

0 commit comments

Comments
 (0)