diff --git a/gpt4all-chat/CHANGELOG.md b/gpt4all-chat/CHANGELOG.md index 8ca1a2a6..6690582e 100644 --- a/gpt4all-chat/CHANGELOG.md +++ b/gpt4all-chat/CHANGELOG.md @@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] + +## Fixed - Fix the timeout error in code interpreter ([#3369](https://github.com/nomic-ai/gpt4all/pull/3369)) +- Fix code interpreter console.log not accepting multiple arguments ([#3371](https://github.com/nomic-ai/gpt4all/pull/3371)) ## [3.6.1] - 2024-12-20 diff --git a/gpt4all-chat/src/codeinterpreter.cpp b/gpt4all-chat/src/codeinterpreter.cpp index c33a40a3..c0c9ed93 100644 --- a/gpt4all-chat/src/codeinterpreter.cpp +++ b/gpt4all-chat/src/codeinterpreter.cpp @@ -5,6 +5,9 @@ #include #include +using namespace Qt::Literals::StringLiterals; + + QString CodeInterpreter::run(const QList ¶ms, qint64 timeout) { m_error = ToolEnums::Error::NoError; @@ -92,7 +95,25 @@ CodeInterpreterWorker::CodeInterpreterWorker() void CodeInterpreterWorker::request(const QString &code) { JavaScriptConsoleCapture consoleCapture; - QJSValue consoleObject = m_engine.newQObject(&consoleCapture); + QJSValue consoleInternalObject = m_engine.newQObject(&consoleCapture); + m_engine.globalObject().setProperty("console_internal", consoleInternalObject); + + // preprocess console.log args in JS since Q_INVOKE doesn't support varargs + auto consoleObject = m_engine.evaluate(uR"( + class Console { + log(...args) { + if (args.length && typeof args[0] === 'string') + throw new Error('console.log string formatting not supported'); + let cat = ''; + for (const arg of args) { + cat += String(arg); + } + console_internal.log(cat); + } + } + + new Console(); + )"_s); m_engine.globalObject().setProperty("console", consoleObject); const QJSValue result = m_engine.evaluate(code);