Skip to content

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.

ターミナルウィンドウ
npm install @sakutto/core

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/v1

The model is not included in @sakutto/core. Obtaining the model and checking its license remain the responsibility of the server setup.

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.

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 Origin header
  • keep allowRemote: false in the client

Example startup:

ターミナルウィンドウ
npm install @sakutto/core
PFML3_URL=http://127.0.0.1:8080/v1 npm start
curl --json '{"text":"猫が窓のそばで眠っています。"}' http://127.0.0.1:4174/translate
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.