Use Node or a local server
With only @sakutto/core, you can send translation requests to your own local inference process instead of running inference in a browser. The target server must expose raw OpenAI-compatible /v1/completions for a PLaMo model. Chat completions are not used.
1. Install
Section titled “1. Install”npm install @sakutto/core2. Prepare a PLaMo server
Section titled “2. Prepare a PLaMo server”Start a server that can run PLaMo 3 Translate / PFML3 through raw completions, such as a recent llama.cpp llama-server, mlx_lm.server, or LM Studio. The examples use this loopback address:
http://127.0.0.1:8080/v1The model is not included in @sakutto/core. Obtaining the model and checking its license remain the responsibility of the server setup.
3. Create the translation client
Section titled “3. Create the translation client”import { createLocalServerTranslator } from '@sakutto/core/server';
const translator = createLocalServerTranslator( { baseUrl: 'http://127.0.0.1:8080/v1', model: 'pfnet/plamo-3-translate-0.8b', apiKey: '', timeoutMs: 120_000, allowRemote: false, parallel: 8, }, { src: 'ja', tgt: 'en' },);
const text = await translator.translateText('こんにちは');console.log(text);tgt is required. The defaults are form: 'polite' and priority 0. Use translator.translate() when you need streaming deltas and translateText() when final text is enough. Error chunks reject instead of returning source text as if it were a translation.
4. Wrap it in a small HTTP API
Section titled “4. Wrap it in a small HTTP API”The repository’s examples/node-server/server.mjs is a minimal loopback JSON server. Its important safeguards are:
- listen only on
127.0.0.1 - require
Content-Type: application/json - reject requests that carry a browser
Originheader - keep
allowRemote: falsein the client
Example startup:
npm install @sakutto/corePFML3_URL=http://127.0.0.1:8080/v1 npm startcurl --json '{"text":"猫が窓のそばで眠っています。"}' http://127.0.0.1:4174/translateBrowser SDK or local server?
Section titled “Browser SDK or local server?”| Setup | Best for |
|---|---|
@sakutto/core + local server |
You already operate an inference server, want Node.js batch processing, or want GPU management on the server side |
@sakutto/runtime-wllama + browser |
You want the app to be self-contained, offline inference on the user’s device, or no server operation |
For self-contained browser inference, continue to Translate and OCR in the browser.