From 85b2ade8b850a0d4d1e81968cac34827b0a62b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Rame=CC=81?= Date: Fri, 15 Mar 2024 13:34:25 +0100 Subject: [PATCH] chore(llm): adjust more precisely the fingerprint when it fails returning the right response format --- src/features/initiative.ts | 9 ++++++--- src/i18n/fr/common.json | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/features/initiative.ts b/src/features/initiative.ts index 0ad1879..0a67eba 100644 --- a/src/features/initiative.ts +++ b/src/features/initiative.ts @@ -38,6 +38,7 @@ import { WebsiteTemplateSchemaType, resultSchemaDefinition, } from '@etabli/src/gpt/template'; +import { getServerTranslation } from '@etabli/src/i18n'; import { llmResponseFormatError, tokensReachTheLimitError } from '@etabli/src/models/entities/errors'; import { LiteInitiativeMapSchema, LiteInitiativeMapSchemaType } from '@etabli/src/models/entities/initiative'; import { prisma } from '@etabli/src/prisma'; @@ -646,6 +647,10 @@ export async function feedInitiativesFromDatabase() { const initiativeGptTemplate = handlebars.compile(initiativeGptTemplateContent); + const { t } = getServerTranslation('common', { + lng: 'fr', + }); + // Since the underlying wappalyzer analysis per initiative map can take some time due to being in a Chromium environment // we parallelize hoping to save some time. But still, we take in considerations the LLM API rate limit const iterationLlmManagerApiCalls = 2; // One for the embeddings of the tools, and the other for the computation of the initiative sheet @@ -1051,9 +1056,7 @@ export async function feedInitiativesFromDatabase() { }), messageToAppend: failedDueToLlmResponseFormat > 0 - ? `C'est la ${ - failedDueToLlmResponseFormat === 1 ? 'deuxième' : `${failedDueToLlmResponseFormat + 1}ème` - } tentative car la dernière fois tu n'as pas respecté le format JSON attendu !` + ? t('llm.template.initiative.responseFormatFailures', { count: failedDueToLlmResponseFormat }) : undefined, }) ); diff --git a/src/i18n/fr/common.json b/src/i18n/fr/common.json index 6c4b652..9cd2613 100644 --- a/src/i18n/fr/common.json +++ b/src/i18n/fr/common.json @@ -81,6 +81,12 @@ "functionalUseCases": "casDUtilisationFonctionnels", "tools": "outilsUtilises" } + }, + "template": { + "initiative": { + "responseFormatFailures_one": "Sache que c'est la deuxième tentative car la dernière fois tu n'as pas respecté le format de réponse attendu ! (on veut un JSON avec les propriétés citées, sans commentaire ni note autour)", + "responseFormatFailures_other": "On te renvoie la même demande car les {{count}} dernières fois tu n'as toujours pas respecté le format JSON attendu (sans commentaire ni note autour). Fais attention à bien formater ta réponse." + } } } }