-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
chat: prototype of choices API for response stream #238011
Open
connor4312
wants to merge
1
commit into
main
Choose a base branch
from
connor4312/chat-choices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+338
−48
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/vs/workbench/contrib/chat/browser/chatContentParts/chatChoicesContentPart.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Emitter } from '../../../../../base/common/event.js'; | ||
import { Disposable, IDisposable } from '../../../../../base/common/lifecycle.js'; | ||
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js'; | ||
import { IChatProgressRenderableResponseContent } from '../../common/chatModel.js'; | ||
import { IChatChoices, IChatSendRequestOptions, IChatService } from '../../common/chatService.js'; | ||
import { isResponseVM } from '../../common/chatViewModel.js'; | ||
import { IChatWidgetService } from '../chat.js'; | ||
import { ChatChoicesWidget } from './chatChoicesWidget.js'; | ||
import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js'; | ||
|
||
export class ChatChoicesContentPart extends Disposable implements IChatContentPart { | ||
public readonly domNode: HTMLElement; | ||
|
||
private readonly _onDidChangeHeight = this._register(new Emitter<void>()); | ||
public readonly onDidChangeHeight = this._onDidChangeHeight.event; | ||
|
||
private get showButtons() { | ||
return this.choices.disableAfterUse ? !this.choices.isUsed : true; | ||
} | ||
|
||
constructor( | ||
private readonly choices: IChatChoices, | ||
context: IChatContentPartRenderContext, | ||
@IInstantiationService private readonly instantiationService: IInstantiationService, | ||
@IChatService private readonly chatService: IChatService, | ||
@IChatWidgetService chatWidgetService: IChatWidgetService, | ||
) { | ||
super(); | ||
|
||
const element = context.element; | ||
const buttonsWidget = this._register(this.instantiationService.createInstance( | ||
ChatChoicesWidget<string | { title: string }>, | ||
choices.title, | ||
choices.message, | ||
choices.items.map((choice, i) => ({ | ||
label: choiceLabel(choice), | ||
data: choice, | ||
isSecondary: i > 0, | ||
})) | ||
)); | ||
buttonsWidget.setShowButtons(this.showButtons); | ||
|
||
this._register(buttonsWidget.onDidClick(async e => { | ||
if (isResponseVM(element)) { | ||
const prompt = `${e.label}: "${choices.title}"`; | ||
const options: IChatSendRequestOptions = { | ||
choiceData: [e.data], | ||
agentId: element.agent?.id, | ||
slashCommand: element.slashCommand?.name, | ||
madeChoice: { | ||
title: e.label, | ||
responseId: context.element.id, | ||
}, | ||
userSelectedModelId: chatWidgetService.getWidgetBySessionId(element.sessionId)?.input.currentLanguageModel, | ||
}; | ||
|
||
const wasShowingButtons = this.showButtons; | ||
if (await this.chatService.sendRequest(element.sessionId, prompt, options)) { | ||
choices.isUsed = true; | ||
if (this.showButtons !== wasShowingButtons) { | ||
buttonsWidget.setShowButtons(this.showButtons); | ||
this._onDidChangeHeight.fire(); | ||
} | ||
} | ||
} | ||
})); | ||
|
||
this.domNode = buttonsWidget.domNode; | ||
} | ||
|
||
hasSameContent(other: IChatProgressRenderableResponseContent): boolean { | ||
// No other change allowed for this content type | ||
return other.kind === 'choices'; | ||
} | ||
|
||
addDisposable(disposable: IDisposable): void { | ||
this._register(disposable); | ||
} | ||
} | ||
|
||
const choiceLabel = (choice: string | { title: string }) => typeof choice === 'string' ? choice : choice.title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { ITreeFilter, TreeFilterResult } from '../../../../base/browser/ui/tree/tree.js'; | ||
import { FuzzyScore } from '../../../../base/common/filters.js'; | ||
import { isRequestVM, isResponseVM } from '../common/chatViewModel.js'; | ||
import { ChatTreeItem } from './chat.js'; | ||
|
||
export interface IChatWidgetFilterDelegate { | ||
getPrevElement(element: ChatTreeItem): ChatTreeItem | null; | ||
} | ||
|
||
export class ChatWidgetFilter implements ITreeFilter<ChatTreeItem, FuzzyScore> { | ||
constructor( | ||
private readonly delegate: IChatWidgetFilterDelegate, | ||
private readonly inherited: undefined | ((item: ChatTreeItem) => boolean), | ||
) { } | ||
|
||
filter(element: ChatTreeItem): TreeFilterResult<FuzzyScore> { | ||
if (isRequestVM(element)) { | ||
const isChoiceFromResponseId = element.madeChoice?.responseId; | ||
const previous = this.delegate.getPrevElement(element); | ||
if (isResponseVM(previous) && previous.id === isChoiceFromResponseId) { | ||
return false; | ||
} | ||
} | ||
|
||
return this.inherited?.(element) ?? true; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having trouble to understand why this is an array and not just "the item", also how is the related to
madeChoice
. From the usage they seem equal'ish but from the APIchoiceData
suggests to be all data and the latter seems to be the actual choice made?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the pattern of confirmations, but I'm good making it a single object if you think it makes more sense