feat: add custom route to export data for LLM
Déploiement API PROD / build (push) Successful in 2m8s
Déploiement API PROD / deploy (push) Successful in 58s

This commit is contained in:
2026-06-11 19:07:18 +04:00
parent b565224fcd
commit a000af5c8b
4 changed files with 215 additions and 0 deletions
+36
View File
@@ -2,7 +2,43 @@
const { createCoreController } = require('@strapi/strapi').factories;
const VALID_LANGS = new Set(['fr', 'en', 'es', 'de', 'it'])
module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
async export(ctx) {
const { type = 'pairs', lang, format = 'jsonl' } = ctx.query
const langs = lang
? lang.split(',').map(l => l.trim()).filter(l => VALID_LANGS.has(l))
: null
if (lang && (!langs || langs.length === 0)) {
return ctx.badRequest('Langue(s) invalide(s). Valeurs acceptées : fr, en, es, de, it.')
}
if (!['pairs', 'instruct'].includes(type)) {
return ctx.badRequest('type invalide. Valeurs acceptées : pairs, instruct.')
}
const paroles = await strapi.service('api::parole.parole').fetchAllParoles()
const { metadata, pairs } = strapi.service('api::parole.parole').buildExport(paroles, type, langs)
if (format === 'json') {
return ctx.send({ metadata, data: pairs })
}
// JSONL : première ligne = métadonnées, suivies des exemples d'entraînement.
// Pour filtrer la ligne de métadonnées : jq 'select(._metadata | not)'
const lines = [
JSON.stringify({ _metadata: true, ...metadata }),
...pairs.map(p => JSON.stringify(p)),
]
ctx.set('Content-Type', 'application/x-ndjson')
ctx.set('Content-Disposition', `attachment; filename="pawol-nu-export-${Date.now()}.jsonl"`)
ctx.body = lines.join('\n')
},
async findOne(documentId) {
const parole = await strapi.documents('api::parole.parole').findOne({
documentId,