From f2b0d632299d3c7712eec2674615b954b0bbc044 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 26 Aug 2024 17:36:31 +0800 Subject: [PATCH] refactor(llm): simplify request body creation in OpenAILikeProvider #60 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. --- src/main/kotlin/com/phodal/shire/llm/OpenAILikeProvider.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/phodal/shire/llm/OpenAILikeProvider.kt b/src/main/kotlin/com/phodal/shire/llm/OpenAILikeProvider.kt index 5fa002df..7cc6fe53 100644 --- a/src/main/kotlin/com/phodal/shire/llm/OpenAILikeProvider.kt +++ b/src/main/kotlin/com/phodal/shire/llm/OpenAILikeProvider.kt @@ -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 { @@ -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()) {