From c2267a58a0c360997a282417ec61b26dfb201048 Mon Sep 17 00:00:00 2001 From: kami Date: Mon, 18 May 2026 21:38:50 +0400 Subject: [PATCH] feat(core:inference): add ResponseFormat, ToolDefinition, ToolCallRequest; extend InferenceRequest with tools and responseFormat --- core/inference/build.gradle | 1 + .../com/correx/core/inference/FinishReason.kt | 2 ++ .../correx/core/inference/InferenceRequest.kt | 2 ++ .../correx/core/inference/InferenceResponse.kt | 1 + .../com/correx/core/inference/ResponseFormat.kt | 13 +++++++++++++ .../correx/core/inference/ToolCallRequest.kt | 16 ++++++++++++++++ .../com/correx/core/inference/ToolDefinition.kt | 17 +++++++++++++++++ 7 files changed, 52 insertions(+) create mode 100644 core/inference/src/main/kotlin/com/correx/core/inference/ResponseFormat.kt create mode 100644 core/inference/src/main/kotlin/com/correx/core/inference/ToolCallRequest.kt create mode 100644 core/inference/src/main/kotlin/com/correx/core/inference/ToolDefinition.kt diff --git a/core/inference/build.gradle b/core/inference/build.gradle index 7f436a45..bb2f22de 100644 --- a/core/inference/build.gradle +++ b/core/inference/build.gradle @@ -7,4 +7,5 @@ plugins { dependencies { implementation(project(":core:events")) implementation(project(":core:context")) + implementation(project(":core:artifacts")) } \ No newline at end of file diff --git a/core/inference/src/main/kotlin/com/correx/core/inference/FinishReason.kt b/core/inference/src/main/kotlin/com/correx/core/inference/FinishReason.kt index c02ac7c1..3d54dd69 100644 --- a/core/inference/src/main/kotlin/com/correx/core/inference/FinishReason.kt +++ b/core/inference/src/main/kotlin/com/correx/core/inference/FinishReason.kt @@ -9,6 +9,8 @@ sealed class FinishReason { @Serializable object Length : FinishReason() @Serializable + object ToolCall : FinishReason() + @Serializable object Timeout : FinishReason() @Serializable object Cancelled : FinishReason() diff --git a/core/inference/src/main/kotlin/com/correx/core/inference/InferenceRequest.kt b/core/inference/src/main/kotlin/com/correx/core/inference/InferenceRequest.kt index ddbeef87..995282ad 100644 --- a/core/inference/src/main/kotlin/com/correx/core/inference/InferenceRequest.kt +++ b/core/inference/src/main/kotlin/com/correx/core/inference/InferenceRequest.kt @@ -14,4 +14,6 @@ data class InferenceRequest( val contextPack: ContextPack, val generationConfig: GenerationConfig, val timeout: InferenceTimeout? = null, + val responseFormat: ResponseFormat = ResponseFormat.Text, + val tools: List = emptyList(), ) \ No newline at end of file diff --git a/core/inference/src/main/kotlin/com/correx/core/inference/InferenceResponse.kt b/core/inference/src/main/kotlin/com/correx/core/inference/InferenceResponse.kt index 1356fb69..1a43fd80 100644 --- a/core/inference/src/main/kotlin/com/correx/core/inference/InferenceResponse.kt +++ b/core/inference/src/main/kotlin/com/correx/core/inference/InferenceResponse.kt @@ -10,4 +10,5 @@ data class InferenceResponse( val finishReason: FinishReason, val tokensUsed: TokenUsage, val latencyMs: Long, + val toolCalls: List = emptyList(), ) \ No newline at end of file diff --git a/core/inference/src/main/kotlin/com/correx/core/inference/ResponseFormat.kt b/core/inference/src/main/kotlin/com/correx/core/inference/ResponseFormat.kt new file mode 100644 index 00000000..e623a08a --- /dev/null +++ b/core/inference/src/main/kotlin/com/correx/core/inference/ResponseFormat.kt @@ -0,0 +1,13 @@ +package com.correx.core.inference + +import com.correx.core.artifacts.kind.JsonSchema +import kotlinx.serialization.Serializable + +@Serializable +sealed interface ResponseFormat { + @Serializable + object Text : ResponseFormat + + @Serializable + data class Json(val schema: JsonSchema) : ResponseFormat +} diff --git a/core/inference/src/main/kotlin/com/correx/core/inference/ToolCallRequest.kt b/core/inference/src/main/kotlin/com/correx/core/inference/ToolCallRequest.kt new file mode 100644 index 00000000..a5dfe2c0 --- /dev/null +++ b/core/inference/src/main/kotlin/com/correx/core/inference/ToolCallRequest.kt @@ -0,0 +1,16 @@ +package com.correx.core.inference + +import kotlinx.serialization.Serializable + +@Serializable +data class ToolCallRequest( + val id: String? = null, + val type: String = "function", + val function: ToolCallFunction, +) + +@Serializable +data class ToolCallFunction( + val name: String, + val arguments: String, +) \ No newline at end of file diff --git a/core/inference/src/main/kotlin/com/correx/core/inference/ToolDefinition.kt b/core/inference/src/main/kotlin/com/correx/core/inference/ToolDefinition.kt new file mode 100644 index 00000000..e580a5e6 --- /dev/null +++ b/core/inference/src/main/kotlin/com/correx/core/inference/ToolDefinition.kt @@ -0,0 +1,17 @@ +package com.correx.core.inference + +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonObject + +@Serializable +data class ToolDefinition( + val type: String = "function", + val function: ToolFunction, +) + +@Serializable +data class ToolFunction( + val name: String, + val description: String, + val parameters: JsonObject, +)