countTokens method
Count tokens in text
Implementation
Future<int> countTokens(
VSCodeAdapter adapter,
String text, {
int timeoutSeconds = 120,
}) async {
final result = await adapter.sendRequest(
'executeScriptVce',
{
'script': '''
const models = await context.vscode.lm.selectChatModels({id: params.modelId});
if (models.length === 0) throw new Error('Model not found');
const count = await models[0].countTokens(params.text);
return count;
''',
'params': {'modelId': id, 'text': text},
},
scriptName: 'LanguageModelChat.countTokens',
timeout: Duration(seconds: timeoutSeconds),
);
return (_scriptValue(result, 'LanguageModelChat.countTokens') as num).toInt();
}