refactor(prompts): extract prompt templates to dedicated module
This commit is contained in:
parent
3c3dab1525
commit
eec90209d2
2 changed files with 19 additions and 14 deletions
18
src/index.ts
18
src/index.ts
|
|
@ -6,6 +6,7 @@ import { streamText } from "ai";
|
|||
import { initConfig, loadConfig } from "./config";
|
||||
import { Conversation } from "./conversation";
|
||||
import { handleTopLevel } from "./errors";
|
||||
import { Prompts } from "./prompts";
|
||||
import Renderer from "./render";
|
||||
|
||||
async function main() {
|
||||
|
|
@ -73,21 +74,10 @@ async function main() {
|
|||
|
||||
let prompt = "Introduce yourself.";
|
||||
const input = positionals.join(" ").trim();
|
||||
if (messageFlag) {
|
||||
prompt = `\`\`\`diff
|
||||
${input}
|
||||
\`\`\`
|
||||
if (messageFlag) prompt = Prompts.commit(input);
|
||||
else if (reviewFlag) prompt = Prompts.review(input);
|
||||
else if (input) prompt = input;
|
||||
|
||||
Generate a conventional commit message for this diff. If you are unable to generate a reasonable option, ask for more context.`;
|
||||
} else if (reviewFlag) {
|
||||
prompt = `\`\`\`diff
|
||||
${input}
|
||||
\`\`\`
|
||||
|
||||
Review the above diff for any potential bugs, best practices, performance issues, or security flaws. Let me know if you need any more context to compelete your review.`;
|
||||
} else if (input) {
|
||||
prompt = input;
|
||||
}
|
||||
convo.messages.push({ role: "user", content: prompt });
|
||||
|
||||
const { fullStream, text, totalUsage } = streamText({
|
||||
|
|
|
|||
15
src/prompts.ts
Normal file
15
src/prompts.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
export const Prompts = {
|
||||
default: "Introduce yourself.",
|
||||
|
||||
commit: (input: string) => `\`\`\`diff
|
||||
${input}
|
||||
\`\`\`
|
||||
|
||||
Generate a conventional commit message for this diff. If you are unable to generate a reasonable option, ask for more context.`,
|
||||
|
||||
review: (input: string) => `\`\`\`diff
|
||||
${input}
|
||||
\`\`\`
|
||||
|
||||
Review the above diff for any potential bugs, best practices, performance issues, or security flaws. Let me know if you need any more context to complete your review.`,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue