1
1
import 'dotenv/config' ;
2
2
import { v4 as uuidv4 } from 'uuid' ;
3
3
4
- import { ChatGeneration , LiteralClient } from '../src' ;
4
+ import { ChatGeneration , IGenerationMessage , LiteralClient } from '../src' ;
5
5
import { Dataset } from '../src/evaluation/dataset' ;
6
6
import { Score } from '../src/evaluation/score' ;
7
7
import { sleep } from './utils' ;
@@ -583,16 +583,15 @@ describe('End to end tests for the SDK', function () {
583
583
} ) ;
584
584
585
585
describe ( 'Prompt api' , ( ) => {
586
- it ( 'should get a prompt' , async ( ) => {
586
+ it ( 'should get a prompt by name ' , async ( ) => {
587
587
const prompt = await client . api . getPrompt ( 'Default' ) ;
588
588
589
589
expect ( prompt ) . not . toBeNull ( ) ;
590
590
expect ( prompt ?. name ) . toBe ( 'Default' ) ;
591
- expect ( prompt ?. version ) . toBe ( 0 ) ;
592
591
} ) ;
593
592
594
593
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 ) ;
596
595
597
596
const fetchedPrompt = await client . api . getPromptById ( prompt ! . id ) ;
598
597
@@ -611,7 +610,7 @@ describe('End to end tests for the SDK', function () {
611
610
} ) ;
612
611
613
612
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 ) ;
615
614
616
615
const formatted = prompt ! . formatMessages ( ) ;
617
616
@@ -628,7 +627,7 @@ is a templated list.`;
628
627
} ) ;
629
628
630
629
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 ) ;
632
631
633
632
const formatted = prompt ! . formatMessages ( { test_var : 'Edited value' } ) ;
634
633
@@ -645,14 +644,47 @@ is a templated list.`;
645
644
} ) ;
646
645
647
646
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 , [
649
655
{ version : 0 , rollout : 100 }
650
656
] ) ;
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 ) ;
656
688
} ) ;
657
689
} ) ;
658
690
} ) ;
0 commit comments