-
Notifications
You must be signed in to change notification settings - Fork 335
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
chore(audoedit): decouple codeToReplaceData
from getPromptForModelType
#6474
Merged
valerybugakov
merged 3 commits into
main
from
vb/autoedits-analytics-logger-integration-2
Dec 27, 2024
+223
−269
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0e03084
chore(audoedit): decouple `codeToReplaceData` from `getPromptForModel…
valerybugakov 1e6f4a0
Merge branch 'main' into vb/autoedits-analytics-logger-integration-2
valerybugakov 3bb7198
Merge branch 'main' into vb/autoedits-analytics-logger-integration-2
valerybugakov 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,41 @@ | ||
import type * as vscode from 'vscode' | ||
|
||
import type { | ||
AutoEditsTokenLimit, | ||
AutocompleteContextSnippet, | ||
DocumentContext, | ||
PromptString, | ||
} from '@sourcegraph/cody-shared' | ||
|
||
import type { AutoeditsPrompt } from '../adapters/base' | ||
|
||
import { SYSTEM_PROMPT } from './constants' | ||
import { type CodeToReplaceData, getCompletionsPromptWithSystemPrompt } from './prompt-utils' | ||
import { type CurrentFilePromptComponents, getCompletionsPromptWithSystemPrompt } from './prompt-utils' | ||
|
||
export interface UserPromptArgs { | ||
docContext: DocumentContext | ||
document: vscode.TextDocument | ||
position: vscode.Position | ||
export interface UserPromptArgs | ||
extends Pick<CurrentFilePromptComponents, 'areaPrompt' | 'fileWithMarkerPrompt'> { | ||
context: AutocompleteContextSnippet[] | ||
tokenBudget: AutoEditsTokenLimit | ||
} | ||
|
||
export interface UserPromptResponse { | ||
codeToReplaceData: CodeToReplaceData | ||
prompt: PromptString | ||
} | ||
|
||
export interface UserPromptForModelArgs extends UserPromptArgs { | ||
isChatModel: boolean | ||
} | ||
|
||
export interface UserPromptForModelResponse { | ||
codeToReplaceData: CodeToReplaceData | ||
prompt: AutoeditsPrompt | ||
} | ||
|
||
/** | ||
* Class for generating user prompts in auto-edits functionality. | ||
* The major difference between different strategy is the prompt rendering. | ||
*/ | ||
export abstract class AutoeditsUserPromptStrategy { | ||
protected abstract getUserPrompt(args: UserPromptArgs): UserPromptResponse | ||
protected abstract getUserPrompt(args: UserPromptArgs): PromptString | ||
|
||
public getPromptForModelType({ | ||
isChatModel, | ||
...userPromptArgs | ||
}: UserPromptForModelArgs): UserPromptForModelResponse { | ||
const { codeToReplaceData, prompt } = this.getUserPrompt(userPromptArgs) | ||
}: UserPromptForModelArgs): AutoeditsPrompt { | ||
const prompt = this.getUserPrompt(userPromptArgs) | ||
|
||
const adjustedPrompt: AutoeditsPrompt = isChatModel | ||
? { systemMessage: SYSTEM_PROMPT, userMessage: prompt } | ||
: { userMessage: getCompletionsPromptWithSystemPrompt(SYSTEM_PROMPT, prompt) } | ||
|
||
return { | ||
codeToReplaceData, | ||
prompt: adjustedPrompt, | ||
} | ||
return adjustedPrompt | ||
} | ||
} |
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
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.
Why do we need this decoupling, do
autoedits-provider
need any additional fields from thecodeToReplaceData
?I think
fileWithMarkerPrompt
andareaPrompt
are the prompt components which are used to construct the final prompt. Earlier structure abstracts the individual prompt components from theautoedits-provider
so that,autoedits-provider
only has to know about the final prompt and not the individual components, and finalprompt-strateges
(eg:default-prompt-strategy.ts
orshort-term-diff-prompt-strategy.ts
) can call and use these prompt componentfileWithMarkerPrompt
and integrate/manipulate however it sees fit.autoedit-provider
first receiving the these prompt components, then it sending to the prompt constructors (likedefault-prompt-strategy
) imposes some risk, for example what if the prompt gets modified in theautoedits-provider
itself.autoedits-provider
as well, where earlier, I could just readprompt-constructor
for the final prompt creation and had to not at all look at theautoedits-provider
.I think if we need some additional fields from the prompt constructor we could send them in the
codeToReplaceData
itself, but can keep the responsibility of creating final prompt with individual prompt constructors.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.
Yeah, I agree. I started moving
fileWithMarkerPrompt, areaPrompt
out ofgetCurrentFilePromptComponents
so that we can get onlycodeToReplaceData
and other parts would be calculated inside of thegetPromptForModelType
method but it involved too many additional changes.For now, my goal is to extract the
codeToReplaceData
calculation because it's helpful to have it early. I can hidefileWithMarkerPrompt, areaPrompt
from the autoedits provider in a follow-up PR. WDYT?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.
yeah totally, we can do that in a follow up PR.
Approving to unblock !!
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.
Created an issue to follow-up https://linear.app/sourcegraph/issue/CODY-4596/hide-prompt-component-management-logic-from-the-autoedits-provider