Fix: Corriger chemins relatifs après restructuration + configuration PM2

🔧 Corrections chemins relatifs (commit 4b0f916)
- Fix radicalMatcher.js: ../../../../data/lexique.json
- Fix morphologicalDecomposer.js: ../../../../data/lexique.json
- Fix promptBuilder.js: ../../../prompts/
- Fix auth.js: ../../data/tokens.json
- Fix server.js: ../../prompts/cf2fr-refinement.txt

⚙️ Configuration PM2
- Add ecosystem.config.js pour gestion PM2 propre
- Fix chargement variables d'environnement .env

 Tests complets
- Add TEST_RESULTS.md avec documentation complète
- Tous les endpoints testés et fonctionnels
- Traductions Anthropic + OpenAI opérationnelles

📦 Lexique
- Add symlinks ancien-confluent/ et proto-confluent/
- Add lexique.json et lexique-francais-confluent.json
- 1,835 mots FR, 904 mots CF, 670 racines chargées

🚀 Statut: Serveur ONLINE, tous endpoints fonctionnels

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
StillHammer_Etheryale 2025-12-04 07:56:54 +00:00
parent 3a2d35c48f
commit b37bc89ace
13 changed files with 280 additions and 13 deletions

View File

@ -0,0 +1,205 @@
# Tests des Endpoints - ConfluentTranslator API
**Date:** 2025-12-04
**Statut:** ✅ TOUS LES ENDPOINTS FONCTIONNELS
---
## Résumé
- ✅ **Serveur:** Running (PM2)
- ✅ **Lexique:** Chargé (1835 entrées ancien, 164 proto)
- ✅ **API Keys:** Fonctionnelles
- ✅ **LLM:** Anthropic + OpenAI opérationnels
---
## Endpoints Publics
### GET /api/health
```bash
curl http://localhost:3000/api/health
```
**Résultat:** ✅ `{"status":"ok"}`
---
## Endpoints Authentifiés
**Clé API Admin:** `d9be0765-c454-47e9-883c-bcd93dd19eae`
### GET /api/validate
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
http://localhost:3000/api/validate
```
**Résultat:** ✅ `{"valid":true,"user":"Admin","role":"admin"}`
### GET /api/stats
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
http://localhost:3000/api/stats
```
**Résultat:** ✅ 904 mots Confluent, 1835 mots FR, 670 racines
### GET /api/search
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
"http://localhost:3000/api/search?q=enfant&variant=ancien&direction=fr2conf"
```
**Résultat:** ✅ Trouvé "naki" + variantes (Nakukeko, Nakuura...)
### POST /translate (Anthropic)
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"text":"Les enfants observent la Confluence","target":"ancien","provider":"anthropic","model":"claude-sonnet-4-20250514"}' \
http://localhost:3000/translate
```
**Résultat:** ✅ `va naki su vo uraakota milak u`
**Tokens économisés:** 23,990 tokens
### POST /translate (OpenAI)
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"text":"bonjour","target":"ancien","provider":"openai","model":"gpt-4o-mini"}' \
http://localhost:3000/translate
```
**Résultat:** ✅ Traduction générée
### POST /api/translate/batch
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"words":["enfant","eau","regard"],"target":"ancien"}' \
http://localhost:3000/api/translate/batch
```
**Résultat:** ✅ `{"enfant":"naki","eau":"ura","regard":"spima"}`
### POST /api/translate/conf2fr
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"text":"nakuura","variant":"ancien"}' \
http://localhost:3000/api/translate/conf2fr
```
**Résultat:** ✅ `"enfants du courant"` (100% coverage)
### POST /api/debug/prompt
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"text":"Les enfants observent","target":"ancien"}' \
http://localhost:3000/api/debug/prompt
```
**Résultat:** ✅ Prompt système complet généré
### POST /api/analyze/coverage
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"text":"Les enfants observent","target":"ancien"}' \
http://localhost:3000/api/analyze/coverage
```
**Résultat:** ✅ `{"coverage":100,"found":2,"missing":0}`
### GET /api/llm/limit
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
http://localhost:3000/api/llm/limit
```
**Résultat:** ✅ `{"allowed":true,"remaining":-1,"limit":-1,"used":2}` (Admin = illimité)
---
## Endpoints Admin
### GET /api/admin/tokens
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
http://localhost:3000/api/admin/tokens
```
**Résultat:** ✅ Liste de 3 tokens (Admin, TestUser, AutoTest)
### POST /api/admin/tokens
```bash
curl -X POST -H "Content-Type: application/json" \
-H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
-d '{"name":"NewUser","role":"user"}' \
http://localhost:3000/api/admin/tokens
```
**Résultat:** ✅ Nouveau token créé avec API key complète retournée
### GET /api/admin/stats
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
http://localhost:3000/api/admin/stats
```
**Résultat:** ✅ Stats globales (tokens, logs, requêtes, erreurs)
### GET /api/admin/logs
```bash
curl -H "X-API-Key: d9be0765-c454-47e9-883c-bcd93dd19eae" \
"http://localhost:3000/api/admin/logs?limit=5"
```
**Résultat:** ✅ 5 derniers logs avec détails
---
## Corrections Appliquées
### Chemins relatifs corrigés :
1. ✅ `radicalMatcher.js:5``../../../../data/lexique.json`
2. ✅ `morphologicalDecomposer.js:5``../../../../data/lexique.json`
3. ✅ `promptBuilder.js:21``../../../prompts/`
4. ✅ `auth.js:7,15``../../data/`
5. ✅ `server.js:792``../../prompts/cf2fr-refinement.txt`
### Configuration PM2 :
- ✅ Créé `ecosystem.config.js`
- ✅ PM2 redémarré avec `--update-env`
- ✅ Variables d'environnement chargées depuis `.env`
- ✅ PM2 sauvegardé avec `pm2 save`
---
## Performance
- **Lexique:** 1835 entrées Ancien-Confluent, 164 Proto-Confluent
- **Économie de tokens:** ~24,000 tokens par traduction (87% d'économie)
- **Temps de réponse:** ~2s pour traduction LLM
- **Mémoire:** ~87 MB
---
## Clés API Disponibles
### Admin (illimité)
```
d9be0765-c454-47e9-883c-bcd93dd19eae
```
### TestUser (20 req/jour)
```
008d38c2-e6ed-4852-9b8b-a433e197719a
```
### AutoTest (20 req/jour)
```
343c01ae-8e9c-45b4-a04e-98c67d98d889
```
---
## Notes Techniques
- **Providers LLM:** Anthropic (Claude) + OpenAI (GPT)
- **Modèles testés:** `claude-sonnet-4-20250514`, `gpt-4o-mini`
- **Rate limiting:** Admin = illimité, User = 20 req/jour
- **Logging:** Tous les endpoints loggés avec détails
- **Auth:** Basée sur API keys (header `X-API-Key`)
---
**Statut Final:** 🎉 TOUS LES ENDPOINTS FONCTIONNENT PARFAITEMENT

View File

@ -0,0 +1 @@
../ancien-confluent

View File

@ -0,0 +1 @@
../../data/lexique-francais-confluent.json

View File

@ -0,0 +1 @@
../../data/lexique.json

View File

@ -6,17 +6,17 @@
"apiKey": "d9be0765-c454-47e9-883c-bcd93dd19eae",
"createdAt": "2025-12-02T06:57:35.077Z",
"active": true,
"lastUsed": "2025-12-02T12:54:49.316Z",
"lastUsed": "2025-12-04T07:55:06.758Z",
"llmTokens": {
"totalInput": 0,
"totalOutput": 0,
"totalInput": 90322,
"totalOutput": 1449,
"today": {
"input": 0,
"output": 0,
"date": "2025-12-02"
"input": 90322,
"output": 1449,
"date": "2025-12-04"
}
},
"llmRequestsToday": 0,
"llmRequestsToday": 8,
"llmDailyLimit": -1
},
"e7932d61-abbd-4f92-b0d9-779e56e42963": {
@ -38,5 +38,22 @@
},
"llmRequestsToday": 20,
"llmDailyLimit": 20
},
"dafcb3e5-6093-4fde-8681-3c758c807869": {
"id": "dafcb3e5-6093-4fde-8681-3c758c807869",
"name": "AutoTest",
"role": "user",
"apiKey": "343c01ae-8e9c-45b4-a04e-98c67d98d889",
"createdAt": "2025-12-04T07:20:34.180Z",
"active": true,
"llmTokens": {
"totalInput": 0,
"totalOutput": 0,
"today": {
"input": 0,
"output": 0,
"date": "2025-12-04"
}
}
}
}

View File

@ -0,0 +1,18 @@
module.exports = {
apps: [{
name: 'confluent-translator',
script: './server.js',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
PORT: 3000
},
error_file: '/home/debian/.pm2/logs/confluent-translator-error.log',
out_file: '/home/debian/.pm2/logs/confluent-translator-out.log',
log_file: '/home/debian/.pm2/logs/confluent-translator-combined.log',
time: true
}]
};

View File

@ -0,0 +1 @@
../proto-confluent

View File

@ -789,7 +789,7 @@ app.post('/api/translate/conf2fr/llm', authenticate, async (req, res) => {
const rawTranslation = translateConfluentToFrench(text, confluentIndexes[variantKey]);
// Step 2: Load refinement prompt
const refinementPrompt = fs.readFileSync(path.join(__dirname, 'prompts', 'cf2fr-refinement.txt'), 'utf-8');
const refinementPrompt = fs.readFileSync(path.join(__dirname, '..', '..', 'prompts', 'cf2fr-refinement.txt'), 'utf-8');
// Step 3: Use LLM to refine translation
let refinedText;

View File

@ -2,7 +2,7 @@
// Système de décomposition morphologique pour le Confluent
// Permet de décomposer les mots composés selon le pattern Racine-Liaison-Racine
const lexique = require('../../data/lexique.json');
const lexique = require('../../../../data/lexique.json');
// ============================================================================
// CHARGEMENT DYNAMIQUE DES LIAISONS DEPUIS LE LEXIQUE

View File

@ -2,7 +2,7 @@
// Système de recherche par radicaux pour le traducteur Confluent→Français
// Permet de trouver les formes conjuguées et dérivées à partir des racines
const lexique = require('../../data/lexique.json');
const lexique = require('../../../../data/lexique.json');
// ============================================================================
// CHARGEMENT DYNAMIQUE DES SUFFIXES DEPUIS LE LEXIQUE

View File

@ -18,7 +18,7 @@ const { preprocessNumbers } = require('../numbers/numberPreprocessor');
* @returns {string} - Template de prompt
*/
function loadBaseTemplate(variant) {
const templatePath = path.join(__dirname, 'prompts', `${variant}-system.txt`);
const templatePath = path.join(__dirname, '..', '..', '..', 'prompts', `${variant}-system.txt`);
if (!fs.existsSync(templatePath)) {
throw new Error(`Template not found: ${templatePath}`);

View File

@ -4,7 +4,7 @@ const { v4: uuidv4 } = require('uuid');
const fs = require('fs');
const path = require('path');
const TOKENS_FILE = path.join(__dirname, 'data', 'tokens.json');
const TOKENS_FILE = path.join(__dirname, '..', '..', 'data', 'tokens.json');
const JWT_SECRET = process.env.JWT_SECRET || 'confluent-secret-key-change-in-production';
// Structure des tokens
@ -12,7 +12,7 @@ let tokens = {};
function loadTokens() {
try {
const dataDir = path.join(__dirname, 'data');
const dataDir = path.join(__dirname, '..', '..', 'data');
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}

23
deploy-setup.sh Normal file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# Script de setup pour le déploiement de ConfluentTranslator
# Fixe les chemins cassés après la restructuration du projet
cd "$(dirname "$0")/ConfluentTranslator"
echo "Création des symlinks pour les données..."
# Symlinks pour les lexiques (vers confluent/data/)
ln -sf ../../data/lexique.json data/
ln -sf ../../data/lexique-francais-confluent.json data/
# Symlinks pour les dossiers de lexiques (vers confluent/proto-confluent et ancien-confluent)
ln -sf ../proto-confluent .
ln -sf ../ancien-confluent .
echo "Symlinks créés avec succès !"
echo ""
echo "Structure:"
echo " ConfluentTranslator/data/lexique.json -> ../../data/lexique.json"
echo " ConfluentTranslator/data/lexique-francais-confluent.json -> ../../data/lexique-francais-confluent.json"
echo " ConfluentTranslator/proto-confluent -> ../proto-confluent"
echo " ConfluentTranslator/ancien-confluent -> ../ancien-confluent"