-
Notifications
You must be signed in to change notification settings - Fork 291
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
Hitesh/autoedits improvements #5956
base: main
Are you sure you want to change the base?
Changes from all commits
15bcaca
9295afc
daa9d6e
4b403c6
626ffae
3ec791c
e1d334c
2b0495e
4c0ee7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ export function getCurrentFilePromptComponents( | |
const codeToReplace = { | ||
codeToRewrite: codeToRewrite, | ||
startLine: completePrefixLines - prefixContext.codeToRewriteStartLines, | ||
endLine: completePrefixLines + suffixContext.codeToRewriteEndLines, | ||
endLine: completePrefixLines + suffixContext.codeToRewriteEndLines - 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, above you can just write How is |
||
} | ||
|
||
const fileWithMarker = ps`${prefixContext.prefixBeforeArea} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||
import { type AutoEditsTokenLimit, logDebug } from '@sourcegraph/cody-shared' | ||||||
import type * as vscode from 'vscode' | ||||||
import type { | ||||||
AutocompleteContextSnippet, | ||||||
DocumentContext, | ||||||
} from '../../../../lib/shared/src/completions/types' | ||||||
import { lines } from '../../completions/text-processing' | ||||||
import type { | ||||||
ChatPrompt, | ||||||
PromptProvider, | ||||||
PromptProviderResponse, | ||||||
PromptResponseData, | ||||||
} from '../prompt-provider' | ||||||
import { getModelResponse } from '../prompt-provider' | ||||||
import { type CodeToReplaceData, SYSTEM_PROMPT, getBaseUserPrompt } from '../prompt-utils' | ||||||
|
||||||
export class FireworksPromptProvider implements PromptProvider { | ||||||
getPrompt( | ||||||
docContext: DocumentContext, | ||||||
document: vscode.TextDocument, | ||||||
context: AutocompleteContextSnippet[], | ||||||
tokenBudget: AutoEditsTokenLimit | ||||||
): PromptResponseData { | ||||||
const { codeToReplace, promptResponse: userPrompt } = getBaseUserPrompt( | ||||||
docContext, | ||||||
document, | ||||||
context, | ||||||
tokenBudget | ||||||
) | ||||||
const prompt: ChatPrompt = [ | ||||||
{ | ||||||
role: 'system', | ||||||
content: SYSTEM_PROMPT, | ||||||
}, | ||||||
{ | ||||||
role: 'user', | ||||||
content: userPrompt, | ||||||
}, | ||||||
] | ||||||
return { | ||||||
codeToReplace: codeToReplace, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the property name and the variable name are the same, you can just write it once as a shorthand.
Suggested change
|
||||||
promptResponse: prompt, | ||||||
} | ||||||
} | ||||||
|
||||||
postProcessResponse(codeToReplace: CodeToReplaceData, response: string): string { | ||||||
// todo (hitesh): The finetuned model is messing up the identation of the first line. | ||||||
// todo: correct it manully for now, by checking the first line of the code to rewrite and adding the same indentation to the first line of the completion | ||||||
const codeToRewrite = codeToReplace.codeToRewrite.toString() | ||||||
const codeToRewriteLines = lines(codeToRewrite) | ||||||
const completionLines = lines(response) | ||||||
const firstLineMatch = codeToRewriteLines[0].match(/^(\s*)/) | ||||||
const firstLineIndentation = firstLineMatch ? firstLineMatch[1] : '' | ||||||
completionLines[0] = firstLineIndentation + completionLines[0].trimLeft() | ||||||
const completion = completionLines.join('\n') | ||||||
return completion | ||||||
} | ||||||
|
||||||
async getModelResponse( | ||||||
model: string, | ||||||
apiKey: string, | ||||||
prompt: PromptProviderResponse | ||||||
): Promise<string> { | ||||||
try { | ||||||
const response = await getModelResponse( | ||||||
'https://sourcegraph-6c39ed29.direct.fireworks.ai/v1/chat/completions', | ||||||
JSON.stringify({ | ||||||
model: model, | ||||||
messages: prompt, | ||||||
temperature: 0.1, | ||||||
max_tokens: 256, | ||||||
response_format: { | ||||||
type: 'text', | ||||||
}, | ||||||
}), | ||||||
apiKey | ||||||
) | ||||||
return response.choices[0].message.content | ||||||
} catch (error) { | ||||||
logDebug('AutoEdits', 'Error calling OpenAI API:', error) | ||||||
throw error | ||||||
} | ||||||
} | ||||||
} |
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.
This is a good candidate for a
switch
statement.Note, the method name is misspelled:
initialize