LJTSG commited on
Commit
1a8f20a
Β·
verified Β·
1 Parent(s): 54064eb

Upload mamba_runtime.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. mamba_runtime.js +5 -5
mamba_runtime.js CHANGED
@@ -757,11 +757,11 @@ class MambaRuntime {
757
  }
758
 
759
  // ── Tokenize/detokenize via server ──────────────────────────────────────
760
- async tokenize(text) {
761
  const resp = await fetch('/tokenize', {
762
  method: 'POST',
763
  headers: { 'Content-Type': 'application/json' },
764
- body: JSON.stringify({ text }),
765
  });
766
  const data = await resp.json();
767
  return data.result;
@@ -778,14 +778,14 @@ class MambaRuntime {
778
  }
779
 
780
  // ── Generate text ──────────────────────────────────────────────────────
781
- async generate(prompt, maxTokens = 100, temperature = 0.75, onToken = null) {
782
  if (!this.ready) throw new Error('Call loadWeights() first');
783
  this._allocateScratch();
784
 
785
  console.log('[mamba] generate:', prompt, 'max_tokens:', maxTokens);
786
 
787
- // Tokenize the prompt
788
- const promptTokens = await this.tokenize(prompt);
789
  console.log(`[mamba] prompt tokens (${promptTokens.length}):`, promptTokens);
790
 
791
  // Process prompt tokens through forward pass to build SSM state
 
757
  }
758
 
759
  // ── Tokenize/detokenize via server ──────────────────────────────────────
760
+ async tokenize(text, system = '') {
761
  const resp = await fetch('/tokenize', {
762
  method: 'POST',
763
  headers: { 'Content-Type': 'application/json' },
764
+ body: JSON.stringify({ text, system }),
765
  });
766
  const data = await resp.json();
767
  return data.result;
 
778
  }
779
 
780
  // ── Generate text ──────────────────────────────────────────────────────
781
+ async generate(prompt, maxTokens = 100, temperature = 0.75, onToken = null, system = '') {
782
  if (!this.ready) throw new Error('Call loadWeights() first');
783
  this._allocateScratch();
784
 
785
  console.log('[mamba] generate:', prompt, 'max_tokens:', maxTokens);
786
 
787
+ // Tokenize the prompt (with optional system prompt)
788
+ const promptTokens = await this.tokenize(prompt, system);
789
  console.log(`[mamba] prompt tokens (${promptTokens.length}):`, promptTokens);
790
 
791
  // Process prompt tokens through forward pass to build SSM state