Merge pull request #453 from devchat-ai/enhancement/combine-insert-retrieve-steps-#256

Streamline Log Insertion by Combining Insert and Retrieve Actions
This commit is contained in:
boob.yang 2024-02-09 09:34:09 +08:00 committed by GitHub
commit dc58a93bed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -283,8 +283,7 @@ class DevChat {
const responseData = this.parseOutData(stdout, false); const responseData = this.parseOutData(stdout, false);
let promptHash = ""; let promptHash = "";
if (saveToLog) { if (saveToLog) {
await this.logInsert(options.context, content, responseData.response, options.parent); const logs = await this.logInsert(options.context, content, responseData.response, options.parent);
const logs = await this.log({"maxCount": 1});
assertValue(!logs || !logs.length, "Failed to insert devchat log"); assertValue(!logs || !logs.length, "Failed to insert devchat log");
promptHash = logs[0]["hash"]; promptHash = logs[0]["hash"];
} }
@ -313,7 +312,7 @@ class DevChat {
} }
} }
async logInsert(contexts: string[] | undefined, request: string, response: string, parent: string | undefined): Promise<boolean> { async logInsert(contexts: string[] | undefined, request: string, response: string, parent: string | undefined): Promise<LogEntry[]> {
try { try {
// build log data // build log data
const llmModelData = await ApiKeyManager.llmModel(); const llmModelData = await ApiKeyManager.llmModel();
@ -357,11 +356,16 @@ class DevChat {
logger.channel()?.warn(`${stderr}`); logger.channel()?.warn(`${stderr}`);
} }
return true; const logs = JSON.parse(stdout.trim()).reverse();
for (const log of logs) {
log.response = log.responses[0];
delete log.responses;
}
return logs;
} catch (error: any) { } catch (error: any) {
logger.channel()?.error(`Failed to insert log: ${error.message}`); logger.channel()?.error(`Failed to insert log: ${error.message}`);
logger.channel()?.show(); logger.channel()?.show();
return false; return [];
} }
} }