Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/ai/integration/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ export const liveTestConfigs: readonly TestConfig[] = backends.flatMap(
}
);

/**
* Test configurations used for server prompt templates integration tests.
* Server prompt templates don't define the model name from the client, so these test configs
* do not define a model string.
* These tests should only run once per backend, rather than once per backend *per model*.
*/
export const promptTemplatesTestConfigs: readonly TestConfig[] = backends.flatMap(backend => {
const ai = getAI(app, { backend });
return {
ai,
model: '', // Unused by prompt templates tests
toString: () => formatConfigAsString({ ai, model: '' })
};
});

export const TINY_IMG_BASE64 =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=';
export const IMAGE_MIME_TYPE = 'image/png';
Expand Down
17 changes: 6 additions & 11 deletions packages/ai/integration/prompt-templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
getTemplateGenerativeModel,
getTemplateImagenModel
} from '../src';
import { testConfigs } from './constants';
import { STAGING_URL } from '../src/constants';
import { promptTemplatesTestConfigs } from './constants';

const templateBackendSuffix = (
backendType: BackendType
Expand All @@ -31,13 +30,11 @@ const templateBackendSuffix = (

describe('Prompt templates', function () {
this.timeout(20_000);
testConfigs.forEach(testConfig => {
describe(`${testConfig.toString()}`, () => {
promptTemplatesTestConfigs.forEach(testConfig => {
describe(`${promptTemplatesTestConfigs.toString()}`, () => {
describe('Generative Model', () => {
it('successfully generates content', async () => {
const model = getTemplateGenerativeModel(testConfig.ai, {
baseUrl: STAGING_URL
});
const model = getTemplateGenerativeModel(testConfig.ai);
const { response } = await model.generateContent(
`sassy-greeting-${templateBackendSuffix(
testConfig.ai.backend.backendType
Expand All @@ -49,16 +46,14 @@ describe('Prompt templates', function () {
});
describe('Imagen model', async () => {
it('successfully generates images', async () => {
const model = getTemplateImagenModel(testConfig.ai, {
baseUrl: STAGING_URL
});
const model = getTemplateImagenModel(testConfig.ai);
const { images } = await model.generateImages(
`portrait-${templateBackendSuffix(
testConfig.ai.backend.backendType
)}`,
{ animal: 'Rhino' }
);
expect(images.length).to.equal(2); // We ask for two images in the prompt template
expect(images.length).to.equal(1); // We ask for two images in the prompt template
});
});
});
Expand Down
Loading