Resolve #3457200 "Ai translations submodule"
Closes #3457200
Merge request reports
Activity
added 1 commit
- 6914f1f4 - 3457200: Remove mentions of node as hard-coded entity type
- Resolved by Marcus Johansson
- Resolved by Marcus Johansson
- Resolved by Marcus Johansson
214 * Adding the translation in database and linking it to the original entity. 215 * 216 * @param \Drupal\Core\Entity\ContentEntityInterface $entity 217 * The entity object. 218 * @param string $target_language 219 * The target language. 220 * @param array $bundleFields 221 * An array of field name and their translation. 222 */ 223 public function insertTranslation( 224 ContentEntityInterface $entity, 225 string $target_language, 226 array $bundleFields, 227 ) { 228 if ($entity->hasTranslation($target_language)) { 229 return; - Resolved by Marcus Johansson
- Resolved by Marcus Johansson
- Resolved by Marcus Johansson
I checked the code and gave some suggestions - the thing that should change is that the formatted text can't have upcasted text format, that could lead to security issues.
The rest are recommendations, but the current prompt does not give me good results, I got this as title for instance: Sure! The translation of "test" to Swedish is "test"
The prompt should also be base prompt injection proofed.
1 ai_translate.translate_content: 2 path: '/ai_translate/translate/{entity_type}/{entity_id}/{lang_from}/{lang_to}' 3 defaults: 4 _controller: '\Drupal\ai_translate\Controller\AiTranslateController::translate' 5 _title: 'AI powered Translation' 6 requirements: 7 _permission: 'create ai content translation' - Resolved by Marcus Johansson
added 1 commit
- 83c73ce5 - 3457200: Change the prompt, do not use referrer URL for redirect
added 1 commit
- 2fe35fc9 - [3457200] SHow error if no default selected. with link to config screen
7 7 8 8 use Drupal\Core\Routing\RouteMatchInterface; 9 9 10 /** 11 * Implements hook_install(); 12 * 13 * @param $is_syncing 14 */ 15 function ai_translate_hook_install($is_syncing){ 16 _ai_translate_check_default_provider_and_model(); IMO this belongs to ai_translate_requirements() and should be placed in ai_translate.install Default provider can be set after installing ai_translate, but results of hook_requirements will be always displayed in status report. Also, this would follow the pattern of ai_requirements()
changed this line in version 15 of the diff
21 30 return $output; 22 31 } 23 32 } 33 34 changed this line in version 13 of the diff
23 32 } 33 34 35 /** 36 * Check if default provider is chosen and model is selected. 37 */ 38 function _ai_translate_check_default_provider_and_model() { 39 $ai_config = \Drupal::service('config.factory')->get('ai.settings'); 40 $default_providers = $ai_config->get('default_providers') ?? []; 41 if( 42 !isset($default_providers['chat']['provider_id']) && !isset($default_providers['chat']['model_id']) 43 || 44 $default_providers['chat']['provider_id'] == "" 45 || $default_providers['chat']['model_id'] == '' 46 ) { 47 \Drupal::messenger()->addMessage(t('Please set a default chat provider & model in the <a href="/admin/config/ai/settings">AI module settings</a>.'), 'error', FALSE); changed this line in version 15 of the diff
added 47 commits
- 2fe35fc9...03eb813e - 37 earlier commits
- 5e044fcc - Issue #3460736 by Marcus_Johansson: Refactor all files to use generictype files
- 2479c9ff - Issue #3460736 by Marcus_Johansson: Refactor all files to use generictype files
- a0acfdcc - Issue #3460736 by Marcus_Johansson: Refactor all files to use generictype files
- 1c114cdc - Issue #3460736 by Marcus_Johansson: Refactor all files to use generictype files
- 27957757 - Issue #3460736 by Marcus_Johansson: Refactor all files to use generictype files
- 451f6b2d - Issue #3460753: Embeddings should allow to specify the number of dimensions
- 93f915ad - Issue #3460781 by Marcus_Johansson: Base64 response does not work on OpenAI...
- a5f47fa5 - Phpcs fixes
- fafe8139 - Phpcs fixes
- d2819753 - [3457200] added RUNTIME requirement
Toggle commit list12 12 * 13 13 * @param $is_syncing 14 14 */ 15 function ai_translate_hook_install($is_syncing){ This should be moved into a .install file. If the function _ai_translate_check_default_provider_and_model is only used when installing, it should also be moved there. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21module.api.php/function/hook_install/10
31 31 } 32 32 } 33 33 34 35 34 /** 36 35 * Check if default provider is chosen and model is selected. 37 36 */ 38 37 function _ai_translate_check_default_provider_and_model() { 39 38 $ai_config = \Drupal::service('config.factory')->get('ai.settings'); 40 39 $default_providers = $ai_config->get('default_providers') ?? []; This is ok, but using abstraction would be better if we decide to change the configuration schema.
You can do
if (!\Drupal::service('ai.provider')->getDefaultProviderForOperationType('chat')) {
changed this line in version 15 of the diff
added 1 commit
- 24f32ae9 - [3457200] last changes in the translate module
added 52 commits
-
24f32ae9...539feb95 - 51 commits from branch
project:1.0.x
- 123b74c7 - Merge branch '1.0.x' into '3457200-ai-translations-submodule'
-
24f32ae9...539feb95 - 51 commits from branch
- Resolved by Valery Lourie