diff --git a/src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt b/src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt index 2f92afe..17444e9 100644 --- a/src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt +++ b/src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt @@ -51,7 +51,12 @@ class Agent(val scope: CoroutineScope) { val manually: Boolean?, ) - data class CompletionResponse(val id: String, val choices: List) { + data class CompletionResponse( + val id: String, + val choices: List, + val promptBuildingElapse: Long, + val llmRequestElapse: Long + ) { data class Choice(val index: Int, val text: String, val replaceRange: Range, ) { data class Range(val start: Int, val end: Int) } @@ -63,7 +68,10 @@ class Agent(val scope: CoroutineScope) { @SerializedName("lines") val lines: Int, @SerializedName("length") val length: Int, @SerializedName("ide") val ide: String, - @SerializedName("language") val language: String + @SerializedName("language") val language: String, + @SerializedName("prompt_time") val promptBuildingElapse: Long, + @SerializedName("llm_time") val llmRequestElapse: Long, + @SerializedName("cache_hit") val cacheHit: Boolean = false ) { enum class EventType { @SerializedName("view") VIEW, @@ -261,23 +269,27 @@ class Agent(val scope: CoroutineScope) { completionRequest: CompletionRequest ): CompletionResponse? = suspendCancellableCoroutine { continuation -> currentRequest = RequestInfo.fromCompletionRequest(completionRequest) + var startTime = System.currentTimeMillis() val prompt = ContextBuilder( completionRequest.filepath, completionRequest.text, completionRequest.position ).createPrompt(CONFIG["complete_model"] as? String) + val promptBuildingElapse = System.currentTimeMillis() - startTime scope.launch { + startTime = System.currentTimeMillis() val chunks = request(prompt) .let(::toLines) .let(::stopAtFirstBrace) .let(::stopAtDuplicateLine) .let(::stopAtBlockEnds) val completion = aggregate(chunks) + val llmRequestElapse = System.currentTimeMillis() - startTime val offset = completionRequest.position val replaceRange = CompletionResponse.Choice.Range(start = offset, end = offset) val choice = CompletionResponse.Choice(index = 0, text = completion.text, replaceRange = replaceRange) - val response = CompletionResponse(id = completion.id, choices = listOf(choice)) + val response = CompletionResponse(completion.id, listOf(choice), promptBuildingElapse, llmRequestElapse) continuation.resumeWith(Result.success(response)) } @@ -302,6 +314,7 @@ class Agent(val scope: CoroutineScope) { httpClient.newCall(requestBuilder.build()).execute().use { response -> logger.info("Log event response: $response") } + logger.info("Code completion log event: $logEventRequest") } catch (e: Exception) { logger.warn(e) } diff --git a/src/main/kotlin/ai/devchat/plugin/completion/editor/InlineCompletionService.kt b/src/main/kotlin/ai/devchat/plugin/completion/editor/InlineCompletionService.kt index da94cf6..f9d0540 100644 --- a/src/main/kotlin/ai/devchat/plugin/completion/editor/InlineCompletionService.kt +++ b/src/main/kotlin/ai/devchat/plugin/completion/editor/InlineCompletionService.kt @@ -164,7 +164,9 @@ class InlineCompletionService { lines = textLines.size, length = text.length, ide = "intellij", - language = virtualFile?.extension ?: "" + language = virtualFile?.extension ?: "", + promptBuildingElapse = completion.promptBuildingElapse, + llmRequestElapse = completion.llmRequestElapse ) ) } @@ -230,7 +232,9 @@ class InlineCompletionService { lines = text.lines().size, length = text.length, ide = "intellij", - language = virtualFile?.extension ?: "" + language = virtualFile?.extension ?: "", + promptBuildingElapse = currentCompletion.completion.promptBuildingElapse, + llmRequestElapse = currentCompletion.completion.llmRequestElapse ) ) } @@ -246,7 +250,9 @@ class InlineCompletionService { id=currentCompletion.completion.id, choices=listOf(Agent.CompletionResponse.Choice( 0, remainingText, Agent.CompletionResponse.Choice.Range(offset, offset) - )) + )), + promptBuildingElapse = 0, + llmRequestElapse = 0, ) ) }