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 {
3434 const val KTOR_LOGGING = " io.ktor:ktor-client-logging:${Versions .KTOR } "
3535 const val KTOR_ANDROID = " io.ktor:ktor-client-android:${Versions .KTOR } "
3636 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 } "
3838 }
3939
4040 object DI {
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ internal final class CompletionViewModel: ObservableObject {
4242 addLoading ( )
4343 do {
4444 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 ]
4646 removeLoading ( )
4747 addAIImage ( url: result)
4848 } else {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ pluginManagement {
88
99dependencyResolutionManagement {
1010 repositories {
11+ mavenLocal()
1112 google()
1213 mavenCentral()
1314 }
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ kotlin {
6767 }
6868 val androidMain by getting {
6969 dependencies {
70- implementation(Dependencies .Network .KTOR_ANDROID )
70+ implementation(Dependencies .Network .KTOR_OKHTTP )
7171 }
7272 }
7373 val androidTest by getting {
@@ -98,7 +98,7 @@ kotlin {
9898 }
9999 val jvmMain by getting {
100100 dependencies {
101- implementation(Dependencies .Network .KTOR_JAVA )
101+ implementation(Dependencies .Network .KTOR_OKHTTP )
102102 }
103103 }
104104 val jvmTest by getting {
Original file line number Diff line number Diff line change 11package co.yml.ychat.di.module
22
3- import io.ktor.client.engine.android.Android
3+ import io.ktor.client.engine.okhttp.OkHttp
44import org.koin.dsl.module
55
66internal actual fun platformModule () = module {
7- single { Android .create() }
7+ single { OkHttp .create() }
88}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package co.yml.ychat.di.provider
22
33import io.ktor.client.HttpClient
44import io.ktor.client.engine.HttpClientEngine
5+ import io.ktor.client.plugins.HttpTimeout
56import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
67import io.ktor.client.plugins.defaultRequest
78import io.ktor.client.request.header
@@ -14,6 +15,7 @@ import kotlinx.serialization.json.Json
1415internal object NetworkProvider {
1516
1617 private const val BASE_URL = " api.openai.com"
18+ private const val TIMEOUT_MILLIS = 60000L
1719
1820 fun provideHttpClient (engine : HttpClientEngine , apiKey : String ): HttpClient {
1921 return HttpClient (engine) {
@@ -25,6 +27,11 @@ internal object NetworkProvider {
2527 }
2628 header(" Authorization" , " Bearer $apiKey " )
2729 }
30+ install(HttpTimeout ) {
31+ requestTimeoutMillis = TIMEOUT_MILLIS
32+ connectTimeoutMillis = TIMEOUT_MILLIS
33+ socketTimeoutMillis = TIMEOUT_MILLIS
34+ }
2835 install(ContentNegotiation ) {
2936 json(
3037 Json {
Original file line number Diff line number Diff line change 11package co.yml.ychat.di.module
22
3- import io.ktor.client.engine.java.Java
3+ import io.ktor.client.engine.okhttp.OkHttp
44import org.koin.dsl.module
55
66internal actual fun platformModule () = module {
7- single { Java .create() }
7+ single { OkHttp .create() }
88}
You can’t perform that action at this time.
0 commit comments