From 63ff3e4c1f469ef79e0b22fd5e196585e0b832c2 Mon Sep 17 00:00:00 2001 From: Sweaterdog Date: Sat, 7 Jun 2025 17:03:16 -0700 Subject: [PATCH] Update gpt.js Fixed some logging --- src/models/gpt.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/models/gpt.js b/src/models/gpt.js index 4fd72fa..3c9bfde 100644 --- a/src/models/gpt.js +++ b/src/models/gpt.js @@ -87,7 +87,25 @@ export class GPT { if (typeof res === 'string') { res = res.replace(//g, '').replace(/<\/thinking>/g, ''); } - log(JSON.stringify(messages), res); + + if (imageData) { + const conversationForLogVision = [{ role: "system", content: systemMessage }].concat(turns); + let visionPromptText = ""; + if (turns.length > 0) { + const lastTurn = turns[turns.length - 1]; + if (lastTurn.role === 'user') { + if (typeof lastTurn.content === 'string') { + visionPromptText = lastTurn.content; + } else if (Array.isArray(lastTurn.content)) { + const textPart = lastTurn.content.find(part => part.type === 'text'); + if (textPart) visionPromptText = textPart.text; + } + } + } + logVision(conversationForLogVision, imageData, res, visionPromptText); + } else { + log(JSON.stringify([{ role: "system", content: systemMessage }].concat(turns)), res); + } return res; } @@ -107,7 +125,8 @@ export class GPT { const res = await this.sendRequest(imageFormattedTurns, systemMessage); if (imageBuffer && res) { - logVision(original_turns, imageBuffer, res, systemMessage); + // The conversationHistory for logVision should be the state *before* this specific vision interaction's prompt was added. + logVision([{ role: "system", content: systemMessage }].concat(original_turns), imageBuffer, res, systemMessage); } return res; }