Skip to content

Commit b2f0135

Browse files
committed
Don't need a regex to determine the code interpreter call since we split immediately.
Signed-off-by: Adam Treat <[email protected]>
1 parent 5bf7f6c commit b2f0135

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

gpt4all-chat/src/chatmodel.h

+6-19
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,12 @@ class ChatItem : public QObject
256256
if (parser.startIndex() < 0)
257257
return value;
258258

259-
// Otherwise we only return the text before and any partial code interpreter code
259+
// Otherwise we only return the text before and any partial tool call
260260
const QString beforeToolCall = value.left(parser.startIndex());
261-
const QString toolCallString = value.mid(parser.startIndex());
262-
return beforeToolCall + codeInterpreterContent(toolCallString);
261+
return beforeToolCall;
263262
}
264263

265-
// For complete tool calls we only return content if it is code interpreter
264+
// For tool calls we only return content if it is the code interpreter
266265
if (type() == Type::ToolCall)
267266
return codeInterpreterContent(value);
268267

@@ -275,23 +274,11 @@ class ChatItem : public QObject
275274

276275
QString codeInterpreterContent(const QString &value) const
277276
{
278-
// Constants for identifying and formatting the code interpreter tool call
279-
static const QString prefix = ToolCallConstants::CodeInterpreterTag;
280-
281-
// Check if the tool call is a code interpreter tool call
282-
if (!value.startsWith(prefix))
283-
return QString();
284-
285-
// Regex to remove the tag and any surrounding whitespace
286-
static const QRegularExpression regex("^"
287-
+ ToolCallConstants::CodeInterpreterTag
288-
+ "\\s*|\\s*"
289-
+ ToolCallConstants::CodeInterpreterEndTag
290-
+ "$");
277+
ToolCallParser parser;
278+
parser.update(value);
291279

292280
// Extract the code
293-
QString code = value;
294-
code.remove(regex);
281+
QString code = parser.toolCall();
295282
code = code.trimmed();
296283

297284
QString result;

0 commit comments

Comments
 (0)