Problem/Motivation
Gemini seems really great on keeping the style also on translations. Rather use it.
Proposed resolution
Solution in merge code to follow.
Note: this integrates and solves #3502139: Gemini API error with empty stopSequences value
Gemini does not offer (yet) a specialized translateText method like DeepL does, so the chat method used by ai_translate can be used. Maybe this is superfluous, nonetheless it was a good exercise and Gemini can now be used with:
$translator = \Drupal::service('ai.provider')->createInstance('gemini');
$input = new TranslateTextInput($text, 'en', 'it');
/** @var \Drupal\ai\OperationType\TranslateText\TranslateTextOutput $translation */
$translation = $translator->translateText($input, 'models/gemini-1.5-pro', []);
return $translation->getNormalized();
or if set as default in AI settings with:
$providerConfig = $this->aiProviderManager->getDefaultProviderForOperationType('translate_text');
$provider = $this->aiProviderManager->createInstance($providerConfig['provider_id'], $providerConfig);
$translation = $provider->translateText(
new TranslateTextInput($input_text, $langFrom?->getId(), $langTo->getId()),
$providerConfig['model_id']
);
Remaining tasks
Add tests?
Comments
Comment #3
viappidu commentedPatch for composer
Comment #4
viappidu commentedPatch for composer
Comment #5
jibla commentedComment #6
jibla commentedClosing as duplicate/won't fix.
After reviewing this issue against the current state of the module (1.x branch), this feature request is no longer needed.
1. The AI module's ai_translate submodule already provides translation support for all chat-capable providers, including Gemini.
2. The stopSequences fix (referenced issue #3502139: Gemini API error with empty stopSequences value) has already been resolved on the 1.x branch.
Thank you @viappidu for the contribution effort.