Should use the AI module under the hood

Created on 26 July 2024, 5 months ago

Problem/Motivation

This module is super powerful.
It would benefit from using the https://www.drupal.org/project/ai module under the hood.

As a matter of fact, I think it could actially maybe also reworked to use ai_automator, but that would be a major rework.
Just using the ai module would allow you to go your own path while making use of the shared AI infrastructure.

I would actually dream this to be a submodule of the ai module because metatag is a basic module that every site needs.
And once you enable AI this could/should also be in there. It's another discussion.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇧🇪Belgium wouters_f Leuven

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wouters_f
  • 🇧🇪Belgium wouters_f Leuven

    Example LLM call via AI module

        // Find the default selected LLM
        $sets = \Drupal::service('ai.provider')->getDefaultProviderForOperationType('chat');
    
        $service = \Drupal::service('ai.provider');
        $provider = $service->createInstance($sets['provider_id']);
        $messages = new ChatInput([
          new chatMessage('system', 'You are helpful assistant.'),
          new chatMessage('user', $input),
        ]);
        $message = $provider->chat($messages, $sets['model_id'])->getNormalized();
        return $message->getText();
    

    Example image generation call via AI module

       $config = [
          "n" => 1,
          "response_format" => "url",
          "size" => "1024x1024",
          "quality" => "standard",
          "style" => "vivid",
        ];
        $tags = ["tag_1", "tag_2"];
        try {
          $ai_provider->setConfiguration($config);
          $input = new TextToImageInput($prompt);
          $response = $ai_provider->textToImage($input_prompt, $default_model, $tags);
          $url = $this->saveAndGetImageUrl($response);
    

    Please join the SLACK #ai channel in the Drupal Slack or in the docs https://www.drupal.org/community/contributor-guide/reference-information...

  • Thanks for this. We will review and evaluate.

  • 🇰🇬Kyrgyzstan dan_metille

    I'm feeling that this suggestion is interesting, as I'ld prefer to only put my OpenAI key in one place.
    I originally landed on this thread because I was planing to uninstall metatag_ai on a project and use Automators instead.
    Now I'm curious to make some comparison, because @wouters_f stated that 'This module is super powerful'.

  • 🇧🇪Belgium wouters_f Leuven

    Yes I said that. Good metadata can not be underestimated.
    But putting al your eggs in one basket (openai) might be a bit risky.
    The AI module makes that abstraction.

    Automators is maybe even more powerfull as it is more flexible. But it's a different kind of tool (more a framework kind of tool).
    I do like modules that fix one problem properly (like this module).

    Still hoping they consider using the openai connector via the ai module and this way open up their implementation for other AI providers.

  • Merge request !12Use Drupal AI as dependency → (Open) created by nx2611
  • 🇬🇧United Kingdom scott_euser

    Love seeing that so much code can get deleted! Added a couple comments [which might mean even more :)]

  • Assigned to nx2611
  • Status changed to Needs review 11 days ago
  • 🇫🇷France luukyb

    Hi @nx2611, the Drupal AI module is now on Beta release. Could you try again? See if you still have those PHP errors. Thanks

Production build 0.71.5 2024