Skip to content

Commit 6a90610

Browse files
committed
fix: support for long-string translations with AI - setup maxTokens as x2 from input length
1 parent 95e21e7 commit 6a90610

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ export default class I18nPlugin extends AdminForthPlugin {
409409
icon: 'flowbite:language-outline',
410410
// if optional `confirm` is provided, user will be asked to confirm action
411411
confirm: 'Are you sure you want to translate selected items?',
412-
state: 'selected',
413412
allowed: async ({ resource, adminUser, selectedIds, allowedActions }) => {
414413
console.log('allowedActions', JSON.stringify(allowedActions));
415414
return allowedActions.edit;
@@ -507,9 +506,11 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
507506
const resp = await this.options.completeAdapter.complete(
508507
prompt,
509508
[],
510-
300,
509+
prompt.length * 2,
511510
);
512511

512+
console.log(`🪲🔪LLM resp >> ${prompt.length}, <<${resp.content.length} :\n\n`, JSON.stringify(resp));
513+
513514

514515
if (resp.error) {
515516
throw new AiTranslateError(resp.error);
@@ -803,7 +804,9 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
803804

804805
if (params) {
805806
for (const [key, value] of Object.entries(params)) {
806-
result = result.replace(`{${key}}`, value);
807+
if (result) {
808+
result = result.replace(`{${key}}`, value);
809+
}
807810
}
808811
}
809812
return result;

0 commit comments

Comments
 (0)