Refactor DevChat log insertion to handle large values

This commit is contained in:
bobo.yang 2024-05-27 13:41:13 +08:00
parent bf0c0b2109
commit ce7f7e7ec8
2 changed files with 10 additions and 2 deletions

View File

@ -356,9 +356,17 @@ class DevChat {
"response_tokens": 1,
...parent? {"parent": parent} : {}
};
const insertValue = JSON.stringify(logData);
let insertValueOrFile = insertValue;
if (insertValue.length > 4 * 1024) {
const tempDir = os.tmpdir();
const tempFile = path.join(tempDir, 'devchat_log_insert.json');
await fs.promises.writeFile(tempFile, insertValue);
insertValueOrFile = tempFile;
}
// build args for log insert
const args = ["-m", "devchat", "log", "--insert", JSON.stringify(logData)];
const args = ["-m", "devchat", "log", "--insert", insertValueOrFile];
const {code, stdout, stderr} = await this.runCommand(args);

2
tools

@ -1 +1 @@
Subproject commit ab2abbdde678cf757707dc540b81efb465e7b3f5
Subproject commit b80f6402b6895d022a56598e9285baa39ad92670