Skip to content

Basic

A simple prompt and response using SystemLanguageModel and LanguageModelSession.

ts
import { SystemLanguageModel, LanguageModelSession } from "tsfm-sdk";

async function main() {
  const model = new SystemLanguageModel();
  const { available, reason } = await model.waitUntilAvailable();
  if (!available) {
    console.error("Model not available:", reason);
    model.dispose();
    return;
  }

  const session = new LanguageModelSession({
    instructions: "You are a concise assistant.",
  });

  const reply = await session.respond("What is the capital of France?");
  console.log("Response:", reply);

  session.dispose();
  model.dispose();
}

main().catch(console.error);

What This Shows

  1. Create a SystemLanguageModel and wait for availability
  2. Create a session with system instructions
  3. Generate a text response with respond()
  4. Dispose both session and model to free native resources

Released under the Apache 2.0 License.