leancodepl / arb_translate

A command-line tool for automatically adding missing message translations to ARB files using Google Gemini LLM by LeanCode
https://leancode.co
Apache License 2.0
47 stars 5 forks source link

FormatException: Unhandled CitationMetadata format #1

Closed clemortel closed 6 months ago

clemortel commented 7 months ago

Hi LeanCode team,

Very good work, thank for this package !

So i'm in France, with following configuration :

`Unhandled exception: FormatException: Unhandled CitationMetadata format

0 _parseCitationMetadata (package:google_generative_ai/src/api.dart:576:10)

1 _parseCandidate (package:google_generative_ai/src/api.dart:514:15)

2 MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)

3 ListIterator.moveNext (dart:_internal/iterable.dart:354:26)

4 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)

5 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)

6 new List.of (dart:core-patch/array_patch.dart:39:18)

7 ListIterable.toList (dart:_internal/iterable.dart:224:7)

8 parseGenerateContentResponse (package:google_generative_ai/src/api.dart:470:41)

9 GenerativeModel.generateContent (package:google_generative_ai/src/model.dart:127:14)

#10 GeminiTranslationDelegate._translateBatch (package:arb_translate/src/translation_delegates/gemini_translation_delegate.dart:130:21) #11 Future.wait. (dart:async/future.dart:523:21) #12 GeminiTranslationDelegate.translate (package:arb_translate/src/translation_delegates/gemini_translation_delegate.dart:65:28) #13 _translateBundle (package:arb_translate/src/translate.dart:73:25) #14 translate (package:arb_translate/src/translate.dart:38:5) #15 main (file:///Users/clem/.pub-cache/hosted/pub.dev/arb_translate-0.0.3/bin/arb_translate.dart:49:3) ` My Vertex API is enable and I've tried to change region and increase quotas Thanks in advance for your help !
RobertOdrowaz commented 7 months ago

Hi, thanks for reporting this issue. It seems that Gemini provides citations for some messages and the parsing of those citations fails. Could you try to find out which messages in your arb_fr.arb cause it to fail? It would help me with reproducing it

clemortel commented 7 months ago

I wanted to try again, but now i have another exception `Unhandled exception: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

0 GenerativeModel.generateContent (package:google_generative_ai/src/model.dart:130:9)

#1 GeminiTranslationDelegate._translateBatch (package:arb_translate/src/translation_delegates/gemini_translation_delegate.dart:130:21) #2 Future.wait. (dart:async/future.dart:523:21) #3 GeminiTranslationDelegate.translate (package:arb_translate/src/translation_delegates/gemini_translation_delegate.dart:65:28) #4 _translateBundle (package:arb_translate/src/translate.dart:73:25) #5 translate (package:arb_translate/src/translate.dart:38:5) #6 main (file:///Users/clem/.pub-cache/hosted/pub.dev/arb_translate-0.0.3/bin/arb_translate.dart:49:3) ` I've tried gcloud auth login, and regenerate api key
RobertOdrowaz commented 7 months ago

It looks like there is an issue with your token. How are you providing the token? With envvar, l10n.yaml or command argument? Can you try using a command argument arb_translate --api-key $(gcloud auth print-access-token)?

*If you were using arb-translate-api-key in l10n.yaml for API key you have to remove it because it has higher priority than the command argument.

clemortel commented 7 months ago

I was using envvar, now it work with the command argument, thanks

I have found messages causing problems, it's all messages containing placeholders

RobertOdrowaz commented 7 months ago

Can you please send me an example and verify that an ARB file with only this example fails as well?

{
  "yourExample": "Your example... {placeholder}",
  @"yourExample": {
    ...
  }
}
clemortel commented 7 months ago

Her is my code example not working { "@@locale": "fr", "groupMemberAddDialogContent": "Ajouter {pseudo} à", "@groupMemberAddDialogContent": { "description": "Content of the dialog when try to add member", "placeholders": { "pseudo": { "type": "String", "example": "Diseedant" } } } }

RobertOdrowaz commented 7 months ago

Thank you for the example. I was able to reproduce the problem. The issue is upstream in the google_generative_ai package. I have created an issue there (https://github.com/google/generative-ai-dart/issues/75) and I will open a PR shortly to fix it. I will also create a branch here with dependency on the fixed version of google_generative_ai unit the fix is released by Google on pub

RobertOdrowaz commented 7 months ago

It was a bit harder than I expected there is also a small difference between vertex ai API and Gemini API in citations but I've implemented the temporary workaround. Try using the version from git.

  1. Deactivate the pub version
    dart pub global deactivate arb_translate
  2. Activate the git version
    dart pub global activate -sgit https://github.com/leancodepl/arb_translate.git --git-ref citation-source-parsing-issue-workaround
clemortel commented 7 months ago

Thanks for the fast workaround, however i have now another problem : Provided API key is not valid I've tried to regenerate one and tried with l10.Yaml file and the --api-key also

RobertOdrowaz commented 7 months ago

Please send me a screenshot showing the command you are using (with --api-key) and the result

clemortel commented 7 months ago

Capture d’écran 2024-02-16 à 19 54 33

RobertOdrowaz commented 7 months ago

Can you try calling exactly this?

arb_translate --api-key $(gcloud auth print-access-token)
clemortel commented 7 months ago

Same : Capture d’écran 2024-02-16 à 20 45 27

clemortel commented 6 months ago

Any news on this ? The package still seem very awesome if working

leanderSen33 commented 6 months ago

I am having the same problem, "Translating 1 terms for locale de... Provided API key is not valid" And I used arb_translate --api-key $(gcloud auth print-access-token). I am in Germany.

RobertOdrowaz commented 6 months ago

I've fixed the original citation parsing issue and I think I've found the source and fixed the invalid API key. Setting model provider in l10n.yaml wasn't working correctly so arb_translate was trying to call Gemini API with Vertex AI key. Check out the new 0.1.2 version