Skip to content

Commit

Permalink
some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Montagon committed Sep 4, 2023
1 parent 9d3ad79 commit 1ffe687
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,10 @@ private suspend fun HttpClient.makeRequest(
call: ApplicationCall,
url: String,
body: String,
token: String)
{
token: String
) {
val response = this.request(url) {
headers {
bearerAuth(token)
}
contentType(ContentType.Application.Json)
method = HttpMethod.Post
setBody(body)
setHttpRequestBuilder(token, body)
}
call.respond(response.status, response.body<String>())
}
Expand All @@ -98,12 +93,7 @@ private suspend fun HttpClient.makeStreaming(
token: String
) {
this.preparePost(url) {
headers {
bearerAuth(token)
}
contentType(ContentType.Application.Json)
method = HttpMethod.Post
setBody(body)
setHttpRequestBuilder(token, body)
}.execute { httpResponse ->
val channel: ByteReadChannel = httpResponse.body()
call.respondBytesWriter(
Expand All @@ -121,6 +111,17 @@ private suspend fun HttpClient.makeStreaming(
}
}

private fun setHttpRequestBuilder(token: String, body: String): HttpRequestBuilder =
HttpRequestBuilder().apply {
headers {
bearerAuth(token)
}
contentType(ContentType.Application.Json)
method = HttpMethod.Post
setBody(body)
}


private fun ApplicationCall.getProvider(): Provider =
request.headers["xef-provider"]?.toProvider()
?: Provider.OPENAI
Expand Down

0 comments on commit 1ffe687

Please sign in to comment.