Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: proactively show code generation iterations #5282

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q/dev proactively show code generation iterations"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,12 @@
},
"codeGenerationStatus": {
"shape": "CodeGenerationStatus"
},
"codeGenerationRemainingIterationCount": {
"shape": "Integer"
},
"codeGenerationTotalIterationCount": {
"shape": "Integer"
}
},
"documentation": "<p>Response for getting task assist code generation status.</p>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,18 @@ export class FeatureDevController {
tabID,
session.uploadId
)

const remainingIterations = session.state.codeGenerationRemainingIterationCount
const totalIterations = session.state.codeGenerationTotalIterationCount

if (remainingIterations !== undefined && totalIterations !== undefined) {
this.messenger.sendAnswer({
type: 'answer',
tabID: tabID,
message: `You have ${remainingIterations} out of ${totalIterations} code iterations remaining.`,
})
}

this.messenger.sendAnswer({
message: undefined,
type: 'system-prompt',
Expand Down
22 changes: 19 additions & 3 deletions packages/core/src/amazonqFeatureDev/session/sessionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,18 @@ abstract class CodeGenBase {
newFiles: NewFileInfo[]
deletedFiles: DeletedFileInfo[]
references: CodeReference[]
codeGenerationRemainingIterationCount?: number
codeGenerationTotalIterationCount?: number
}> {
for (
let pollingIteration = 0;
pollingIteration < this.pollCount && !this.tokenSource.token.isCancellationRequested;
++pollingIteration
) {
const codegenResult = await this.config.proxyClient.getCodeGeneration(this.conversationId, codeGenerationId)
const codeGenerationRemainingIterationCount = codegenResult.codeGenerationRemainingIterationCount
const codeGenerationTotalIterationCount = codegenResult.codeGenerationTotalIterationCount

getLogger().debug(`Codegen response: %O`, codegenResult)
telemetry.setCodeGenerationResult(codegenResult.codeGenerationStatus.status)
switch (codegenResult.codeGenerationStatus.status) {
Expand All @@ -273,6 +278,8 @@ abstract class CodeGenBase {
newFiles: newFileInfo,
deletedFiles: getDeletedFileInfos(deletedFiles, workspaceFolders),
references,
codeGenerationRemainingIterationCount: codeGenerationRemainingIterationCount,
codeGenerationTotalIterationCount: codeGenerationTotalIterationCount,
}
}
case 'predict-ready':
Expand Down Expand Up @@ -321,7 +328,9 @@ export class CodeGenState extends CodeGenBase implements SessionState {
public deletedFiles: DeletedFileInfo[],
public references: CodeReference[],
tabID: string,
private currentIteration: number
private currentIteration: number,
public codeGenerationRemainingIterationCount?: number,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting public fields before private fields

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We couldn't because "A required parameter cannot follow an optional parameter."

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let's follow the linter

public codeGenerationTotalIterationCount?: number
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these fields optional?

Copy link
Contributor Author

@linyuxi0511 linyuxi0511 Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we do need them to be optional, since at the very first time when we asking for code generation, we don't know this iteration counts. We could have some default value passed when we initiate the CodeGenState, but that might misrepresent the meaning of "remaining/total counts". Hence I would prefer to leave it optional.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, this is because this is getting CodeGenResult instead of CodeGenStatus. Sounds good

) {
super(config, tabID)
}
Expand Down Expand Up @@ -358,6 +367,9 @@ export class CodeGenState extends CodeGenBase implements SessionState {
this.filePaths = codeGeneration.newFiles
this.deletedFiles = codeGeneration.deletedFiles
this.references = codeGeneration.references
this.codeGenerationRemainingIterationCount = codeGeneration.codeGenerationRemainingIterationCount
this.codeGenerationTotalIterationCount = codeGeneration.codeGenerationTotalIterationCount

action.telemetry.setAmazonqNumberOfReferences(this.references.length)
action.telemetry.recordUserCodeGenerationTelemetry(span, this.conversationId)
const nextState = new PrepareCodeGenState(
Expand All @@ -367,7 +379,9 @@ export class CodeGenState extends CodeGenBase implements SessionState {
this.deletedFiles,
this.references,
this.tabID,
this.currentIteration + 1
this.currentIteration + 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious: there is any risk that currentIteration be different from those counts? And if its, have we tested what is shown to the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the currentIteration would be simply "totaliteration-remainingIteration". This is calculated in the front end.
However we decided to expose and use the API carried values since they are got from the source of truth - our ddb table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so do we need remove currentIteration since we now have new counts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this field currentIteration is not actually being used for now. I think the idea is to use iterationCounts instead.

this.codeGenerationRemainingIterationCount,
this.codeGenerationTotalIterationCount
)
return {
nextState,
Expand Down Expand Up @@ -480,7 +494,9 @@ export class PrepareCodeGenState implements SessionState {
public deletedFiles: DeletedFileInfo[],
public references: CodeReference[],
public tabID: string,
private currentIteration: number
private currentIteration: number,
public codeGenerationRemainingIterationCount?: number,
public codeGenerationTotalIterationCount?: number
) {
this.tokenSource = new vscode.CancellationTokenSource()
this.uploadId = config.uploadId
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/amazonqFeatureDev/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export interface SessionState {
readonly tabID: string
interact(action: SessionStateAction): Promise<SessionStateInteraction>
updateWorkspaceRoot?: (workspaceRoot: string) => void
codeGenerationRemainingIterationCount?: number
codeGenerationTotalIterationCount?: number
}

export interface SessionStateConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,9 @@
"members": {
"conversationId": { "shape": "ConversationId" },
"codeGenerationStatus": { "shape": "CodeGenerationStatus" },
"codeGenerationStatusDetail": { "shape": "CodeGenerationStatusDetail" }
"codeGenerationStatusDetail": { "shape": "CodeGenerationStatusDetail" },
"codeGenerationRemainingIterationCount": { "shape": "Integer" },
"codeGenerationTotalIterationCount": { "shape": "Integer" }
},
"documentation": "<p>Response for getting task assist code generation status.</p>"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ describe('sessionState', () => {

describe('CodeGenState', () => {
it('transitions to PrepareCodeGenState when codeGenerationStatus ready ', async () => {
mockGetCodeGeneration = sinon.stub().resolves({ codeGenerationStatus: { status: 'Complete' } })
mockGetCodeGeneration = sinon.stub().resolves({
codeGenerationStatus: { status: 'Complete' },
codeGenerationRemainingIterationCount: 2,
codeGenerationTotalIterationCount: 3,
})
mockExportResultArchive = sinon.stub().resolves({ newFileContents: [], deletedFiles: [], references: [] })

const testAction = mockSessionStateAction()
const state = new CodeGenState(testConfig, testApproach, [], [], [], tabId, 0)
const state = new CodeGenState(testConfig, testApproach, [], [], [], tabId, 0, 2, 3)
const result = await state.interact(testAction)

const nextState = new PrepareCodeGenState(testConfig, testApproach, [], [], [], tabId, 1)
const nextState = new PrepareCodeGenState(testConfig, testApproach, [], [], [], tabId, 1, 2, 3)

assert.deepStrictEqual(result, {
nextState,
Expand Down
Loading