-
Notifications
You must be signed in to change notification settings - Fork 62
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(chat): Refactor prompt hierarchy #834
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1a02ebb
Refactor prompt hierarchy
nirinchev c11f4d8
reformat
nirinchev 955c202
Fix build
nirinchev 87a0112
Address feedback, remove connect messages from all prompt builders
nirinchev 9dedc3b
Add tests and fix historyMessages not removing the pre-connection prompt
nirinchev 8f7e6c1
Remove .only
nirinchev 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,52 +1,26 @@ | ||
import * as vscode from 'vscode'; | ||
import type { PromptArgsBase } from './promptBase'; | ||
import { PromptBase } from './promptBase'; | ||
|
||
import { getHistoryMessages } from './history'; | ||
|
||
export class GenericPrompt { | ||
static getAssistantPrompt(): vscode.LanguageModelChatMessage { | ||
const prompt = `You are a MongoDB expert. | ||
export class GenericPrompt extends PromptBase<PromptArgsBase> { | ||
protected getAssistantPrompt(): string { | ||
return `You are a MongoDB expert. | ||
Your task is to help the user craft MongoDB queries and aggregation pipelines that perform their task. | ||
Keep your response concise. | ||
You should suggest queries that are performant and correct. | ||
Respond with markdown, suggest code in a Markdown code block that begins with \`\`\`javascript and ends with \`\`\`. | ||
You can imagine the schema, collection, and database name. | ||
Respond in MongoDB shell syntax using the \`\`\`javascript code block syntax.`; | ||
|
||
// eslint-disable-next-line new-cap | ||
return vscode.LanguageModelChatMessage.Assistant(prompt); | ||
} | ||
|
||
static getUserPrompt(prompt: string): vscode.LanguageModelChatMessage { | ||
// eslint-disable-next-line new-cap | ||
return vscode.LanguageModelChatMessage.User(prompt); | ||
protected getUserPrompt(args: PromptArgsBase): Promise<string> { | ||
return Promise.resolve(args.request.prompt); | ||
} | ||
|
||
static getEmptyRequestResponse(): string { | ||
public getEmptyRequestResponse(): string { | ||
// TODO(VSCODE-572): Generic empty response handler | ||
return vscode.l10n.t( | ||
'Ask anything about MongoDB, from writing queries to questions about your cluster.' | ||
); | ||
} | ||
|
||
static buildMessages({ | ||
context, | ||
request, | ||
}: { | ||
request: { | ||
prompt: string; | ||
}; | ||
context: vscode.ChatContext; | ||
}): vscode.LanguageModelChatMessage[] { | ||
const messages = [ | ||
GenericPrompt.getAssistantPrompt(), | ||
...getHistoryMessages({ context }), | ||
GenericPrompt.getUserPrompt(request.prompt), | ||
]; | ||
|
||
return messages; | ||
} | ||
} | ||
|
||
export function isPromptEmpty(request: vscode.ChatRequest): boolean { | ||
return !request.prompt || request.prompt.trim().length === 0; | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import { GenericPrompt } from './generic'; | ||
import type * as vscode from 'vscode'; | ||
import { NamespacePrompt } from './namespace'; | ||
import { QueryPrompt } from './query'; | ||
import { SchemaPrompt } from './schema'; | ||
|
||
export class Prompts { | ||
public static generic = new GenericPrompt(); | ||
public static namespace = new NamespacePrompt(); | ||
public static query = new QueryPrompt(); | ||
public static schema = new SchemaPrompt(); | ||
|
||
public static isPromptEmpty(request: vscode.ChatRequest): boolean { | ||
return !request.prompt || request.prompt.trim().length === 0; | ||
} | ||
} |
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.
This is a drive-by - I wanted to more strongly confine the metadata types to ensure we don't have
docsChatbotMessageId
unless the intent isdocs
.