Skip to content

Commit

Permalink
Merge pull request #170 from devchat-ai/timing-completion
Browse files Browse the repository at this point in the history
Timing code completions
  • Loading branch information
pplam authored Jun 13, 2024
2 parents 4d1b7f3 + 02ad72f commit f6d07f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ class Agent(val scope: CoroutineScope) {
val manually: Boolean?,
)

data class CompletionResponse(val id: String, val choices: List<Choice>) {
data class CompletionResponse(
val id: String,
val choices: List<Choice>,
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)
}
Expand All @@ -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,
Expand Down Expand Up @@ -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))
}

Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
Expand Down Expand Up @@ -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
)
)
}
Expand All @@ -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,
)
)
}
Expand Down

0 comments on commit f6d07f0

Please sign in to comment.