Testing a new AI Provider
So, you have started developing a new AI Provider for the Drupal AI module. Great! Now it's time to test it to ensure everything works as expected. This guide will walk you through the steps to effectively test your AI Provider.
Please note that your provider might not support all operation types (chat, vision, tools, structured data, embeddings) and that is ok.
We will section it into different operation types, and subsections for each type of operation if it exists.
Prerequisites for all tests
- Enable the AI Module: Ensure that the Drupal AI module is enabled on your Drupal site.
drush pm:en ai - Configure the Provider: Navigate to the AI Providers configuration page (
/admin/config/ai/providers) and set up your new AI Provider with the necessary API keys and settings. - Enable the AI API Explorer: Make sure the AI API Explorer module is enabled to facilitate testing.
drush pm:en ai_api_explorer
Different Operation Types
Chat Operations
For all of the tests, the following steps are true:
- Navigate to the AI API Explorer for chat at
/admin/config/ai/explorers/chat_generator. You need a provider that supports chat operations; without one, the explorer shows what to set up instead. - Open Request settings and pick your provider's model under Model. If the models do not load, something is wrong with the provider's model fetching.
Basic Chat Test
- Write a prompt like
Can you tell me a joke?in the message box and press Send. - The answer from the AI provider shows below your message, with the model, token usage and time.
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Chat Provider Configuration Tests
- Under Model, open All model settings. If your provider has specific configuration options, try changing them and see if they have the expected effect on the answers.
- A good test is to use temperature settings to see if the answers become more creative or more focused based on the values you set.
System Prompt Test
- Under Model, enter a system prompt like
Always mention banana at least once. - Now send a message like
Tell me about the weather today. - The answer must contain the word
bananaat least once. If not, check the logs for errors and debug as necessary.
Streaming Chat Test
- Under Output, check Stream the response.
- Send a message like
Tell me a story about a brave knight. At least two paragraphs long. - The answer should appear incrementally as the AI provider streams it. If not, check the logs for errors and debug as necessary.
Note that you need to make sure that your server doesn't buffer the output, then streaming won't work as expected due to that. Please verify with the OpenAI or Ollama provider for instance.
Vision Chat Test
- Attach an image with the file field under the message box. PNG should always work.
- Send a message like
Describe the image I have uploaded. - The answer should describe the image you uploaded. If not, check the logs for errors and debug as necessary.
Structured Data Chat Test
Note: If you fetched via Git or you are testing against a dev release, you need to build the JSON Schema Editor to be able to run this test. If you see a plain textarea, you can assume it was not built. You can find more information about building it here: Why is the built editor not included?
- Under Output, check Structured output.
-
Enter the following structured output format into the JSON schema field:
{ "schema": { "properties": { "name": { "title": "Name", "type": "string" }, "authors": { "items": { "type": "string" }, "title": "Authors", "type": "array" } }, "required": [ "name", "authors" ], "title": "Book", "type": "object", "additionalProperties": false }, "name": "book", "strict": true } -
Now send a message like
The book The Long Earth was written by Stephen Baxter and Terry Pratchett. -
The answer should be the following JSON, marked as matching the schema:
{ "name": "The Long Earth", "authors": [ "Stephen Baxter", "Terry Pratchett" ] } -
If not, check the logs for errors and debug as necessary.
PDF Chat Test
- Attach a PDF with the file field under the message box.
- Send a message like
Describe the PDF I have uploaded. - The answer should describe the PDF you uploaded. If not, check the logs for errors and debug as necessary.
Tool Use Chat Test
- In your settings.php add
$settings['extension_discovery_scan_tests'] = TRUE;to enable the test tools. - Enable the
AI Testmodule. You can do this viadrush pm:en ai_test. - Under Tools, search or find the
Calculator (ai_test)tool and select it. - Under When the model calls a tool, choose Run it and continue.
- Now send a message like
What is 25 multiplied by 4? Use the Calculator tool to compute the answer. - The thread should show the
calculatorcall with the argument"expression": "25 * 4", the tool result100, and an answer from the model that uses it.
Embeddings Operations
Text Embeddings Test
- Navigate to the AI API Explorer for embeddings at
/admin/config/ai/explorers/embeddings_generator. You need a provider that supports embeddings operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Enter a text like
The quick brown fox jumps over the lazy dog. - It should now load and it should show the embedding vector from the AI provider in the right section that says "Responses will appear here". It will be a lot of numbers.
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Image Embeddings Test
- Navigate to the AI API Explorer for embeddings at
/admin/config/ai/explorers/embeddings_generator. You need a provider that supports embeddings operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Upload an image file. PNG should always work.
- It should now load and it should show the embedding vector from the AI provider in the right section that says "Responses will appear here". It will be a lot of numbers.
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Image Classification Operations
- Navigate to the AI API Explorer for image classification at
/admin/config/ai/explorers/image_classification_generator. You need a provider that supports image classification operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Upload an image file.
- If needed set labels under
Labelswith new line separated labels. - It should now load and it should show the classification results from the AI provider in the right section that says "Responses will appear here".
- If it works, congrats! If not, check the logs for errors and debug
Moderation Operations
- Navigate to the AI API Explorer for moderation at
/admin/config/ai/explorers/moderation_generator. You need a provider that supports moderation operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Enter a text like
I want to harm someone. - It should now load and it should show the moderation results from the AI provider in the right section that says "Responses will appear here". It should indicate that the text is flagged and some categories with scores.
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Speech-to-Text Operations
- Navigate to the AI API Explorer for speech-to-text at
/admin/config/ai/explorers/speech_to_text_generator. You need a provider that supports speech-to-text operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Upload an audio file.
- It should now load and it should show the transcribed text from the AI provider in the right section that says "Responses will appear here".
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Text-to-Speech Operations
- Navigate to the AI API Explorer for text-to-speech at
/admin/config/ai/explorers/text_to_speech_generator. You need a provider that supports text-to-speech operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Enter a text like
Hello, this is a test of the text to speech functionality. - It should now load and it should provide an audio playback of the text from the AI provider in the right section that says "Responses will appear here".
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Text-to-Image Operations
- Navigate to the AI API Explorer for text-to-image at
/admin/config/ai/explorers/text_to_image_generator. You need a provider that supports text-to-image operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown on the left side. If the models do not load, something is wrong with the provider's model fetching.
- Enter a prompt like
A futuristic cityscape at sunset. - It should now load and it should show the generated image from the AI provider in the right section that says "Responses will appear here".
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Decision Operations
- Navigate to the AI API Explorer for decisions at
/admin/config/ai/explorers/decision_generator. You need a provider that supports decision operations; without one, the explorer shows what to set up instead. - Select your new AI Provider from the dropdown. Only models that declare the features used by the entered questions are listed.
- Keep the sample state and questions, or enter your own, and submit.
- The response shows the probabilities for each question. If it works, congrats! If not, check the logs for errors and debug as necessary.
Decision providers should also adopt the offline contract test suite described in the Decision provider contract.