Skip to content

Commit

Permalink
feat(action.ts, index.js): add directory creation for save_path to en…
Browse files Browse the repository at this point in the history
…sure the path exists before writing files
  • Loading branch information
0xJord4n committed Dec 24, 2024
1 parent d73530f commit 206b219
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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));
const path_1 = __importDefault(__nccwpck_require__(6928));
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 @@ -35,6 +36,8 @@ exports["default"] = (input) => __awaiter(void 0, void 0, void 0, function* () {
stopSequences: input.stop,
});
if (input.save_path) {
const dir = path_1.default.dirname(input.save_path);
fs_1.default.mkdirSync(dir, { recursive: true });
fs_1.default.writeFileSync(input.save_path, llmResponse.text, {
encoding: "utf-8",
});
Expand Down
4 changes: 4 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { Output } from "./types";
import { CoreMessage, generateText } from "ai";
import type { inputSchema } from "./input";
import fs from "fs";
import path from "path";

export default async (input: z.infer<typeof inputSchema>): Promise<Output> => {
const llmResponse = await generateText({
model: provider(input.provider, input.provider_options)(input.model),
Expand All @@ -18,6 +20,8 @@ export default async (input: z.infer<typeof inputSchema>): Promise<Output> => {
});

if (input.save_path) {
const dir = path.dirname(input.save_path);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(input.save_path, llmResponse.text, {
encoding: "utf-8",
});
Expand Down

0 comments on commit 206b219

Please sign in to comment.