fix (templates): law OK.

This commit is contained in:
Rodrigo Rodriguez 2024-09-11 14:41:24 -03:00
parent 98ef0213ac
commit d43a0796b6
4 changed files with 67 additions and 60 deletions

View file

@ -2688,7 +2688,7 @@ await fs.writeFile(localName, buf, { encoding: null });
public async getPdf({ pid, file }) {
const { min } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min, `BASIC GET (pdf): ${file}`);
try {
let data;
if (GBConfigService.get('STORAGE_NAME')) {
@ -2703,10 +2703,14 @@ await fs.writeFile(localName, buf, { encoding: null });
} else {
let packagePath = GBUtil.getGBAIPath(min.botId, `gbdrive`);
let filePath = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, file);
data = await fs.readFile(filePath, 'utf8');
data = new Uint8Array(Buffer.from(data, 'utf8'));
data = await fs.readFile(filePath);
data = new Uint8Array(data);
}
return await GBUtil.getPdfText(data);
} catch (error) {
GBLogEx.error(min, error);
return null;
}
}
public async setContext({ pid, text }) {
@ -2779,8 +2783,7 @@ await fs.writeFile(tempFilePath, imageBuffer);
ig.state.generateDevice(username);
await ig.account.login(username, password);
const imageBuffer = await fs.readFile(imagePath);
const publishResult = await ig.publish.photo(
{ file: imageBuffer, caption });
const publishResult = await ig.publish.photo({ file: imageBuffer, caption });
GBLogEx.info(min, `Image posted on IG: ${publishResult}`);
}
@ -2790,6 +2793,6 @@ await fs.writeFile(tempFilePath, imageBuffer);
ChatServices.usersMode[user.userSystemId] = mode;
GBLogEx.info(min, `LLM Mode (user.userSystemId) : ${mode}`);
GBLogEx.info(min, `LLM Mode (${user.userSystemId}): ${mode}`);
}
}

View file

@ -147,9 +147,8 @@ export class GBUtil {
}
}
public static async copyIfNewerRecursive(src, dest) {
if (!await GBUtil.exists(src)) {
if (!(await GBUtil.exists(src))) {
console.error(`Source path "${src}" does not exist.`);
return;
}
@ -157,8 +156,8 @@ export class GBUtil {
// Check if the source is a directory
if ((await fs.stat(src)).isDirectory()) {
// Create the destination directory if it doesn't exist
if (!await GBUtil.exists(dest)) {
fs.mkdir(dest, { recursive: true });
if (!(await GBUtil.exists(dest))) {
await fs.mkdir(dest, { recursive: true });
}
// Read all files and directories in the source directory
@ -169,21 +168,23 @@ export class GBUtil {
const destEntry = path.join(dest, entry);
// Recursively copy each entry
this.copyIfNewerRecursive(srcEntry, destEntry);
await this.copyIfNewerRecursive(srcEntry, destEntry);
}
} else {
// Source is a file, check if we need to copy it
if (await GBUtil.exists(dest)) {
const srcStat = await fs.stat(src);
const destStat = await fs.stat(dest);
// Copy only if the source file is newer than the destination file
if (srcStat.mtime > destStat.mtime) {
fs.cp(src, dest, { force: true });
await fs.cp(src, dest, { force: true });
}
} else {
// Destination file doesn't exist, so copy it
fs.cp(src, dest, { force: true });
await fs.cp(src, dest, { force: true });
}
}
}
@ -198,7 +199,6 @@ export class GBUtil {
}
public static async getPdfText(data): Promise<string> {
const pdf = await getDocument({ data }).promise;
let pages = [];
@ -229,6 +229,4 @@ export class GBUtil {
return urljoin(gbai, packageName ? packageName : `${botId}.${packageType}`);
}
}
}

View file

@ -1,8 +1,14 @@
TALK "What is the case number?"
HEAR caseNumber
text = GET "case.pdf"
HEAR cod
text = GET "case-" + cod + ".pdf"
IF text THEN
text = "Based on this document, answer the person's questions:\n\n" + text
SET CONTEXT text
SET ANSWER MODE "direct"
SET ANSWER MODE "document"
TALK "Case ${cod} loaded. You can ask me anything about the case or request a summary in any way you need."
TALK "Case ${caseNumber} loaded. You can ask me anything about the case or request a summary in any way you need."
ELSE
TALK "The case was not found, please try again."
END IF