Getting Started

Last updated on
1 December 2024

This will just introduce how to setup a first example workflows where we will sentiment analyze, add an header image, summarize and categorize a piece of text, using the AI Interpolator OpenAI plugin and the AI Interpolator. They are pretty good examples to get an overview how the AI Interpolator works.

After that there is a more complex chaining example where the goal is that you give Drupal an external link to some news item and it will create a mp3 audio file with yourself and your best friend discussing the articles content on your automatically created podcast.

Its important to understand that the AI Interpolator module itself is just a wrapper module and you need one of the plugins to be able to do something. Thats why each of these examples comes with full installation guide as well, since the plugins differs in what you need to setup.

Note: If you learn by watching videos you can visit Workflows of AI for more workflow videos.

Simple example #1 - Automatic sentiment analysis of an article

In this example we will automatically rate a text if its negative, neutral or positive about its topic using a List (text) field and OpenAI.

  1. Download and enable the AI Interpolator and AI Interpolator OpenAI module, like you would any other module. This will install the OpenAI module since its a dependency.
  2. Login to your OpenAI account and get an API key.
  3. Visit Configurations -> OpenAI -> Settings (/admin/config/openai/settings) and paste the API key and save.
  4. Create or use and entity type, for instance a node content type. If you have the standard installation you can use the Article content type for instance. For this example we will use Article.
  5. If it does not exist, add a Text (formatted, long) or Text (formatted, long, with summary) to the chosen entity type, Call it Body in this example.
  6. Add another field that is a List (text) field, called Sentiment Analysis. On the settings page of this list give the possible text values Negative, Neutral, Positive.
  7. If you scroll down on the settings page you should now see a check box titled "Enable AI Interpolator". Check that one.
  8. You will now see a lot of fields probably, the most important is the "Choose AI Interpolator Rule" field. For this example you should select "OpenAI List String".
  9. The forms might change now, the next step if to make sure that "Interpolator Input Mode" is set to "Base Mode".
  10. In the "Interpolator Base Field" you choose "Body" as the context data representation.
  11. The most important field then is the "Interpolator Prompt" field that is the prompt that you send to OpenAI to select the correct value in this case. There are some placeholders that replaces text that can be seen by opening the fieldset "Placeholders available", in our case we will use {{ context }} which is the actual article without HTML and {{ options_comma }} which is a comma separated list of all options.
  12. Add the following prompt to the "Interpolator Prompt":
    Based on the context text, what is the general sentiment in the article. The possible values are: {{ options }}
    
    Context:
    ------------------------
    {{ context }}
    ------------------------
  13. Click the fieldset "Advanced Settings"
  14. Because its a sentiment analysis and it requires some better skills than GPT-3.5, under "OpenAI Model" choose any of the GPT-4 models available.
  15. Save the settings.
  16. Add an Article and fill in the Body field, but make sure you don't touch the Sentiment Analysis field (manual setting, overrides automatic).
  17. Save the article and then click edit and you will see that the Sentiment Analysis field is filled out magically and (if you trust GPT) correctly.

Simple example #2 - Automatically generate a header image

In this example we will automatically generate a header image for our article using an Image field and OpenAI. This follows on example #1 and is a simple chaining example.

  1. On our Article add another field that is an Text (plain long) field, called Image Prompt.
  2. Scroll down on the settings page you should now see a check box titled "Enable AI Interpolator". Check that one.
  3. In the "Choose AI Interpolato Rule" field select "OpenAI String Long".
  4. The forms might change now, the next step if to make sure that "Interpolator Input Mode" is set to "Base Mode".
  5. In the "Interpolator Base Field" you choose "Body" as the context data representation.
  6. What we will do now is to generate a prompt that will be used to create the header image. Feel free to be expressive here. But you can base it on adding the following prompt to the "Interpolator Prompt" with your own stylistic choices:
    Based on the context text, generate an one sentence expressive image prompt that describes an image that fits the mood and theme of the context. Be abstractive and describe the image as being in vector style.
    
    Context:
    ------------------------
    {{ context }}
    ------------------------
  7. Click the fieldset "Advanced Settings"
  8. Since we are now adding steps to the process and the image generation can take time we will switch this rule to use Drupal's Batch API. This will make sure that each rule runs in its own server request. This can be done by changing the field "Interpolator Worker" to Batch.
  9. Make sure that the field "Interpolator Weight" is 100. Explanation why comes in a coupld of steps.
  10. Save the settings.
  11. On our Article add another field that is an Image field, called Header Image.
  12. Scroll down on the settings page you should now see a check box titled "Enable AI Interpolator". Check that one.
  13. In the "Choose AI Interpolato Rule" field select "OpenAI DALL-E".
  14. The forms might change now, the next step if to make sure that "Interpolator Input Mode" is set to "Base Mode".
  15. In the "Interpolator Base Field" you choose "Image Prompt" as the context data representation - this is the image generation prompt we just generated.
  16. Since we trust the prompt that was generated we can add the following prompt to the "Interpolator Prompt":
    {{ context }}
  17. Click the fieldset "Advanced Settings"
  18. Under the field "DALL-E Engine" select "DALL-E 3". The other specific DALL-E settings you can change as you like.
  19. In the field "Interpolator Weight" set 101. This field basically decides when a rule is run in a chain - this means that our Image Prompt with weight 100 will run before this, because we will not be able to generate an image unless there is a prompt to generate from.
  20. Also here set the field "Interpolator Worker" to Batch so we don't time out.
  21. Save the settings.
  22. On the Article we had created in example #1, click edit and save. You will now see the Batch API in action, it would look like a progress bar.
  23. When its finished, click edit again and you will see that the Image Prompt and Header Image fields are filled out.

Simple example #3 - Automatically summarize the article

In this example we will automatically summarize our article using a Text (formatted, long) field and OpenAI.

  1. On our article add a Text (formatted, long) and call it Summary in this example.
  2. Check the "Enable AI Interpolator".
  3. You will now see a lot of fields probably, the most important is the "Choose AI Interpolato Rule" field. For this example you should select "OpenAI Text Long".
  4. The forms might change now, the next step if to make sure that "Interpolator Input Mode" is set to "Base Mode".
  5. In the "Interpolator Base Field" you choose "Body" as the context data representation.
  6. Add the following prompt to the "Interpolator Prompt":
    Based on the context text write a summary between 200 to 300 characters.
    
    Context:
    ------------------------
    {{ context }}
    ------------------------
  7. Save the settings.
  8. On the Article we had created in example #1, click edit and save. 
  9. When its finished, click edit again and you will see that the Summary field is filled out.

This example requires that you have an OpenAI account, ElevenLabs account. We will use the AI Interpolator Simple Crawler in this case to scrape the website, something that requires that website to be server-side rendered. For more complex way, use the AI Interpolator Scraping Bot plugin.

The other pre-requisite for using your own voice and your friends voice is that you have cloned your voices using Instant Voice Cloning in ElevenLabs. For this example we call the voices JoeDrupal and MaryDrupal.

The last pre-requisite for it to generate a concetanated mp3 is that your server has FFmpeg installed. Without it, it will still create each conversation piece as its own mp3.

  1. Download and enable the AI InterpolatorAI Interpolator OpenAI, ElevenLabs Field and AI Interpolator Simple Crawler module, like you would any other module. This will install the OpenAI module since its a dependency.
  2. Enable the built-in Link module as well.
  3. Login to your OpenAI account and get an API key.
  4. Visit Configurations -> OpenAI -> Settings (/admin/config/openai/settings) and paste the API key and save.
  5. Login to your ElevenLabs account and get and API key.
  6. Visit Configurations -> Web Services -> ElevenLabs Settings (/admin/config/system/eleven-labs-settings) and paste the API key and save
  7. Create a content type called Podcast.
  8. Delete the body field that is added automatically.
  9. Add a field that is a Link field, called URL. Set as required and only allow external URL's and disable link text.
  10. Add a Text (formatted, long) field, Call it HTML.
  11. Check "Enable AI Interpolator". 
  12. The rule you want to select is "Simple Crawler" and set it to "Base Mode" and the base field to "URL".
  13. Click the fieldset "Advanced Settings"
  14. Since this is a long chain, set Batch mode on Interpolator Worker and keep weight at 100.
  15. Select "Article Semgmentation (Readability)" as the Crawler Mode. This will make sure that only the actual text is scraped.
  16. Save the settings.
  17. Add a File field, Call it Podcast File.
  18. Under allowed file extensions write "mp3". Set Allowed Number of Values to "unlimited".
  19. Add a ElevenLabs field, Call it Discussion.
  20. Set Allowed Number of Values to "unlimited".
  21. (If FFMPEG is installed) In the field "Re-Save in Audio field", choose Podcast File.
  22. (If FFMPEG is installed) Check the checkbox "Concatenate File in FFmpeg". To spice up things you can add intro, soundscape and outro music here if you want :)
  23. Check the "Enable AI Interpolator" checkbox
  24. Choose the rule "ElevenLabs Dialogue Creator".
  25. Choose "Base Mode" and the Interpolator Base Field "HTML", since the discussion is based on the scraped content.
  26. If you did not create your own voices, but want to use some generic voices from ElevenLabs, check under Placeholders available for the possible datanames - I will assume joedrupal and marydrupal in this case, just replace them in the prompt.
  27. Add the following prompt to the "Interpolator Prompt":
    Based on the context text create a dialogue between podcast interviewer Joe Drupal who is a stern host that uses the word like in all sentences and the guest Mary Drupal who is a serious, but humorous, guest expert on the topic and who is answering the questions. Start with an introduction and create 5 dialogues back and forth and then end with a thank you to the guest. Make sure that one quirky dad joke is added somewhere in the dialogue.
    
    The elevenlabs voices to use are:
    Joe Drupal = {{ joedrupal }}
    Mary Drupal = {{ marydrupal }}
    
    Context:
    {{ context }}
  28. Feel free to modify this prompt, but what it does is generate a text dialogue that will be sent with meta data who said what to ElevenLabs to generate audio.
  29. Click the fieldset "Advanced Settings"
  30. Since this is a long chain, set Batch mode on Interpolator Worker and keep weight at 101 so it happens after the scraping is done.
  31. Use a GPT-4 based model in the setting OpenAI Model.
  32. Add an Podcast content type and fill in the URL field and nothing else (CNN has good server side rendered articles for instance).
  33. Save the Podcast, grab a coffee because the generation takes time and then listen to the file that got created in Podcast File (with FFmpeg) or use the virtual player to listen to the show on the node view (without FFmpeg).

Help improve this page

Page status: No known problems

You can: