Skip to content

Commit

Permalink
codewhisperer: dont send unknown as completion type for empty recos (#…
Browse files Browse the repository at this point in the history
…3949)

* codewhisperer: dont send unknown as completion type for empty recos

* use first recommmendation completion type for user trigger decision

* remove unused import
  • Loading branch information
zixlin7 authored Oct 27, 2023
1 parent f009236 commit 1f5e736
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class CodeWhispererService {
false,
false,
"",
CodewhispererCompletionType.Unknown
CodewhispererCompletionType.Line
),
-1,
CodewhispererSuggestionState.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,7 @@ class CodeWhispererTelemetryService {
val classifierThreshold = CodeWhispererAutoTriggerService.getThreshold()

val supplementalContext = requestContext.supplementalContext
val completionType = if (recommendationContext.details.any {
it.completionType == CodewhispererCompletionType.Block
}
) {
CodewhispererCompletionType.Block
} else CodewhispererCompletionType.Line
val completionType = if (recommendationContext.details.isEmpty()) CodewhispererCompletionType.Line else recommendationContext.details[0].completionType

// only send if it's a pro tier user
projectCoroutineScope(project).launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ object CodeWhispererUtil {
val nonBlankLines = content.split("\n").count { it.isNotBlank() }

return when {
content.isEmpty() -> CodewhispererCompletionType.Unknown
content.isEmpty() -> CodewhispererCompletionType.Line
nonBlankLines > 1 -> CodewhispererCompletionType.Block
else -> CodewhispererCompletionType.Line
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhis
import software.aws.toolkits.jetbrains.services.telemetry.NoOpPublisher
import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
import software.aws.toolkits.jetbrains.settings.AwsSettings
import software.aws.toolkits.telemetry.CodewhispererCompletionType
import software.aws.toolkits.telemetry.CodewhispererPreviousSuggestionState
import software.aws.toolkits.telemetry.CodewhispererSuggestionState
import java.time.Duration
Expand Down Expand Up @@ -265,7 +264,7 @@ class CodeWhispererTelemetryServiceTest {
1,
"codewhispererSessionId" to responseContext.sessionId,
"codewhispererFirstRequestId" to requestContext.latencyContext.firstRequestId,
"codewhispererCompletionType" to CodewhispererCompletionType.Line,
"codewhispererCompletionType" to recommendationContext.details[0].completionType,
"codewhispererLanguage" to requestContext.fileContextInfo.programmingLanguage.toTelemetryType(),
"codewhispererTriggerType" to requestContext.triggerTypeInfo.triggerType,
"codewhispererAutomatedTriggerType" to requestContext.triggerTypeInfo.automatedTriggerType.telemetryType,
Expand Down Expand Up @@ -467,12 +466,7 @@ class CodeWhispererTelemetryServiceTest {
val expectedSuggestionReferenceCount = 1
val expectedGeneratedLineCount = 50
val expectedCharCount = 100
val expectedCompletionType = if (expectedRecommendationContext.details.any {
it.completionType == CodewhispererCompletionType.Block
}
) {
CodewhispererCompletionType.Block
} else CodewhispererCompletionType.Line
val expectedCompletionType = expectedRecommendationContext.details[0].completionType
sut.sendUserTriggerDecisionEvent(
expectedRequestContext,
expectedResponseContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
metricCaptor.allValues,
userDecision,
numOfEmptyRecommendations,
"codewhispererSuggestionState" to CodewhispererSuggestionState.Empty.toString()
"codewhispererSuggestionState" to CodewhispererSuggestionState.Empty.toString(),
"codewhispererCompletionType" to CodewhispererCompletionType.Line.toString()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ fun aRecommendationContextAndSessionContext(decisions: List<CodewhispererSuggest
decisions.forEach { decision ->
val toAdd = if (decision == CodewhispererSuggestionState.Empty) {
val completion = aCompletion("", true, 0, 0)
DetailContext(aString(), completion, completion, Random.nextBoolean(), Random.nextBoolean(), aString(), CodewhispererCompletionType.Unknown)
DetailContext(aString(), completion, completion, Random.nextBoolean(), Random.nextBoolean(), aString(), CodewhispererCompletionType.Line)
} else if (decision == CodewhispererSuggestionState.Discard) {
val completion = aCompletion()
DetailContext(aString(), completion, completion, true, Random.nextBoolean(), aString(), CodewhispererCompletionType.Unknown)
DetailContext(aString(), completion, completion, true, Random.nextBoolean(), aString(), CodewhispererCompletionType.Line)
} else {
val completion = aCompletion()
DetailContext(aString(), completion, completion, false, Random.nextBoolean(), aString(), CodewhispererCompletionType.Unknown)
DetailContext(aString(), completion, completion, false, Random.nextBoolean(), aString(), CodewhispererCompletionType.Line)
}

details.add(toAdd)
Expand Down

0 comments on commit 1f5e736

Please sign in to comment.