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
55 stars 5 forks source link

Failed to parse response #9

Closed dumazy closed 6 months ago

dumazy commented 7 months ago

Issue

I cannot seem to get arb_translate to work anymore. I'm using 0.1.3.

Translating 4 terms for locale bg...
Failed to parse response for 1/1, retrying 1/5...
Failed to parse response for 1/1, retrying 2/5...
Failed to parse response for 1/1, retrying 3/5...
Failed to parse response for 1/1, retrying 4/5...
Failed to parse response for 1/1, retrying 5/5...

It's detecting the missing translations and seems to be calling the API, but cannot parse the response. I couldn't find any additional logs about this.

Config

# l10n.yaml

arb-dir: lib/l10n
template-arb-file: intl_en.arb
arb-translate-context: "construction and installation ERP software"
arb-translate-vertex-ai-project-url: https://europe-west1-aiplatform.googleapis.com/v1/projects/<our-project-id>/locations/europe-west1/publishers/google/models # replaced our real project id here for reporting this issue
arb-translate-model-provider: vertex-ai
arb-translate-exclude-locales: ["sq"] # Vertex AI does not support Albanian at the moment

Command & API key

I first fetched a new API key with gcloud auth login and gcloud auth print-access-token. If I tried to run the command with an old token, it gave an appropriate error message about that.

$ arb_translate --api-key <api-key>

Since 0.1.3?

This happened after installing version 0.1.3, but it also has been a few weeks since I ran it on the previous version.

$ dart pub global activate arb_translate 
Package arb_translate is currently active at version 0.1.3.
The package arb_translate is already activated at newest available version.
To recompile executables, first run `dart pub global deactivate arb_translate`.
Installed executable arb_translate.
Activated arb_translate 0.1.3.

Other attempts

I've also tried with removing the new arb-translate-exclude-locales option but I've got the same result. Also adding "bg" to the excluded languages didn't help. It properly skipped "bg" but had the same issue with "de".

I've also tried removing the new labels and just adding one simple label:

"certificates": "Certificates"

but it also failed to parse for this single label.

m1n093 commented 7 months ago

Hello, i have the same issue

I noticed that the response often contains some text before the JSON file structure.

For example:

'''
arb
{
  "certificates": "Certificates"
}
'''

or

'''
json
{
  "certificates": "Certificates"
}
'''

Can you add a function that will correctly extract the JSON?

Even such a simple improvement makes a significant difference.

  String _extractJson(String response) {
          int startIndex = response.indexOf('{');
          int endIndex = response.lastIndexOf('}');

          return response.substring(startIndex, endIndex + 1);
  }

I've also noticed that sometimes the response has an incorrect JSON format, for example, missing commas like in the attachment.

image

...but it's ok that it trying to retrieve the response again.

andrewpmoore commented 7 months ago

I'm seeing the same, I first tried it on 0.1.2 which used to work fine and then upgraded to 0.1.3 to see if it fixed it, so I don't think it's something introduced with 0.1.3 and more likely a change in the response coming back from gemini

RobertOdrowaz commented 7 months ago

Thanks for reporting. I will look into making error handling more advanced and robust

antonkarliner commented 6 months ago

Hey! I can also confirm this issue, happens constantly. I hope this will be fixed soon, it's a great tool otherwise, but currently the usage is quite frustrating.

leanderSen33 commented 6 months ago

Same here! it's a pity that I can't use this tool anymore.

RobertOdrowaz commented 6 months ago

Yep, seems like this was caused by a change in Gemini. What's interesting Vertex AI and standard Gemini API seem to behave a bit differently in this case. The Gemini API was returning a correct result more often. Either way I've added the solution proposed by @m1n093 and an instruction in the prompt to return only JSON and this should solve most of the problems. Check out the new version 0.1.4

calcitem commented 6 months ago

Hello!

arb_translate: ^1.0.0

Do a Git commit: https://github.com/calcitem/Sanmill/commit/1a91f224b22ffd26224fba1e4cedf403cad923e8

And then run arb_translate.

Error Message:

Translating 1 terms for locale af...
Instance of 'NoResponseException'
Placeholder validation failed for batch 1/1, retrying 1/5...
Instance of 'NoResponseException'
Placeholder validation failed for batch 1/1, retrying 2/5...
Instance of 'NoResponseException'
Placeholder validation failed for batch 1/1, retrying 3/5...
Instance of 'NoResponseException'
Placeholder validation failed for batch 1/1, retrying 4/5...
Instance of 'NoResponseException'
Placeholder validation failed for batch 1/1, retrying 5/5...
Instance of 'NoResponseException'
Placeholder validation failed for batch 1/1, retrying 6/5...
Failed to get a response from the model

l10n.yaml:

arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-dir: lib/generated/intl/
output-localization-file: l10n.dart
output-class: S
untranslated-messages-file: untranslated-messages-file.txt
# use-deferred-loading: true #enable for web support
synthetic-package: false
nullable-getter: false
arb-translate-context: "Mill (Nine Men's Morris) Game"

Is this the similar issue? Thanks!