react-native-executorch
Version:
An easy way to run AI models in react native with ExecuTorch
25 lines (24 loc) • 713 B
JavaScript
;
export const parseToolCall = message => {
try {
const unparsedToolCalls = message.match('\\[(.|\\s)*\\]');
if (!unparsedToolCalls) {
throw Error('Regex did not match array.');
}
const parsedMessage = JSON.parse(unparsedToolCalls[0]);
const results = [];
for (const tool of parsedMessage) {
if ('name' in tool && typeof tool.name === 'string' && 'arguments' in tool && tool.arguments !== null && typeof tool.arguments === 'object') {
results.push({
toolName: tool.name,
arguments: tool.arguments
});
}
}
return results;
} catch (e) {
console.error(e);
return [];
}
};
//# sourceMappingURL=llm.js.map