@@ -6,8 +6,6 @@ import com.cjcrafter.openai.chat.ChatRequest
6
6
import com.cjcrafter.openai.chat.ChatResponse
7
7
import com.cjcrafter.openai.chat.ChatResponseChunk
8
8
import com.cjcrafter.openai.completions.CompletionRequest
9
- import com.cjcrafter.openai.completions.CompletionResponse
10
- import com.cjcrafter.openai.completions.CompletionResponseChunk
11
9
import com.cjcrafter.openai.exception.OpenAIError
12
10
import io.github.cdimascio.dotenv.Dotenv
13
11
import io.github.cdimascio.dotenv.dotenv
@@ -32,9 +30,8 @@ object KotlinTest {
32
30
val scanner = Scanner (System .`in `)
33
31
34
32
// Print out the menu of options
35
- println (""" $GREEN
36
- Please select one of the options below by typing a number.
37
-
33
+ println ("""
34
+ ${GREEN } Please select one of the options below by typing a number.
38
35
1. Completion (create, sync)
39
36
2. Completion (stream, sync)
40
37
3. Completion (create, async)
@@ -76,17 +73,20 @@ object KotlinTest {
76
73
val openai = OpenAI (key)
77
74
println (RESET + " Generating Response" + PURPLE )
78
75
if (stream) {
79
- if (async)
76
+ if (async) {
80
77
openai.streamCompletionAsync(request, { print (it[0 ].text) })
81
- else
78
+ println (" $CYAN !!! Code has finished executing. Wait for async code to complete.$PURPLE " )
79
+ } else {
82
80
openai.streamCompletion(request, { print (it[0 ].text) })
81
+ }
83
82
} else {
84
- if (async)
83
+ if (async) {
85
84
openai.createCompletionAsync(request, { println (it[0 ].text) })
86
- else
85
+ println (" $CYAN !!! Code has finished executing. Wait for async code to complete.$PURPLE " )
86
+ } else {
87
87
println (openai.createCompletion(request)[0 ].text)
88
+ }
88
89
}
89
- println (" $CYAN !!! Code has finished executing. Wait for async code to complete.$RESET " )
90
90
}
91
91
92
92
@Throws(OpenAIError ::class )
@@ -126,6 +126,7 @@ object KotlinTest {
126
126
print (response[0 ].delta)
127
127
if (response[0 ].isFinished()) messages.add(response[0 ].message)
128
128
})
129
+ println (" $CYAN !!! Code has finished executing. Wait for async code to complete.$PURPLE " )
129
130
} else {
130
131
openai.streamChatCompletion(request, { response: ChatResponseChunk ->
131
132
print (response[0 ].delta)
@@ -138,13 +139,13 @@ object KotlinTest {
138
139
println (response[0 ].message.content)
139
140
messages.add(response[0 ].message)
140
141
})
142
+ println (" $CYAN !!! Code has finished executing. Wait for async code to complete.$PURPLE " )
141
143
} else {
142
144
val response = openai.createChatCompletion(request)
143
145
println (response[0 ].message.content)
144
146
messages.add(response[0 ].message)
145
147
}
146
148
}
147
- println (" $CYAN !!! Code has finished executing. Wait for async code to complete." )
148
149
}
149
150
}
150
151
}
0 commit comments