From 80b22e6c2d058c4e77ad2e88c22cf8a0f65585e7 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Mon, 28 Apr 2025 11:39:18 -0700 Subject: [PATCH] Continue CGRs ignoring missing image dereferences. #733 This is an emergency workaround where formal correctness yields to an unbroken chat experience. --- .../aix/client/aix.client.chatGenerateRequest.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modules/aix/client/aix.client.chatGenerateRequest.ts b/src/modules/aix/client/aix.client.chatGenerateRequest.ts index 9937c3fb5..2b7ec4b4d 100644 --- a/src/modules/aix/client/aix.client.chatGenerateRequest.ts +++ b/src/modules/aix/client/aix.client.chatGenerateRequest.ts @@ -15,6 +15,7 @@ import type { AixAPIChatGenerate_Request, AixMessages_ModelMessage, AixMessages_ // configuration const MODEL_IMAGE_RESCALE_MIMETYPE = !Is.Browser.Safari ? 'image/webp' : 'image/jpeg'; const MODEL_IMAGE_RESCALE_QUALITY = 0.90; +const IGNORE_CGR_NO_IMAGE_DEREFERENCE = true; // set to false to raise an exception, otherwise the CGR will continue skipping the part // AIX <> Simple Text API helpers @@ -138,7 +139,12 @@ export async function aixCGR_ChatSequence_FromDMessagesOrThrow( case 'image_ref': // note, we don't resize, as the user image is resized following the user's preferences - uMsg.parts.push(await aixConvertImageRefToInlineImageOrThrow(uFragment.part, false)); + try { + uMsg.parts.push(await aixConvertImageRefToInlineImageOrThrow(uFragment.part, false)); + } catch (error: any) { + if (IGNORE_CGR_NO_IMAGE_DEREFERENCE) console.warn(`Image from the user missing in the chat generation request because: ${error?.message || error?.toString() || 'Unknown error'} - continuing without`); + else throw error; + } break; case 'doc': @@ -223,7 +229,12 @@ export async function aixCGR_ChatSequence_FromDMessagesOrThrow( */ const isLastAssistantMessage = _index === lastAssistantMessageIndex; const resizeMode = isLastAssistantMessage ? false : 'openai-low-res'; - modelMessage.parts.push(await aixConvertImageRefToInlineImageOrThrow(aFragment.part, resizeMode)); + try { + modelMessage.parts.push(await aixConvertImageRefToInlineImageOrThrow(aFragment.part, resizeMode)); + } catch (error: any) { + if (IGNORE_CGR_NO_IMAGE_DEREFERENCE) console.warn(`Image from the assistant missing in the chat generation request because: ${error?.message || error?.toString() || 'Unknown error'} - continuing without`); + else throw error; + } break; case 'tool_response':