Skip to content

Commit

Permalink
Don't need a regex to determine the code interpreter call since we sp…
Browse files Browse the repository at this point in the history
…lit immediately.

Signed-off-by: Adam Treat <[email protected]>
  • Loading branch information
manyoso committed Dec 17, 2024
1 parent 5bf7f6c commit b2f0135
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions gpt4all-chat/src/chatmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,12 @@ class ChatItem : public QObject
if (parser.startIndex() < 0)
return value;

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

// For complete tool calls we only return content if it is code interpreter
// For tool calls we only return content if it is the code interpreter
if (type() == Type::ToolCall)
return codeInterpreterContent(value);

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

QString codeInterpreterContent(const QString &value) const
{
// Constants for identifying and formatting the code interpreter tool call
static const QString prefix = ToolCallConstants::CodeInterpreterTag;

// Check if the tool call is a code interpreter tool call
if (!value.startsWith(prefix))
return QString();

// Regex to remove the tag and any surrounding whitespace
static const QRegularExpression regex("^"
+ ToolCallConstants::CodeInterpreterTag
+ "\\s*|\\s*"
+ ToolCallConstants::CodeInterpreterEndTag
+ "$");
ToolCallParser parser;
parser.update(value);

// Extract the code
QString code = value;
code.remove(regex);
QString code = parser.toolCall();
code = code.trimmed();

QString result;
Expand Down

0 comments on commit b2f0135

Please sign in to comment.