-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from AmazeeLabs/feature/SLB-489-image-ai-dev
SLB-489: Image AI modules (DEV)
- Loading branch information
Showing
43 changed files
with
2,882 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
open_ai_base_uri: 'https://api.openai.com/v1/' | ||
open_ai_key: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
open_ai_base_uri: 'https://api.openai.com/v1/' | ||
open_ai_key: '' | ||
ai_model: '' | ||
words_length: 40 | ||
alt_prefix: Silverback | ||
alt_suffix: '' | ||
ai_context: '' | ||
debug_mode: 1 |
11 changes: 11 additions & 0 deletions
11
apps/cms/config/sync/system.action.media_alt_ai_update_action.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
uuid: 5fc8a9eb-135d-4fec-a94a-b90808339bd5 | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- media | ||
id: media_alt_ai_update_action | ||
label: 'Alt text update (images only)' | ||
type: media | ||
plugin: 'entity:alt_ai_update_action:media' | ||
configuration: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## INTRODUCTION | ||
[TDB] | ||
|
||
## REQUIREMENTS | ||
[TBD] | ||
|
||
## INSTALLATION | ||
|
||
Install as you would normally install a contributed Drupal module. | ||
See: https://www.drupal.org/node/895232 for further information. | ||
|
||
## CONFIGURATION | ||
[TBD] | ||
|
2 changes: 2 additions & 0 deletions
2
packages/drupal/silverback_ai/config/install/silverback_ai.settings.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
open_ai_base_uri: 'https://api.openai.com/v1/' | ||
open_ai_key: '' |
29 changes: 29 additions & 0 deletions
29
packages/drupal/silverback_ai/modules/silverback_image_ai/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## INTRODUCTION | ||
|
||
The Silveback Alt AI module is a DESCRIBE_THE_MODULE_HERE. | ||
|
||
The primary use case for this module is: | ||
|
||
- Use case #1 | ||
- Use case #2 | ||
- Use case #3 | ||
|
||
## REQUIREMENTS | ||
|
||
DESCRIBE_MODULE_DEPENDENCIES_HERE | ||
|
||
## INSTALLATION | ||
|
||
Install as you would normally install a contributed Drupal module. | ||
See: https://www.drupal.org/node/895232 for further information. | ||
|
||
## CONFIGURATION | ||
- Configuration step #1 | ||
- Configuration step #2 | ||
- Configuration step #3 | ||
|
||
## MAINTAINERS | ||
|
||
Current maintainers for Drupal 10: | ||
|
||
- FIRST_NAME LAST_NAME (NICKNAME) - https://www.drupal.org/u/NICKNAME |
6 changes: 6 additions & 0 deletions
6
...silverback_ai/modules/silverback_image_ai/config/install/silverback_image_ai.settings.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ai_model: 'gpt-4o-mini' | ||
debug_mode: false | ||
words_length: '40' | ||
alt_prefix: '' | ||
alt_suffix: '' | ||
ai_context: '' |
10 changes: 10 additions & 0 deletions
10
.../modules/silverback_image_ai/config/optional/system.action.media_alt_ai_update_action.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- media | ||
id: media_alt_ai_update_action | ||
label: 'Alt text update (imaged only)' | ||
type: media | ||
plugin: entity:alt_ai_update_action:media | ||
configuration: { } |
6 changes: 6 additions & 0 deletions
6
packages/drupal/silverback_ai/modules/silverback_image_ai/drush.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
silverback_image_ai.commands: | ||
class: \Drupal\silverback_image_ai\Drush\Commands\SilverbackImageAiCommands | ||
arguments: ['@entity_type.manager', '@silverback_image_ai.batch.updater', '@silverback_image_ai.utilities'] | ||
tags: | ||
- { name: drush.command } |
7 changes: 7 additions & 0 deletions
7
packages/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'Silverback Alt AI' | ||
type: module | ||
description: 'Silverback AI utilities for images' | ||
package: Silverback | ||
core_version_requirement: ^10 | ||
dependencies: | ||
- silverback_ai:silverback_ai |
6 changes: 6 additions & 0 deletions
6
packages/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Install, update and uninstall functions for the Silveback Alt AI module. | ||
*/ |
7 changes: 7 additions & 0 deletions
7
...ges/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.links.action.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
media.alt_update: | ||
route_name: silverback_image_ai.image_ai_batch_update | ||
title: 'Alt text update (AI)' | ||
weight: 12 | ||
appears_on: | ||
- entity.media.collection | ||
- view.media_library.page |
6 changes: 6 additions & 0 deletions
6
packages/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.links.menu.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
silverback_image_ai.alt_ai_settings: | ||
title: Silverback Image AI settings | ||
description: Settings for the Silverback image AI utilities. | ||
parent: silverback_ai.admin_config_ai | ||
route_name: silverback_image_ai.settings | ||
weight: 10 |
18 changes: 18 additions & 0 deletions
18
packages/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Primary module hooks for Silveback Alt AI module. | ||
*/ | ||
|
||
/** | ||
* | ||
*/ | ||
function silverback_image_ai_form_alter(&$form, &$form_state, $form_id) { | ||
$service = \Drupal::service('silverback_image_ai.utilities'); | ||
|
||
if ($form_id == 'views_exposed_form') { | ||
// .. | ||
$route_name = \Drupal::routeMatch()->getRouteName(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
silverback_image_ai.settings: | ||
path: '/admin/config/system/silverback/image-ai-settings' | ||
defaults: | ||
_title: 'Silverback Alt AI Settings' | ||
_form: 'Drupal\silverback_image_ai\Form\ImageAiSettingsForm' | ||
requirements: | ||
_permission: 'administer site configuration' | ||
|
||
silverback_image_ai.image_ai_batch_update: | ||
path: '/admin/silverback-ai/update/image' | ||
defaults: | ||
_title: 'Image Ai Batch Update' | ||
_form: 'Drupal\silverback_image_ai\Form\ImageAiBatchUpdateForm' | ||
requirements: | ||
_permission: 'access content' |
8 changes: 8 additions & 0 deletions
8
packages/drupal/silverback_ai/modules/silverback_image_ai/silverback_image_ai.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
silverback_image_ai.utilities: | ||
class: Drupal\silverback_image_ai\ImageAiUtilities | ||
arguments: ['@logger.factory','@config.factory', '@http_client', '@silverback_ai.token.usage', '@silverback_ai.openai_http_client', '@entity_type.manager'] | ||
silverback_image_ai.batch.updater: | ||
class: 'Drupal\silverback_image_ai\MediaUpdaterBatch' | ||
arguments: | ||
- '@logger.factory' |
84 changes: 84 additions & 0 deletions
84
...ilverback_ai/modules/silverback_image_ai/src/Drush/Commands/SilverbackImageAiCommands.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Drupal\silverback_image_ai\Drush\Commands; | ||
|
||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; | ||
use Drupal\Component\Plugin\Exception\PluginNotFoundException; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\silverback_image_ai\ImageAiUtilities; | ||
use Drupal\silverback_image_ai\MediaUpdaterBatch; | ||
use Drush\Attributes as CLI; | ||
use Drush\Commands\DrushCommands; | ||
use Drush\Exceptions\UserAbortException; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* A Drush commandfile. | ||
*/ | ||
final class SilverbackImageAiCommands extends DrushCommands { | ||
|
||
/** | ||
* Constructs a SilverbackImageAiCommands object. | ||
*/ | ||
public function __construct( | ||
private readonly EntityTypeManagerInterface $entityTypeManager, | ||
private readonly MediaUpdaterBatch $batch, | ||
private readonly ImageAiUtilities $service | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('entity_type.manager'), | ||
$container->get('silverback_image_ai.batch.updater'), | ||
$container->get('silverback_image_ai.utilities'), | ||
); | ||
} | ||
|
||
/** | ||
* Command description here. | ||
* | ||
* @param false[] $options | ||
* | ||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException | ||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException | ||
* @throws \Drush\Exceptions\UserAbortException | ||
*/ | ||
#[CLI\Command(name: 'silverback-image-ai:alt:generate', aliases: ['slb:alt:g'])] | ||
#[CLI\Option(name: 'update-all', description: 'Update all image alt texts. ATTENTION: This will overwrite existing alt texts.')] | ||
#[CLI\Usage(name: 'silverback-image-ai:alt:generate', description: 'Generate alt text for media images.')] | ||
public function commandName(array $options = [ | ||
'update-all' => FALSE, | ||
]) { | ||
$media_entities = []; | ||
if ($options['update-all']) { | ||
$this->io()->warning(dt('ATTENTION: This action will overwrite all existing media image alt texts.')); | ||
if ($this->io()->confirm(dt('Are you sure you want to update all existing alt texts?'), FALSE)) { | ||
$media_entities = $this->service->getMediaEntitiesToUpdateAll(); | ||
$this->batch->create($media_entities); | ||
} | ||
else { | ||
throw new UserAbortException(); | ||
} | ||
} | ||
else { | ||
try { | ||
$media_entities = $this->service->getMediaEntitiesToUpdateWithAlt(); | ||
$this->batch->create($media_entities); | ||
} catch (InvalidPluginDefinitionException|PluginNotFoundException $e) { | ||
// @todo | ||
} | ||
} | ||
|
||
// Temp. | ||
// $media_entities = array_slice($this->getMediaEntities(), 0, 2);. | ||
$this->logger()->success(dt('@count media images updated.', [ | ||
'@count' => count($media_entities), | ||
])); | ||
} | ||
|
||
} |
Oops, something went wrong.