2
0

tokenization.ts 493 B

123456789101112131415161718192021
  1. import ollama from '../../src/browser.js'
  2. async function main() {
  3. // Tokenize some text
  4. const tokResponse = await ollama.tokenize({
  5. model: 'llama3.2',
  6. text: 'Hello, how are you?'
  7. })
  8. console.log('Tokens from model:', tokResponse.tokens)
  9. // Detokenize the tokens back to text
  10. const detokResponse = await ollama.detokenize({
  11. model: 'llama3.2',
  12. tokens: tokResponse.tokens
  13. })
  14. console.log('Text from model:', detokResponse.text)
  15. }
  16. main().catch(console.error)