Skip to content

Commit 27d9866

Browse files
committed
- added support for post template nodejs blocks
- added support for answering questions about a folder
1 parent 9dac1ea commit 27d9866

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

index.js

+31-5
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,42 @@ const { z } = require('zod');
111111
}
112112
});
113113
console.log('template_res',template_res);
114-
// check if we have none ':pre' code blocks (must run after the template)
115114
// add results from template_res.data obj schema to additional_context object
116115
additional_context = {...additional_context, ...{
117116
schema:template_res.data
118117
}};
118+
// check if we have none ':pre' code blocks (must run after the template)
119+
for (const block of code_blocks) {
120+
// if block.lang doesn't end with ':pre'
121+
if (!block.lang.endsWith(':pre')) {
122+
// if block.lang contains 'js'
123+
if (block.lang.includes('js')) {
124+
const code_executed = await code_helper.executeNode(additional_context,block.code);
125+
// if code_executed is an object
126+
if (typeof code_executed === 'object') {
127+
console.log('adding context from post js code block',code_executed);
128+
additional_context = {...additional_context,...code_executed};
129+
}
130+
}
131+
}
132+
}
133+
//
134+
} else if (action_or_question.data.is_question) {
135+
// 2) if the input is a question, run the question to the model with the 'default-template' and return the response
136+
const question = new code2prompt({
137+
path: currentWorkingDirectory,
138+
template: path.join(actionsDirectory,'default.md'),
139+
extensions: [],
140+
ignore: ["**/node_modules/**","**/*.png","**/*.jpg","**/*.gif","**/package-lock.json","**/.env","**/.gitignore","**/LICENSE"],
141+
OPENAI_KEY: process.env.OPENAI_KEY
142+
});
143+
const response = await question.request(argv.input);
144+
console.log('response:\n',response.data);
145+
} else {
146+
console.log('The input is not an action or a question.. exiting..');
147+
console.log(`Processing input: ${argv.input}`,currentWorkingDirectory,userOS);
148+
console.log(`Actions directory: ${actionsDirectory}`);
119149
}
120-
// 2) if the input is a question, run the question to the model with the 'default-template' and return the response
121-
122-
console.log(`Processing input: ${argv.input}`,currentWorkingDirectory,userOS);
123-
console.log(`Actions directory: ${actionsDirectory}`);
124150
if (argv.debug) {
125151
console.log('Debug mode is on');
126152
}

0 commit comments

Comments
 (0)