Skip to content

Commit 9ff45d7

Browse files
committed
fix(CustomLLMProvider, OpenAIDto): enhance request format handling and update JSON property annotations
1 parent 7604bdf commit 9ff45d7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/llms/custom/CustomLLMProvider.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class CustomLLMProvider(val project: Project, var llmConfig: LlmConfig = LlmConf
2525
CustomSSEProcessor(project) {
2626
private val url get() = llmConfig.url
2727
private val key get() = llmConfig.auth.token
28-
override val requestFormat: String get() = llmConfig.requestFormat
28+
override val requestFormat: String get() = llmConfig.requestFormat.ifEmpty {
29+
llmConfig.toLegacyRequestFormat()
30+
}
31+
2932
override val responseFormat: String get() = llmConfig.responseFormat
3033

3134
private var client = OkHttpClient()

core/src/main/kotlin/cc/unitmesh/devti/llms/custom/OpenAIDto.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ import com.fasterxml.jackson.databind.JsonNode
77
import kotlinx.serialization.Serializable
88

99
data class ChatFunctionCall(
10+
@JsonProperty("name")
1011
val name: String? = null,
12+
@JsonProperty("arguments")
1113
val arguments: JsonNode? = null,
1214
)
1315

1416
data class ChatMessage(
15-
val role: String,
17+
@JsonProperty("role")
18+
val role: String? = null,
19+
@JsonProperty("content")
1620
@JsonInclude
1721
val content: String? = null,
22+
@JsonProperty("name")
1823
val name: String? = null,
1924
@JsonProperty("function_call")
2025
val functionCall: ChatFunctionCall? = null,
2126
)
2227

2328
data class ChatCompletionChoice(
29+
@JsonProperty("index")
2430
val index: Int? = null,
31+
@JsonProperty("message")
2532
@JsonAlias("delta")
2633
val message: ChatMessage? = null,
2734
@JsonProperty("finish_reason")
@@ -39,10 +46,16 @@ data class Usage(
3946
)
4047

4148
data class ChatCompletionResult(
49+
@JsonProperty("id")
4250
val id: String? = null,
51+
@JsonProperty("object")
4352
val `object`: String? = null,
53+
@JsonProperty("created")
4454
val created: Long = 0,
55+
@JsonProperty("model")
4556
val model: String? = null,
57+
@JsonProperty("choices")
4658
val choices: List<ChatCompletionChoice>,
59+
@JsonProperty("usage")
4760
val usage: Usage? = null,
4861
)

0 commit comments

Comments
 (0)