Naar hoofdinhoud gaan

Een Aangepaste Methode als API Aanbieden

champollion's api methode stelt u in staat om elk vertaalpaar te koppelen aan een extern HTTP-eindpunt. Dit is hoe u pipelines integreert die te complex zijn voor een enkele LLM-prompt — morfologische analysatoren, eindige-toestandstransducers (FST's), meerstaps LLM-ketens, of elke aangepaste onderzoeksmethode die u heeft ontwikkeld.

Waarom een API-service?

Sommige vertaalpipelines kunnen niet worden uitgevoerd binnen een eenvoudige prompt-responscyclus:

PipelinestapVoorbeeld
Morfologische decompositiePolysynthetische woorden opsplitsen in morfemen vóór vertaling
FST-validatieUitvoer afwijzen die fonologische of morfologische regels schendt
Meerstaps LLM-ketensGenereer → verifieer → corrigeer-cycli met verschillende modellen
WoordenboekraadplegingRaadpleeg een samengesteld tweetalig woordenboek tijdens de pipeline
Mens-in-de-lusOnzekere vertalingen in de wachtrij plaatsen voor beoordeling door een expert

De api methode behandelt uw pipeline als een zwarte doos — champollion verzendt bronreeksen, uw service retourneert vertalingen. Wat er intern gebeurt, is geheel aan u.

Architectuur

Uw Service Instellen

Uw API-service moet één eindpunt implementeren dat JSON accepteert en retourneert:

Aanvraagformaat

champollion verzendt deze exacte JSON-body (zie api.js):

POST /translate
Content-Type: application/json
Authorization: Bearer <CHAMPOLLION_API_KEY>

{
"source_locale": "en",
"target_locale": "crk",
"method": "crk-coached-v1",
"keys": {
"greeting": "Hello, welcome to our app",
"farewell": "Goodbye and thanks"
}
}
VeldTypeBeschrijving
source_localestringBCP 47 brontalcode
target_localestringBCP 47 doeltalcode
methodstringPluginnaam of "default"
keysobjectKoppeling van sleutel → bronreeks om te vertalen

### Response Format

Your service must return a `translations` object. An optional `meta` object can include cost and diagnostic info:

```json
{
"translations": {
"greeting": "tânisi, pê-kîwêw ôta",
"farewell": "ekosi mâka, kinanâskomitin"
},
"meta": {
"model": "my-custom-pipeline/v1",
"cost_usd": 0.0042,
"method": "decompose-translate-validate"
}
}
FieldTypeRequiredDescription
translationsobjectMap of key → translated string
metaobjectOptional metadata
meta.cost_usdnumberIf present, displayed in champollion's output
errorsobjectFor partial success (HTTP 207): map of key → { message }

Minimal Express Server

import express from 'express';

const app = express();
app.use(express.json());

/**
* champollion API contract:
*
* Request: { source_locale, target_locale, method, keys: { "key": "source" } }
* Response: { translations: { "key": "translated" }, meta: { ... } }
*/
app.post('/translate', async (req, res) => {
const { source_locale, target_locale, method, keys } = req.body;

const translations = {};

for (const [key, source] of Object.entries(keys)) {
// --- Your pipeline goes here ---
// Step 1: Morphological decomposition
const morphemes = await decompose(source, source_locale);

// Step 2: LLM translation with context
const draft = await llmTranslate(morphemes, target_locale);

// Step 3: FST validation
const validated = await fstValidate(draft, target_locale);

// Step 4: Post-processing (orthography normalization, etc.)
translations[key] = await postProcess(validated);
}

res.json({
translations,
meta: {
model: 'my-custom-pipeline/v1',
method: 'decompose-translate-validate',
},
});
});

app.listen(3001, () => {
console.log('Translation API running on http://localhost:3001');
});

Configuring champollion

Point a translation pair at your running service in champollion.config.json:

{
"inputLocale": "en",
"pairs": {
"en:crk": {
"method": "api",
"endpoint": "http://localhost:3001/translate",
"register": "Formal Plains Cree. Use SRO orthography."
}
}
}

Then run sync as usual:

npx champollion sync

champollion will POST your source strings to the endpoint and write the returned translations to crk.json.

Case Study: Plains Cree Pipeline

:::info Under Development The Plains Cree pipeline described below is under active development and is not yet running in production. Details here reflect the current design direction and may change as the project evolves. :::

The arena project demonstrates this pattern. Its Plains Cree pipeline uses:

  1. Morphological decomposition — Break polysynthetic Cree words into translatable morpheme chains
  2. LLM translation — Context-enriched GPT-4o translation with coaching data (SRO orthography rules, register instructions)
  3. FST validation — Finite-state transducer checks that outputs conform to Cree phonological rules
  4. Confidence scoring — Each translation gets a confidence score based on FST pass rate and dictionary coverage

The entire pipeline runs as a single HTTP endpoint that champollion calls via the api method.

Running Evaluations

After translating, you can evaluate output quality using the harness directly:

# Clone the harness
git clone https://github.com/gamedaysuits/arena.git
cd arena
pip install -e .

# Run the evaluation against your method's output
mt-eval run --corpus data/edtekla-dev-v1.json --submit

This produces structured evaluation records with chrF++, BLEU, and exact match scores that can be used as regression baselines.

Authentication

If your API requires authentication, set the apiKey field or use an environment variable:

{
"pairs": {
"en:crk": {
"method": "api",
"endpoint": "https://my-mt-service.example.com/translate",
"apiKey": "${CRK_API_KEY}"
}
}
}

Data Sovereignty & OCAP Principles

The api method is particularly important for Indigenous language communities. By self-hosting the translation pipeline, a community keeps full control over:

  • Proprietary coaching data — register instructions, orthography rules, and domain glossaries never leave community infrastructure.
  • Linguistic resources — curated dictionaries, FST grammars, and elder-verified translations remain under community ownership.
  • Access policies — the community decides who can call the endpoint and under what terms.

This aligns with OCAP® principles (Ownership, Control, Access, Possession), ensuring that sensitive language data is governed by the community rather than a third-party platform.

tip

Combine the api method with a private deployment (e.g., a community-hosted VM or on-prem server) for the strongest data-sovereignty posture. See Support a Low-Resource Language for a full walkthrough.

Cost Estimation

The api method returns null for cost estimation by default — your service controls pricing. If you want to provide cost transparency, have your API return a cost field in the metadata:

{
"translations": { "...": "..." },
"metadata": {
"cost": {
"estimatedCost": 0.0042,
"currency": "USD",
"source": "my-service-pricing"
}
}
}

Aanbevolen Werkwijzen

  1. Retourneer lege reeksen bij fouten — Retourneer de bronreeks niet als een "vertaling." Retourneer "" en de kwaliteitspoort van champollion zal dit opvangen. De sleutel wordt overgeslagen en opnieuw geprobeerd bij de volgende synchronisatie.
  2. Voeg betrouwbaarheidsscores toe — Als uw pipeline de kwaliteit kan inschatten, retourneer deze dan in de metadata. Dit helpt bij kwaliteitscontrole.
  3. Implementeer gezondheidscontroles — Voeg een GET /health eindpunt toe zodat champollion de verbinding kan verifiëren voordat een grote synchronisatie wordt gestart.
  4. Beperk doorvoer op een elegante manier — Als uw pipeline doorvoerlimieten heeft, retourneer dan 429 statuscodes. Het batchsysteem van champollion zal terugschakelen.
  5. Registreer alles — Meerstaps pipelines kunnen stilzwijgend mislukken. Registreer de invoer en uitvoer van elke stap voor foutopsporing.

Licentieverlening

Het api methodepatroon is volledig open — er zijn geen licentiebeperkingen op het inpakken van uw eigen vertaalpipeline als een HTTP-service. De arena is beschikbaar onder MIT-licentie voor referentie-implementaties.

Zie Ook