Setup kernel test structure for OpenAI (with text-to-image)

Created on 2 August 2024, about 2 months ago
Updated 20 September 2024, about 11 hours ago

Problem/Motivation

We are currently missing unit tests and these will be written, but before we have that there are simple kernel tests that can test for a lot of issues happening that would cover a lot of obvious errors on the AI core module.

With the Mockoon server we now have the possibility to mock api calls easily without having to write Guzzle Testing middleware, that might be time consuming. This means that we can simply repoint the basename of the OpenAI provider to a localhost and then run our test calls against this.

Documentation of kernel tests is here amongst other places:
https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/setup-ta...
https://deninet.com/blog/2019/02/10/writing-automated-tests-drupal-8-par...

What we want to do as an initial test is to test so the OpenAI text-to-image (DALL-E) works using the abstractions of the AI module. This means that we are testing the AI Core module together with the (probably) most used provider. We want to test with the following combinations:
1. Working test with normalized input and normalized output.
2. Working test with raw input and raw output.
3. Working test with normalized input and raw output.
4. Working test with raw input and normalized output.
5. Working test of fetching the raw client and doing raw calls.
6. Exception test using the wrong API key, that will also test hotswapping the API key method.
7. Exception test using an request for to many images.
8. Exception test missing a text prompt.

In the AI API Explorer you can get examples for how the code should look like.

When we have the first kernel test, pumping out kernel tests should be a fairly fast operation for any of the developers.

Steps to reproduce

Proposed resolution

Write a Kernel test that does the following:
1. Install AI and Key module.
2. Install OpenAI provider.
3. Setup a working API key.
4. Setup config for OpenAI provider to change the basehost, the api key and turn off moderation.
5. Do the above calls and check various assertions on the output, including looking for expected exceptions.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

1.0

Component

AI Core module

Created by

🇩🇪Germany Marcus_Johansson

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

Comments & Activities

Production build 0.71.5 2024