Skip to content

Commit ca72906

Browse files
committed
fix: Code review adjustments
1 parent 8d8e54c commit ca72906

File tree

6 files changed

+133
-35
lines changed

6 files changed

+133
-35
lines changed

ychat/src/commonMain/kotlin/co/yml/ychat/domain/usecases/ChatCompletionsUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import co.yml.ychat.domain.mapper.toChatMessages
66
import co.yml.ychat.domain.model.ChatCompletionsParams
77
import co.yml.ychat.domain.model.ChatMessage
88

9-
internal data class ChatCompletionsUseCase(private val chatGptApi: ChatGptApi) {
9+
internal class ChatCompletionsUseCase(private val chatGptApi: ChatGptApi) {
1010

1111
suspend fun requestChatCompletions(params: ChatCompletionsParams): List<ChatMessage> {
1212
val requestDto = params.toChatCompletionParamsDto()

ychat/src/commonMain/kotlin/co/yml/ychat/domain/usecases/EditsUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import co.yml.ychat.domain.mapper.toEditsModel
55
import co.yml.ychat.domain.mapper.toEditsParamsDto
66
import co.yml.ychat.domain.model.EditsParams
77

8-
internal data class EditsUseCase(private val chatGptApi: ChatGptApi) {
8+
internal class EditsUseCase(private val chatGptApi: ChatGptApi) {
99

1010
suspend fun requestEdits(params: EditsParams): List<String> {
1111
val requestDto = params.toEditsParamsDto()

ychat/src/commonMain/kotlin/co/yml/ychat/domain/usecases/ImageGenerationsUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import co.yml.ychat.domain.mapper.toImageGenerated
55
import co.yml.ychat.domain.mapper.toImageGenerationsParamsDto
66
import co.yml.ychat.domain.model.ImageGenerationsParams
77

8-
internal data class ImageGenerationsUseCase(private val chatGptApi: ChatGptApi) {
8+
internal class ImageGenerationsUseCase(private val chatGptApi: ChatGptApi) {
99

1010
suspend fun requestImageGenerations(params: ImageGenerationsParams): List<String> {
1111
val requestDto = params.toImageGenerationsParamsDto()

ychat/src/commonMain/kotlin/co/yml/ychat/domain/usecases/ListModelsUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import co.yml.ychat.data.api.ChatGptApi
44
import co.yml.ychat.domain.mapper.toModel
55
import co.yml.ychat.domain.model.AIModel
66

7-
internal data class ListModelsUseCase(private val chatGptApi: ChatGptApi) {
7+
internal class ListModelsUseCase(private val chatGptApi: ChatGptApi) {
88

99
suspend fun getListModels(): List<AIModel> {
1010
val response = chatGptApi.models()

ychat/src/commonMain/kotlin/co/yml/ychat/domain/usecases/RetrieveModelUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import co.yml.ychat.data.api.ChatGptApi
44
import co.yml.ychat.domain.mapper.toModel
55
import co.yml.ychat.domain.model.AIModel
66

7-
internal data class RetrieveModelUseCase(private val chatGptApi: ChatGptApi) {
7+
internal class RetrieveModelUseCase(private val chatGptApi: ChatGptApi) {
88

99
suspend fun getModel(id: String): AIModel {
1010
val response = chatGptApi.model(id)

ychat/src/commonTest/kotlin/infrastructure/MockStorage.kt

Lines changed: 128 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,137 @@ package infrastructure
22

33
object MockStorage {
44

5-
fun completionSuccessResult(text: String) = "{\"id\":\"1\",\"object\":\"text_completion\"," +
6-
"\"created\":1675532539,\"model\":\"text-davinci-003\"," +
7-
"\"choices\":[{\"text\":\"\n\n$text\",\"index\":0,\"logprobs\":null," +
8-
"\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":8,\"completion_tokens\":9," +
9-
"\"total_tokens\":17}}"
5+
fun completionSuccessResult(text: String) = """
6+
{
7+
"id": "1",
8+
"object": "text_completion",
9+
"created": 1675532539,
10+
"model": "text-davinci-003",
11+
"choices": [
12+
{
13+
"text": "\n\n$text",
14+
"index": 0,
15+
"logprobs": null,
16+
"finish_reason": "stop"
17+
}
18+
],
19+
"usage": {
20+
"prompt_tokens": 8,
21+
"completion_tokens": 9,
22+
"total_tokens": 17
23+
}
24+
}
25+
"""
1026

11-
fun chatCompletionsSuccessResult(text: String) = "{\"id\":\"1\",\"object\":\"chat.completion\"," +
12-
"\"created\":1678144798,\"model\":\"gpt-3.5-turbo-0301\"," +
13-
"\"usage\":{\"prompt_tokens\":13,\"completion_tokens\":12,\"total_tokens\":25}," +
14-
"\"choices\":[{\"message\":{\"role\":\"assistant\",\"content\":\"$text\"}," +
15-
"\"finish_reason\":\"stop\",\"index\":0}]}"
27+
fun chatCompletionsSuccessResult(text: String) = """
28+
{
29+
"id": "1",
30+
"object": "chat.completion",
31+
"created": 1678144798,
32+
"model": "gpt-3.5-turbo-0301",
33+
"usage": {
34+
"prompt_tokens": 13,
35+
"completion_tokens": 12,
36+
"total_tokens": 25
37+
},
38+
"choices": [
39+
{
40+
"message": {
41+
"role": "assistant",
42+
"content": "$text"
43+
},
44+
"finish_reason": "stop",
45+
"index": 0
46+
}
47+
]
48+
}
49+
"""
1650

17-
fun imageGenerationsSuccessResult(text: String) =
18-
"{\"created\":1678805561,\"data\":[{\"url\":\"$text\"}]}"
51+
fun imageGenerationsSuccessResult(text: String) = """
52+
{
53+
"created": 1678805561,
54+
"data": [
55+
{
56+
"url": "$text"
57+
}
58+
]
59+
}
60+
"""
1961

20-
fun editsSuccessResult(text: String) = "{\"object\":\"edit\",\"created\":1679072839," +
21-
"\"choices\":[{\"text\":\"$text\",\"index\":0}]," +
22-
"\"usage\":{\"prompt_tokens\":25,\"completion_tokens\":28,\"total_tokens\":53}}"
62+
fun editsSuccessResult(text: String) = """
63+
{
64+
"object": "edit",
65+
"created": 1679072839,
66+
"choices": [
67+
{
68+
"text": "$text",
69+
"index": 0
70+
}
71+
],
72+
"usage": {
73+
"prompt_tokens": 25,
74+
"completion_tokens": 28,
75+
"total_tokens": 53
76+
}
77+
}
78+
"""
2379

24-
fun listModelsSuccessResult(id: String) =
25-
"{\"object\":\"list\",\"data\":[{\"id\":\"$id\",\"object\":\"model\"," +
26-
"\"created\":1649358449,\"owned_by\":\"openai\",\"permission\":" +
27-
"[{\"id\":\"modelperm-49FUp5v084tBB49tC4z8LPH5\",\"object\":\"model_permission\"," +
28-
"\"created\":1669085501,\"allow_create_engine\":false,\"allow_sampling\":true," +
29-
"\"allow_logprobs\":true,\"allow_search_indices\":false,\"allow_view\":true," +
30-
"\"allow_fine_tuning\":false,\"organization\":\"*\",\"group\":null,\"is_blocking" +
31-
"\":false}],\"root\":\"$id\",\"parent\":null}]}"
80+
fun listModelsSuccessResult(id: String) = """
81+
{
82+
"object": "list",
83+
"data": [
84+
{
85+
"id": "$id",
86+
"object": "model",
87+
"created": 1649358449,
88+
"owned_by": "openai",
89+
"permission": [
90+
{
91+
"id": "modelperm-49FUp5v084tBB49tC4z8LPH5",
92+
"object": "model_permission",
93+
"created": 1669085501,
94+
"allow_create_engine": false,
95+
"allow_sampling": true,
96+
"allow_logprobs": true,
97+
"allow_search_indices": false,
98+
"allow_view": true,
99+
"allow_fine_tuning": false,
100+
"organization": "*",
101+
"group": null,
102+
"is_blocking": false
103+
}
104+
],
105+
"root": "$id",
106+
"parent": null
107+
}
108+
]
109+
}
110+
"""
32111

33-
fun modelSuccessResult(id: String) = "{\"id\":\"$id\",\"object\":\"model\"," +
34-
"\"created\":1649358449,\"owned_by\":\"openai\"," +
35-
"\"permission\":[{\"id\":\"modelperm-49FUp5v084tBB49tC4z8LPH5\"," +
36-
"\"object\":\"model_permission\",\"created\":1669085501,\"allow_create_engine\":false," +
37-
"\"allow_sampling\":true,\"allow_logprobs\":true,\"allow_search_indices\":false," +
38-
"\"allow_view\":true,\"allow_fine_tuning\":false,\"organization\":\"*\",\"group\":null," +
39-
"\"is_blocking\":false}],\"root\":\"$id\",\"parent\":null}"
112+
fun modelSuccessResult(id: String) = """
113+
{
114+
"id": "$id",
115+
"object": "model",
116+
"created": 1649358449,
117+
"owned_by": "openai",
118+
"permission": [
119+
{
120+
"id": "modelperm-49FUp5v084tBB49tC4z8LPH5",
121+
"object": "model_permission",
122+
"created": 1669085501,
123+
"allow_create_engine": false,
124+
"allow_sampling": true,
125+
"allow_logprobs": true,
126+
"allow_search_indices": false,
127+
"allow_view": true,
128+
"allow_fine_tuning": false,
129+
"organization": "*",
130+
"group": null,
131+
"is_blocking": false
132+
}
133+
],
134+
"root": "$id",
135+
"parent": null
136+
}
137+
"""
40138
}

0 commit comments

Comments
 (0)