Skip to content

Commit

Permalink
refactor(llm): simplify request body creation in OpenAILikeProvider #60
Browse files Browse the repository at this point in the history
This commit updates the `OpenAILikeProvider` by utilizing the `toRequestBody` extension function for simpler request body creation. This change removes the need for the `create` method and improves code readability.
  • Loading branch information
phodal committed Aug 26, 2024
1 parent da29cf4 commit f2b0d63
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/kotlin/com/phodal/shire/llm/OpenAILikeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.time.Duration

class OpenAILikeProvider : CustomSSEHandler(), LlmProvider {
Expand Down Expand Up @@ -89,7 +90,7 @@ class OpenAILikeProvider : CustomSSEHandler(), LlmProvider {
val customRequest = CustomRequest(messages)
val requestContent = customRequest.updateCustomFormat(requestFormat)

val body = RequestBody.create("application/json; charset=utf-8".toMediaTypeOrNull(), requestContent)
val body = requestContent.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())

val builder = Request.Builder()
if (key.isNotEmpty()) {
Expand Down

0 comments on commit f2b0d63

Please sign in to comment.