Skip to content

Commit

Permalink
feat(index.js): add file saving functionality for LLM response to all…
Browse files Browse the repository at this point in the history
…ow users to save output to a specified path

feat(index.js): update input schema to include optional save_path property for enhanced flexibility in user input
  • Loading branch information
0xJord4n committed Dec 24, 2024
1 parent df5cf04 commit 8d3dfda
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const provider_1 = __importDefault(__nccwpck_require__(4279));
const ai_1 = __nccwpck_require__(6619);
const fs_1 = __importDefault(__nccwpck_require__(9896));
exports["default"] = (input) => __awaiter(void 0, void 0, void 0, function* () {
const llmResponse = yield (0, ai_1.generateText)({
model: (0, provider_1.default)(input.provider, input.provider_options)(input.model),
Expand All @@ -33,6 +34,11 @@ exports["default"] = (input) => __awaiter(void 0, void 0, void 0, function* () {
presencePenalty: input.presence_penalty,
stopSequences: input.stop,
});
if (input.save_path) {
fs_1.default.writeFileSync(input.save_path, llmResponse.text, {
encoding: "utf-8",
});
}
return {
text: llmResponse.text,
usage: llmResponse.usage,
Expand Down Expand Up @@ -129,6 +135,7 @@ exports.messageSchema = zod.object({
exports.inputSchema = zod.object({
provider: zod.nativeEnum(types_1.Provider),
provider_options: exports.providerOptionsSchema,
save_path: zod.string().optional(),
prompt: zod.string().optional(),
system: zod.string().optional(),
messages: zod.array(exports.messageSchema).optional(),
Expand Down

0 comments on commit 8d3dfda

Please sign in to comment.