mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-04-28 03:41:58 +00:00
code interpreter: support variadic console.log (#3371)
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
parent
22f6a7f1bc
commit
e2541a24b3
@ -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
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <QThread>
|
||||
#include <QVariant>
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
|
||||
QString CodeInterpreter::run(const QList<ToolParam> ¶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);
|
||||
|
Loading…
Reference in New Issue
Block a user