Skip to content

Commit

Permalink
Separated default prompt in _gr.js into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdanwan committed Sep 11, 2024
1 parent 4ea9d20 commit 9eae47d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/_gr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,44 @@
import program from './commanderProgram.js';
import getFileContent from './getFileContent.js';
import promptAI from './ai.js';
import defaultPrompt from './defaultPrompt.js';

async function main() {
const args = process.argv;

program.parse(args);

const options = program.opts();

if (args.length == 2) {
// Prints general usage of tool (not all sub-commands and their options are shown)
console.log(program.help());
}

if (options.file) {
const files = options['file'];

let prompt =
'Take the following code and produce a README.md style response based on each file sent that explains the code (please have code snippets with comments):\n\n';
// Let the user specify their own prompt, or use the prompt that we have engineered
let prompt = options.prompt || defaultPrompt;

const modelFlag = options.model || null;
const outputFlag = options.output || null;
const model = options.model || null;
const outputFile = options.outputFile || null;

for (const file of files) {
console.log('Sending file: ');
console.log(file);
console.log('\n');

const content = getFileContent(file, modelFlag, outputFlag);

if (content) {
try {
const content = getFileContent(file);
prompt += content + '\n\n';
} catch (error) {
// Catch the error that's thrown if the file could not be read properly.
console.error(error);
}

// perhaps should throw an error if they can't read a file.
// if the error is thrown, then don't bother prompting AI at all and advise that a file could not be found.
}

try {
await promptAI(prompt);

} catch (err) {
console.error("Throw");
await promptAI(prompt, model, outputFile);
} catch (error) {
console.error(error);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/defaultPrompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// src/defaultPrompt.js

export default `Take the code from each file sent and produce a response in markdown explaining the code.
Ensure that the markdown returned uses semantic headings (i.e., first heading should have one hashtag (#)).
The first heading should be an appropriate title for the document (not README.md).
Give a "level 2 heading" for:
- the project structure
- each file sent (do not make a heading for the relative path of the file)
Ensure that in your explanation of the code that you refer to code snippets from the file(s) that are sent.\n\n`;

0 comments on commit 9eae47d

Please sign in to comment.