Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 157bb88

Browse files
authored
Merge pull request #70 from Chainlit/hugues/fix-prompt-seed
fix: seeded prompt required test udpate
2 parents 6e5b523 + 5833ea2 commit 157bb88

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/api.test.ts

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dotenv/config';
22
import { v4 as uuidv4 } from 'uuid';
33

4-
import { ChatGeneration, LiteralClient } from '../src';
4+
import { ChatGeneration, IGenerationMessage, LiteralClient } from '../src';
55
import { Dataset } from '../src/evaluation/dataset';
66
import { Score } from '../src/evaluation/score';
77
import { sleep } from './utils';
@@ -583,16 +583,15 @@ describe('End to end tests for the SDK', function () {
583583
});
584584

585585
describe('Prompt api', () => {
586-
it('should get a prompt', async () => {
586+
it('should get a prompt by name', async () => {
587587
const prompt = await client.api.getPrompt('Default');
588588

589589
expect(prompt).not.toBeNull();
590590
expect(prompt?.name).toBe('Default');
591-
expect(prompt?.version).toBe(0);
592591
});
593592

594593
it('should get a prompt by id', async () => {
595-
const prompt = await client.api.getPrompt('Default');
594+
const prompt = await client.api.getPrompt('Default', 0);
596595

597596
const fetchedPrompt = await client.api.getPromptById(prompt!.id);
598597

@@ -611,7 +610,7 @@ describe('End to end tests for the SDK', function () {
611610
});
612611

613612
it('should format a prompt with default values', async () => {
614-
const prompt = await client.api.getPrompt('Default');
613+
const prompt = await client.api.getPrompt('Default', 0);
615614

616615
const formatted = prompt!.formatMessages();
617616

@@ -628,7 +627,7 @@ is a templated list.`;
628627
});
629628

630629
it('should format a prompt with custom values', async () => {
631-
const prompt = await client.api.getPrompt('Default');
630+
const prompt = await client.api.getPrompt('Default', 0);
632631

633632
const formatted = prompt!.formatMessages({ test_var: 'Edited value' });
634633

@@ -645,14 +644,47 @@ is a templated list.`;
645644
});
646645

647646
it('should get a prompt A/B testing configuration', async () => {
648-
await client.api.updatePromptAbTesting('Default', [
647+
const promptName = 'TypeScript SDK E2E Tests';
648+
649+
const v0: IGenerationMessage[] = [{ role: 'user', content: 'Hello' }];
650+
const v1: IGenerationMessage[] = [{ role: 'user', content: 'Hello 2' }];
651+
652+
const promptV0 = await client.api.getOrCreatePrompt(promptName, v0);
653+
654+
await client.api.updatePromptAbTesting(promptV0.name, [
649655
{ version: 0, rollout: 100 }
650656
]);
651-
const rollouts = await client.api.getPromptAbTesting('Default');
652-
expect(rollouts).not.toBeNull();
653-
expect(rollouts?.length).toBe(1);
654-
expect(rollouts![0].rollout).toBe(100);
655-
expect(rollouts![0].version).toBe(0);
657+
658+
let abTesting = await client.api.getPromptAbTesting(promptName);
659+
660+
if (!abTesting) {
661+
throw new Error('Prompt AB testing not found');
662+
}
663+
664+
expect(abTesting.length).toBe(1);
665+
expect(abTesting[0].version).toBe(0);
666+
expect(abTesting[0].rollout).toBe(100);
667+
668+
const promptV1 = await client.api.getOrCreatePrompt(promptName, v1);
669+
670+
await client.api.updatePromptAbTesting(promptV1.name, [
671+
{ version: 0, rollout: 60 },
672+
{ version: 1, rollout: 40 }
673+
]);
674+
675+
abTesting = await client.api.getPromptAbTesting(promptV1.name);
676+
677+
if (!abTesting) {
678+
throw new Error('Prompt AB testing not found');
679+
}
680+
681+
abTesting.sort((a, b) => a.version - b.version);
682+
683+
expect(abTesting.length).toBe(2);
684+
expect(abTesting[0].version).toBe(0);
685+
expect(abTesting[0].rollout).toBe(60);
686+
expect(abTesting[1].version).toBe(1);
687+
expect(abTesting[1].rollout).toBe(40);
656688
});
657689
});
658690
});

0 commit comments

Comments
 (0)