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, otherwise you will get a 403 error. - Select your new AI Provider from the dropdown on the right side. If the models do not load, something is wrong with the provider's model fetching.
Basic Chat Test
- On the left side under
messageadd a prompt likeCan you tell me a joke?. - It should now load and it should show the response from the AI provider in the middle section that says "Responses will appear here".
- If it works, congrats! If not, check the logs for errors and debug as necessary.
Chat Provider Configuration Tests
- On the right side, if your provider has specific configuration options, try changing them and see if they have the expected effect on the chat responses.
- A good test is to use temperature settings to see if the responses become more creative or more focused based on the values you set.
System Prompt Test
- On the left side, click on the details "System Prompt".
- Enter a system prompt like
You are a helpful assistant that always responds in a haiku. - Now enter a user message like
Tell me about the weather today. - The response should be in haiku format. If not, check the logs for errors and debug as necessary.
Streaming Chat Test
- On the left side, check the box for
Streamed. - Enter a message like
Tell me a story about a brave knight. At least two paragraphs long. - The response should appear incrementally as the AI provider streams the response. 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
- On the left side, add an image in the file field. PNG should always work.
- Enter a message like
Describe the image I have uploaded. - Make sure to uncheck the
Streamedbox if it is checked. - The response should describe the image you uploaded. If not, check the logs for errors and debug as necessary.
Structured Data Chat Test
- On the left side, click the box
Advancedand then the boxJSON Schema/Structured Output. -
Enter the following structured output format into the
JSON Schema/Structured Outputfield:{ "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 enter a message like
The book The Long Earth was written by Stephen Baxter and Terry Pratchett. -
The response should be:
{ "name": "The Long Earth", "authors": [ "Stephen Baxter", "Terry Pratchett" ] } -
If not, check the logs for errors and debug as necessary.
PDF Chat Test
- On the left side, add a PDF in the file field.
- Enter a message like
Describe the PDF I have uploaded. - The response 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. - On the left side, click the box
Advancedand then the boxFunction Calling. - Click the
Function Callingselect field. - Search or find the
Calculator (ai_test)tool and select it. - Now enter a message like
What is 25 multiplied by 4? Use the Calculator tool to compute the answer. - Check the
Execute Function Callcheckbox. - The response should be:
#1 tool usage: Tool name calculator Arguments from LLM: - expression: "25 * 4" Executed value: 100
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, otherwise you will get a 403 error. - 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, otherwise you will get a 403 error. - 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, otherwise you will get a 403 error. - 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, otherwise you will get a 403 error. - 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, otherwise you will get a 403 error. - 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, otherwise you will get a 403 error. - 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, otherwise you will get a 403 error. - 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.