File tree Expand file tree Collapse file tree 7 files changed +16
-8
lines changed
sample/ios/YChatApp/Features/Completion/ViewModel
androidMain/kotlin/co/yml/ychat/di/module
commonMain/kotlin/co/yml/ychat/di/provider
jvmMain/kotlin/co/yml/ychat/di/module Expand file tree Collapse file tree 7 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ object Dependencies {
34
34
const val KTOR_LOGGING = " io.ktor:ktor-client-logging:${Versions .KTOR } "
35
35
const val KTOR_ANDROID = " io.ktor:ktor-client-android:${Versions .KTOR } "
36
36
const val KTOR_IOS = " io.ktor:ktor-client-ios:${Versions .KTOR } "
37
- const val KTOR_JAVA = " io.ktor:ktor-client-java :${Versions .KTOR } "
37
+ const val KTOR_OKHTTP = " io.ktor:ktor-client-okhttp :${Versions .KTOR } "
38
38
}
39
39
40
40
object DI {
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ internal final class CompletionViewModel: ObservableObject {
42
42
addLoading ( )
43
43
do {
44
44
if input. contains ( " /image " ) {
45
- let result = try await imageGenerations. execute ( prompt: input) [ 0 ] . url
45
+ let result = try await imageGenerations. execute ( prompt: input) [ 0 ]
46
46
removeLoading ( )
47
47
addAIImage ( url: result)
48
48
} else {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ pluginManagement {
8
8
9
9
dependencyResolutionManagement {
10
10
repositories {
11
+ mavenLocal()
11
12
google()
12
13
mavenCentral()
13
14
}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ kotlin {
67
67
}
68
68
val androidMain by getting {
69
69
dependencies {
70
- implementation(Dependencies .Network .KTOR_ANDROID )
70
+ implementation(Dependencies .Network .KTOR_OKHTTP )
71
71
}
72
72
}
73
73
val androidTest by getting {
@@ -98,7 +98,7 @@ kotlin {
98
98
}
99
99
val jvmMain by getting {
100
100
dependencies {
101
- implementation(Dependencies .Network .KTOR_JAVA )
101
+ implementation(Dependencies .Network .KTOR_OKHTTP )
102
102
}
103
103
}
104
104
val jvmTest by getting {
Original file line number Diff line number Diff line change 1
1
package co.yml.ychat.di.module
2
2
3
- import io.ktor.client.engine.android.Android
3
+ import io.ktor.client.engine.okhttp.OkHttp
4
4
import org.koin.dsl.module
5
5
6
6
internal actual fun platformModule () = module {
7
- single { Android .create() }
7
+ single { OkHttp .create() }
8
8
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package co.yml.ychat.di.provider
2
2
3
3
import io.ktor.client.HttpClient
4
4
import io.ktor.client.engine.HttpClientEngine
5
+ import io.ktor.client.plugins.HttpTimeout
5
6
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
6
7
import io.ktor.client.plugins.defaultRequest
7
8
import io.ktor.client.request.header
@@ -14,6 +15,7 @@ import kotlinx.serialization.json.Json
14
15
internal object NetworkProvider {
15
16
16
17
private const val BASE_URL = " api.openai.com"
18
+ private const val TIMEOUT_MILLIS = 60000L
17
19
18
20
fun provideHttpClient (engine : HttpClientEngine , apiKey : String ): HttpClient {
19
21
return HttpClient (engine) {
@@ -25,6 +27,11 @@ internal object NetworkProvider {
25
27
}
26
28
header(" Authorization" , " Bearer $apiKey " )
27
29
}
30
+ install(HttpTimeout ) {
31
+ requestTimeoutMillis = TIMEOUT_MILLIS
32
+ connectTimeoutMillis = TIMEOUT_MILLIS
33
+ socketTimeoutMillis = TIMEOUT_MILLIS
34
+ }
28
35
install(ContentNegotiation ) {
29
36
json(
30
37
Json {
Original file line number Diff line number Diff line change 1
1
package co.yml.ychat.di.module
2
2
3
- import io.ktor.client.engine.java.Java
3
+ import io.ktor.client.engine.okhttp.OkHttp
4
4
import org.koin.dsl.module
5
5
6
6
internal actual fun platformModule () = module {
7
- single { Java .create() }
7
+ single { OkHttp .create() }
8
8
}
You can’t perform that action at this time.
0 commit comments