Skip to content

Commit

Permalink
feat(BE-190): As a user, i want able to use ollama-client
Browse files Browse the repository at this point in the history
 - support specific protocol, host and port
  • Loading branch information
hanrw committed Apr 15, 2024
1 parent dfd8608 commit 8ff4560
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.*
import kotlinx.serialization.json.Json
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds


Expand All @@ -20,12 +19,16 @@ internal expect fun httpClientEngine(): HttpClientEngineFactory<HttpClientEngine
/**
* Creates a new [HttpClient] with [OkHttp] engine and [ContentNegotiation] plugin.
*
* @param url the base URL of the API
* @param protocol the protocol to use - default is HTTPS
* @param host the base URL of the API
* @param port the port to use - default is 443
* @param authToken the authentication token
* @return a new [HttpClient] instance
*/
fun createHttpClient(
url: () -> String,
protocol: () -> String? = { null },
host: () -> String,
port: () -> Int? = { null },
authToken: (() -> String)? = null,
json: Json,
): HttpClient {
Expand Down Expand Up @@ -92,11 +95,11 @@ fun createHttpClient(

defaultRequest {
url {
protocol = URLProtocol.HTTPS
host = url()
this.protocol = protocol()?.let { URLProtocol.createOrDefault(it) } ?: URLProtocol.HTTPS
this.host = host()
port()?.let { this.port = it }
}


authToken?.let {
header(HttpHeaders.Authorization, "Bearer ${it()}")
}
Expand Down

0 comments on commit 8ff4560

Please sign in to comment.