- 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... →
- 🇰🇬Kyrgyzstan sahaj
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.
- 🇬🇧United Kingdom scott_euser
Love seeing that so much code can get deleted! Added a couple comments [which might mean even more :)]