Skip to content
Snippets Groups Projects
Commit 19c90bda authored by thucpn's avatar thucpn
Browse files

use crypto

parent d5cb8980
No related branches found
No related tags found
No related merge requests found
import { tool } from "@llamaindex/core/tools"; import { tool } from "@llamaindex/core/tools";
import { randomUUID } from "@llamaindex/env";
import { FormData } from "formdata-node"; import { FormData } from "formdata-node";
import got from "got"; import got from "got";
import path from "path"; import path from "path";
...@@ -37,7 +36,7 @@ export const imageGenerator = (params: ImgGeneratorToolParams) => { ...@@ -37,7 +36,7 @@ export const imageGenerator = (params: ImgGeneratorToolParams) => {
try { try {
const buffer = await promptToImgBuffer(prompt, apiKey, outputFormat); const buffer = await promptToImgBuffer(prompt, apiKey, outputFormat);
const filename = `${randomUUID()}.${outputFormat}`; const filename = `${crypto.randomUUID()}.${outputFormat}`;
const filePath = path.join(outputDir, filename); const filePath = path.join(outputDir, filename);
await saveDocument(filePath, buffer); await saveDocument(filePath, buffer);
const imageUrl = getFileUrl(filePath, { fileServerURLPrefix }); const imageUrl = getFileUrl(filePath, { fileServerURLPrefix });
......
import { type Logs, Result, Sandbox } from "@e2b/code-interpreter"; import { type Logs, Result, Sandbox } from "@e2b/code-interpreter";
import { tool } from "@llamaindex/core/tools"; import { tool } from "@llamaindex/core/tools";
import { randomUUID } from "@llamaindex/env";
import fs from "fs"; import fs from "fs";
import path from "node:path"; import path from "node:path";
import { z } from "zod"; import { z } from "zod";
...@@ -154,7 +153,7 @@ async function getExtraResult( ...@@ -154,7 +153,7 @@ async function getExtraResult(
} }
async function saveToDisk(outputDir: string, base64Data: string, ext: string) { async function saveToDisk(outputDir: string, base64Data: string, ext: string) {
const filename = `${randomUUID()}.${ext}`; const filename = `${crypto.randomUUID()}.${ext}`;
const buffer = Buffer.from(base64Data, "base64"); const buffer = Buffer.from(base64Data, "base64");
const filePath = path.join(outputDir, filename); const filePath = path.join(outputDir, filename);
await saveDocument(filePath, buffer); await saveDocument(filePath, buffer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment