From 5c03d1a7723e908282bb1fcd132e2b8cf1c19f18 Mon Sep 17 00:00:00 2001 From: kami Date: Mon, 8 Jun 2026 10:59:23 +0400 Subject: [PATCH] feat(server): wire real inference into ProfileAdaptationService --- .../kotlin/com/correx/apps/server/Main.kt | 4 +- .../server/inference/InferenceSummarizer.kt | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/main/kotlin/com/correx/apps/server/inference/InferenceSummarizer.kt diff --git a/apps/server/src/main/kotlin/com/correx/apps/server/Main.kt b/apps/server/src/main/kotlin/com/correx/apps/server/Main.kt index ce6f790d..6aa71dee 100644 --- a/apps/server/src/main/kotlin/com/correx/apps/server/Main.kt +++ b/apps/server/src/main/kotlin/com/correx/apps/server/Main.kt @@ -57,9 +57,11 @@ import com.correx.core.toolintent.rules.ExecInterpreterRule import com.correx.core.toolintent.rules.NetworkHostRule import com.correx.core.toolintent.rules.PathContainmentRule import com.correx.apps.server.freestyle.FreestyleDriver +import com.correx.apps.server.inference.summarizeWithInference import com.correx.apps.server.personalization.ProfileAdaptationService import com.correx.core.artifacts.kind.DefaultArtifactKindRegistry import com.correx.core.events.types.ArtifactId +import com.correx.core.events.types.SessionId import com.correx.infrastructure.InfrastructureModule import com.correx.infrastructure.inference.DefaultProviderRegistry import com.correx.infrastructure.workflow.ExecutionPlanCompiler @@ -320,7 +322,7 @@ fun main() { if (correxConfig.personalization.enabled && correxConfig.personalization.learn) { ProfileAdaptationService( decisionJournalRepository = decisionJournalRepository, - summarize = { _ -> "# no changes\n# (stub: wire real LLM summarizer)" }, + summarize = { prompt -> summarizeWithInference(prompt, SessionId("system"), inferenceRouter) }, ) } else null diff --git a/apps/server/src/main/kotlin/com/correx/apps/server/inference/InferenceSummarizer.kt b/apps/server/src/main/kotlin/com/correx/apps/server/inference/InferenceSummarizer.kt new file mode 100644 index 00000000..b0a00966 --- /dev/null +++ b/apps/server/src/main/kotlin/com/correx/apps/server/inference/InferenceSummarizer.kt @@ -0,0 +1,57 @@ +package com.correx.apps.server.inference + +import com.correx.core.context.model.CompressionMetadata +import com.correx.core.context.model.ContextEntry +import com.correx.core.context.model.ContextLayer +import com.correx.core.context.model.ContextPack +import com.correx.core.context.model.EntryRole +import com.correx.core.events.types.ContextEntryId +import com.correx.core.events.types.ContextPackId +import com.correx.core.events.types.InferenceRequestId +import com.correx.core.events.types.SessionId +import com.correx.core.events.types.StageId +import com.correx.core.inference.GenerationConfig +import com.correx.core.inference.InferenceRequest +import com.correx.core.inference.InferenceRouter +import com.correx.core.inference.ModelCapability +import com.correx.core.inference.ResponseFormat +import java.util.UUID + +suspend fun summarizeWithInference( + prompt: String, + sessionId: SessionId, + inferenceRouter: InferenceRouter, +): String { + val stageId = StageId("summarizer") + val provider = inferenceRouter.route(stageId, setOf(ModelCapability.General)) + val contextPack = ContextPack( + id = ContextPackId(UUID.randomUUID().toString()), + sessionId = sessionId, + stageId = stageId, + layers = mapOf( + ContextLayer.L0 to listOf( + ContextEntry( + id = ContextEntryId(UUID.randomUUID().toString()), + layer = ContextLayer.L0, + content = prompt, + sourceType = "summarizer", + sourceId = "summarizer", + tokenEstimate = prompt.length / 4, + role = EntryRole.USER, + ) + ) + ), + budgetUsed = prompt.length / 4, + budgetLimit = 512, + compressionMetadata = CompressionMetadata(), + ) + val request = InferenceRequest( + requestId = InferenceRequestId(UUID.randomUUID().toString()), + sessionId = sessionId, + stageId = stageId, + contextPack = contextPack, + generationConfig = GenerationConfig(temperature = 0.3, topP = 0.9, maxTokens = 512), + responseFormat = ResponseFormat.Text, + ) + return provider.infer(request).text +}