1
- const { getValueKey, getMultiplier, defaultRate } = require ( './tx' ) ;
1
+ const { getValueKey, getMultiplier, defaultRate, tokenValues } = require ( './tx' ) ;
2
2
3
3
describe ( 'getValueKey' , ( ) => {
4
4
it ( 'should return "16k" for model name containing "gpt-3.5-turbo-16k"' , ( ) => {
@@ -20,27 +20,72 @@ describe('getValueKey', () => {
20
20
it ( 'should return undefined for model names that do not match any known patterns' , ( ) => {
21
21
expect ( getValueKey ( 'gpt-5-some-other-info' ) ) . toBeUndefined ( ) ;
22
22
} ) ;
23
+
24
+ it ( 'should return "gpt-3.5-turbo-1106" for model name containing "gpt-3.5-turbo-1106"' , ( ) => {
25
+ expect ( getValueKey ( 'gpt-3.5-turbo-1106-some-other-info' ) ) . toBe ( 'gpt-3.5-turbo-1106' ) ;
26
+ expect ( getValueKey ( 'openai/gpt-3.5-turbo-1106' ) ) . toBe ( 'gpt-3.5-turbo-1106' ) ;
27
+ expect ( getValueKey ( 'gpt-3.5-turbo-1106/openai' ) ) . toBe ( 'gpt-3.5-turbo-1106' ) ;
28
+ } ) ;
29
+
30
+ it ( 'should return "gpt-4-1106" for model name containing "gpt-4-1106"' , ( ) => {
31
+ expect ( getValueKey ( 'gpt-4-1106-some-other-info' ) ) . toBe ( 'gpt-4-1106' ) ;
32
+ expect ( getValueKey ( 'gpt-4-1106-vision-preview' ) ) . toBe ( 'gpt-4-1106' ) ;
33
+ expect ( getValueKey ( 'gpt-4-1106-preview' ) ) . toBe ( 'gpt-4-1106' ) ;
34
+ expect ( getValueKey ( 'openai/gpt-4-1106' ) ) . toBe ( 'gpt-4-1106' ) ;
35
+ expect ( getValueKey ( 'gpt-4-1106/openai/' ) ) . toBe ( 'gpt-4-1106' ) ;
36
+ } ) ;
23
37
} ) ;
24
38
25
39
describe ( 'getMultiplier' , ( ) => {
26
40
it ( 'should return the correct multiplier for a given valueKey and tokenType' , ( ) => {
27
- expect ( getMultiplier ( { valueKey : '8k' , tokenType : 'prompt' } ) ) . toBe ( 30 ) ;
28
- expect ( getMultiplier ( { valueKey : '8k' , tokenType : 'completion' } ) ) . toBe ( 60 ) ;
41
+ expect ( getMultiplier ( { valueKey : '8k' , tokenType : 'prompt' } ) ) . toBe ( tokenValues [ '8k' ] . prompt ) ;
42
+ expect ( getMultiplier ( { valueKey : '8k' , tokenType : 'completion' } ) ) . toBe (
43
+ tokenValues [ '8k' ] . completion ,
44
+ ) ;
29
45
} ) ;
30
46
31
47
it ( 'should return defaultRate if tokenType is provided but not found in tokenValues' , ( ) => {
32
48
expect ( getMultiplier ( { valueKey : '8k' , tokenType : 'unknownType' } ) ) . toBe ( defaultRate ) ;
33
49
} ) ;
34
50
35
51
it ( 'should derive the valueKey from the model if not provided' , ( ) => {
36
- expect ( getMultiplier ( { tokenType : 'prompt' , model : 'gpt-4-some-other-info' } ) ) . toBe ( 30 ) ;
52
+ expect ( getMultiplier ( { tokenType : 'prompt' , model : 'gpt-4-some-other-info' } ) ) . toBe (
53
+ tokenValues [ '8k' ] . prompt ,
54
+ ) ;
37
55
} ) ;
38
56
39
57
it ( 'should return 1 if only model or tokenType is missing' , ( ) => {
40
58
expect ( getMultiplier ( { tokenType : 'prompt' } ) ) . toBe ( 1 ) ;
41
59
expect ( getMultiplier ( { model : 'gpt-4-some-other-info' } ) ) . toBe ( 1 ) ;
42
60
} ) ;
43
61
62
+ it ( 'should return the correct multiplier for gpt-3.5-turbo-1106' , ( ) => {
63
+ expect ( getMultiplier ( { valueKey : 'gpt-3.5-turbo-1106' , tokenType : 'prompt' } ) ) . toBe (
64
+ tokenValues [ 'gpt-3.5-turbo-1106' ] . prompt ,
65
+ ) ;
66
+ expect ( getMultiplier ( { valueKey : 'gpt-3.5-turbo-1106' , tokenType : 'completion' } ) ) . toBe (
67
+ tokenValues [ 'gpt-3.5-turbo-1106' ] . completion ,
68
+ ) ;
69
+ } ) ;
70
+
71
+ it ( 'should return the correct multiplier for gpt-4-1106' , ( ) => {
72
+ expect ( getMultiplier ( { valueKey : 'gpt-4-1106' , tokenType : 'prompt' } ) ) . toBe (
73
+ tokenValues [ 'gpt-4-1106' ] . prompt ,
74
+ ) ;
75
+ expect ( getMultiplier ( { valueKey : 'gpt-4-1106' , tokenType : 'completion' } ) ) . toBe (
76
+ tokenValues [ 'gpt-4-1106' ] . completion ,
77
+ ) ;
78
+ } ) ;
79
+
80
+ it ( 'should derive the valueKey from the model if not provided for new models' , ( ) => {
81
+ expect (
82
+ getMultiplier ( { tokenType : 'prompt' , model : 'gpt-3.5-turbo-1106-some-other-info' } ) ,
83
+ ) . toBe ( tokenValues [ 'gpt-3.5-turbo-1106' ] . prompt ) ;
84
+ expect ( getMultiplier ( { tokenType : 'completion' , model : 'gpt-4-1106-vision-preview' } ) ) . toBe (
85
+ tokenValues [ 'gpt-4-1106' ] . completion ,
86
+ ) ;
87
+ } ) ;
88
+
44
89
it ( 'should return defaultRate if derived valueKey does not match any known patterns' , ( ) => {
45
90
expect ( getMultiplier ( { tokenType : 'prompt' , model : 'gpt-5-some-other-info' } ) ) . toBe (
46
91
defaultRate ,
0 commit comments