@memberjunction/ai 6.1.0-edge.4 → 6.1.0-edge.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generic/apiKeyDictionary.d.ts.map +1 -1
- package/dist/generic/apiKeyDictionary.js +7 -0
- package/dist/generic/apiKeyDictionary.js.map +1 -1
- package/dist/generic/baseAudio.d.ts +41 -1
- package/dist/generic/baseAudio.d.ts.map +1 -1
- package/dist/generic/baseAudio.js +57 -0
- package/dist/generic/baseAudio.js.map +1 -1
- package/dist/generic/baseModel.d.ts +61 -1
- package/dist/generic/baseModel.d.ts.map +1 -1
- package/dist/generic/baseModel.js +47 -1
- package/dist/generic/baseModel.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiKeyDictionary.d.ts","sourceRoot":"","sources":["../../src/generic/apiKeyDictionary.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAyB;IAG9D,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAM;IAChE,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAKvD,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKtD,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"apiKeyDictionary.d.ts","sourceRoot":"","sources":["../../src/generic/apiKeyDictionary.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAyB;IAG9D,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAM;IAChE,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAKvD,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKtD,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IA0B9C,SAAS,CAAC,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAK5E;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAmBjG;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAM9D"}
|
|
@@ -16,6 +16,13 @@ export class AIAPIKeys {
|
|
|
16
16
|
AIAPIKeys._cachedAPIKeys[normalizedKey] = value;
|
|
17
17
|
}
|
|
18
18
|
GetAPIKey(AIDriverName) {
|
|
19
|
+
// A row with no driver class has no key — that is an ANSWER, not a crash (#3532). This threw
|
|
20
|
+
// `Cannot read properties of null (reading 'toUpperCase')` for one malformed AI model row and
|
|
21
|
+
// took out prompt execution entirely, naming neither the row nor the operation. Every caller
|
|
22
|
+
// already handles a falsy key; none of them expected this to throw.
|
|
23
|
+
if (!AIDriverName) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
19
26
|
const normalizedKey = AIDriverName.toUpperCase();
|
|
20
27
|
const cached = this.GetCachedAPIKey(normalizedKey);
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;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IAClD,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAY,SAAS,CAAC,CAAC,CAAC,4FAA4F;IAC7K,IAAI,GAAG;QACH,OAAO,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;;QAEnC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import { BaseModel, BaseParams } from "./baseModel.js";
|
|
1
|
+
import { BaseModel, BaseParams, ModelUsage } from "./baseModel.js";
|
|
2
|
+
/**
|
|
3
|
+
* One piece of a transcription: the text, plus the audio duration the provider reported for it.
|
|
4
|
+
*
|
|
5
|
+
* `durationSeconds` is the billable quantity for per-minute/per-hour transcription pricing. It is
|
|
6
|
+
* optional because not every provider or response format returns it, and an absent duration must
|
|
7
|
+
* stay absent rather than becoming a zero that prices as free.
|
|
8
|
+
*/
|
|
9
|
+
export type TranscriptionPiece = {
|
|
10
|
+
text: string;
|
|
11
|
+
durationSeconds?: number;
|
|
12
|
+
};
|
|
2
13
|
/**
|
|
3
14
|
* Base class for all audio generation models. Each AI model will have a sub-class implementing the abstract methods in this base class. Not all
|
|
4
15
|
* sub-classes will support all methods. If a method is not supported an exception will be thrown, use the GetSupportedMethods method to determine
|
|
@@ -11,6 +22,26 @@ export declare abstract class BaseAudioGenerator extends BaseModel {
|
|
|
11
22
|
abstract GetModels(): Promise<AudioModel[]>;
|
|
12
23
|
abstract GetPronounciationDictionaries(): Promise<PronounciationDictionary[]>;
|
|
13
24
|
abstract GetSupportedMethods(): Promise<string[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Transcribes audio that may exceed the provider's upload ceiling, splitting it first when
|
|
27
|
+
* it does, and joins the pieces back into one transcript and one duration.
|
|
28
|
+
*
|
|
29
|
+
* Pieces are transcribed **sequentially**, not in parallel: transcription providers rate limit
|
|
30
|
+
* by audio-seconds per minute, so firing an hour of audio at once buys nothing but 429s, and a
|
|
31
|
+
* partial failure mid-way would leave a transcript with an unmarked hole in it.
|
|
32
|
+
*
|
|
33
|
+
* The returned `durationSeconds` is the sum across pieces — which is what the provider bills —
|
|
34
|
+
* and is left undefined if ANY piece failed to report one, since a partial sum would understate
|
|
35
|
+
* the bill while looking like a complete answer.
|
|
36
|
+
*
|
|
37
|
+
* @param audio The full audio to transcribe
|
|
38
|
+
* @param maxUploadBytes The provider's hard upload ceiling
|
|
39
|
+
* @param splitTargetBytes Target piece size, below the ceiling to leave room for multipart framing
|
|
40
|
+
* @param splitter Splitter to use for oversized audio; may be null, in which case oversized audio fails
|
|
41
|
+
* @param providerLabel Provider name, used in the size-limit error messages
|
|
42
|
+
* @param transcribeOne Transcribes a single piece already known to be within the ceiling
|
|
43
|
+
*/
|
|
44
|
+
protected TranscribeWithSplitting(audio: Buffer, maxUploadBytes: number, splitTargetBytes: number, splitter: AudioSplitter | null, providerLabel: string, transcribeOne: (piece: Buffer) => Promise<TranscriptionPiece>): Promise<TranscriptionPiece>;
|
|
14
45
|
}
|
|
15
46
|
/**
|
|
16
47
|
* Return payload for each CreateSpeech request
|
|
@@ -30,6 +61,15 @@ export declare class SpeechResult {
|
|
|
30
61
|
*/
|
|
31
62
|
content: string;
|
|
32
63
|
data?: Buffer;
|
|
64
|
+
/**
|
|
65
|
+
* Usage for the request, when the provider reported enough to build it.
|
|
66
|
+
*
|
|
67
|
+
* Audio models are billed by duration rather than by token, so this is normally a
|
|
68
|
+
* {@link ModelUsage.ForMedia} instance in `Seconds` — the quantity a per-minute or per-hour
|
|
69
|
+
* price unit type prices. Left undefined when the provider did not report a duration, so that
|
|
70
|
+
* cost calculation declines rather than billing the request as free.
|
|
71
|
+
*/
|
|
72
|
+
usage?: ModelUsage;
|
|
33
73
|
}
|
|
34
74
|
export declare class SpeechToTextParams extends BaseParams {
|
|
35
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseAudio.d.ts","sourceRoot":"","sources":["../../src/generic/baseAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"baseAudio.d.ts","sourceRoot":"","sources":["../../src/generic/baseAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGhE;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;GAIG;AACH,8BAAsB,kBAAmB,SAAQ,SAAS;aACtC,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;aAC/D,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;aAC/D,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;aACjC,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;aAClC,6BAA6B,IAAI,OAAO,CAAC,wBAAwB,EAAE,CAAC;aACpE,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAExD;;;;;;;;;;;;;;;;;;OAkBG;cACa,uBAAuB,CACnC,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,aAAa,GAAG,IAAI,EAC9B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,GAC9D,OAAO,CAAC,kBAAkB,CAAC;CA+CjC;AAED;;GAEG;AACH,qBAAa,YAAY;IACrB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG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AM,CAAA;IAEV;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAC7B;;OAEG;IACH,uBAAuB,EAAE,OAAO,CAAA;IAChC;;OAEG;IACH,aAAa,EAAE,OAAO,CAAA;IACtB;;OAEG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAC7B;;OAEG;IACH,kBAAkB,EAAE,OAAO,CAAA;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,EAAE,CAAA;CAC9B;AAED,qBAAa,aAAa;IACtB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,qBAAa,wBAAwB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC7B"}
|
|
@@ -5,6 +5,63 @@ import { BaseModel, BaseParams } from "./baseModel.js";
|
|
|
5
5
|
* what methods are supported by a specific sub-class.
|
|
6
6
|
*/
|
|
7
7
|
export class BaseAudioGenerator extends BaseModel {
|
|
8
|
+
/**
|
|
9
|
+
* Transcribes audio that may exceed the provider's upload ceiling, splitting it first when
|
|
10
|
+
* it does, and joins the pieces back into one transcript and one duration.
|
|
11
|
+
*
|
|
12
|
+
* Pieces are transcribed **sequentially**, not in parallel: transcription providers rate limit
|
|
13
|
+
* by audio-seconds per minute, so firing an hour of audio at once buys nothing but 429s, and a
|
|
14
|
+
* partial failure mid-way would leave a transcript with an unmarked hole in it.
|
|
15
|
+
*
|
|
16
|
+
* The returned `durationSeconds` is the sum across pieces — which is what the provider bills —
|
|
17
|
+
* and is left undefined if ANY piece failed to report one, since a partial sum would understate
|
|
18
|
+
* the bill while looking like a complete answer.
|
|
19
|
+
*
|
|
20
|
+
* @param audio The full audio to transcribe
|
|
21
|
+
* @param maxUploadBytes The provider's hard upload ceiling
|
|
22
|
+
* @param splitTargetBytes Target piece size, below the ceiling to leave room for multipart framing
|
|
23
|
+
* @param splitter Splitter to use for oversized audio; may be null, in which case oversized audio fails
|
|
24
|
+
* @param providerLabel Provider name, used in the size-limit error messages
|
|
25
|
+
* @param transcribeOne Transcribes a single piece already known to be within the ceiling
|
|
26
|
+
*/
|
|
27
|
+
async TranscribeWithSplitting(audio, maxUploadBytes, splitTargetBytes, splitter, providerLabel, transcribeOne) {
|
|
28
|
+
const limitMB = (maxUploadBytes / (1024 * 1024)).toFixed(0);
|
|
29
|
+
if (audio.byteLength <= maxUploadBytes) {
|
|
30
|
+
return await transcribeOne(audio);
|
|
31
|
+
}
|
|
32
|
+
if (!splitter) {
|
|
33
|
+
throw new Error(`Audio is ${(audio.byteLength / (1024 * 1024)).toFixed(1)}MB, above ${providerLabel}'s ${limitMB}MB ` +
|
|
34
|
+
`transcription limit. Assign an AudioSplitter to the Splitter property to transcribe ` +
|
|
35
|
+
`audio this size.`);
|
|
36
|
+
}
|
|
37
|
+
const pieces = await splitter.Split(audio, splitTargetBytes);
|
|
38
|
+
if (pieces.length === 0) {
|
|
39
|
+
throw new Error('The configured AudioSplitter returned no pieces');
|
|
40
|
+
}
|
|
41
|
+
const transcripts = [];
|
|
42
|
+
let totalDurationSeconds = 0;
|
|
43
|
+
let everyPieceReportedDuration = true;
|
|
44
|
+
for (const piece of pieces) {
|
|
45
|
+
// A piece the splitter left oversized would fail at the API with a size error naming
|
|
46
|
+
// neither the splitter nor which piece; say so here instead.
|
|
47
|
+
if (piece.byteLength > maxUploadBytes) {
|
|
48
|
+
throw new Error(`The configured AudioSplitter produced a ${(piece.byteLength / (1024 * 1024)).toFixed(1)}MB ` +
|
|
49
|
+
`piece, above ${providerLabel}'s ${limitMB}MB limit`);
|
|
50
|
+
}
|
|
51
|
+
const transcribed = await transcribeOne(piece);
|
|
52
|
+
transcripts.push(transcribed.text);
|
|
53
|
+
if (transcribed.durationSeconds == null) {
|
|
54
|
+
everyPieceReportedDuration = false;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
totalDurationSeconds += transcribed.durationSeconds;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
text: transcripts.filter((t) => t.length > 0).join(' '),
|
|
62
|
+
durationSeconds: everyPieceReportedDuration ? totalDurationSeconds : undefined,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
8
65
|
}
|
|
9
66
|
/**
|
|
10
67
|
* Return payload for each CreateSpeech request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseAudio.js","sourceRoot":"","sources":["../../src/generic/baseAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"baseAudio.js","sourceRoot":"","sources":["../../src/generic/baseAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAehE;;;;GAIG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,SAAS;IAQtD;;;;;;;;;;;;;;;;;;OAkBG;IACO,KAAK,CAAC,uBAAuB,CACnC,KAAa,EACb,cAAsB,EACtB,gBAAwB,EACxB,QAA8B,EAC9B,aAAqB,EACrB,aAA6D;QAE7D,MAAM,OAAO,GAAG,CAAC,cAAc,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAE5D,IAAI,KAAK,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;YACrC,OAAO,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACX,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,IAAI,GAAG,IAAI,C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ACvD,eAAe,EAAE,0BAA0B,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS;SACjF,CAAC;IACN,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;CAyBxB;AAED,MAAM,OAAO,kBAAmB,SAAQ,UAAU;CAmCjD;AAyED;;GAEG;AACH,MAAM,OAAO,SAAS;CAwCrB;AAED;;GAEG;AACH,MAAM,OAAO,WAAW;CAMvB;AAED,MAAM,OAAO,UAAU;CAmCtB;AAED,MAAM,OAAO,aAAa;CASzB;AAED;;GAEG;AACH,MAAM,OAAO,wBAAwB;CAOpC"}
|
|
@@ -50,12 +50,45 @@ export declare class BaseParams {
|
|
|
50
50
|
stopSequences?: string[];
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* The base measure a model's usage is counted in.
|
|
54
|
+
*
|
|
55
|
+
* `Tokens` is the default and is carried by the token fields on {@link ModelUsage}. The other
|
|
56
|
+
* kinds are *continuous* measures — what a model bills for when tokens are not the unit of work —
|
|
57
|
+
* and are carried by {@link ModelUsage.inputUnits} / {@link ModelUsage.outputUnits}.
|
|
58
|
+
*
|
|
59
|
+
* Always the BASE measure, never the billing measure: audio billed per hour is still counted in
|
|
60
|
+
* `Seconds`, and the price unit type driver does the conversion. That keeps one recorded quantity
|
|
61
|
+
* valid across vendors who bill the same model per minute and per hour.
|
|
62
|
+
*
|
|
63
|
+
* **This union must stay a SUPERSET of the `AIUsageType` catalog.** Those rows are the source:
|
|
64
|
+
* `MJAIPromptRunEntityServer` resolves a run's `UsageTypeID` to its `Name` and hands the string
|
|
65
|
+
* straight to this type. Adding a usage-type row whose name is absent here means every run
|
|
66
|
+
* recorded in it becomes unpriceable at runtime — a data change breaking a type, with no compile
|
|
67
|
+
* error to warn you. `MODEL_USAGE_UNIT_KINDS` below exists so a test can assert the two agree;
|
|
68
|
+
* `Characters` is present for exactly that reason, ahead of any driver for it.
|
|
69
|
+
*
|
|
70
|
+
* A kind being listed here does NOT mean runs recorded in it can be priced. Pricing is driven by
|
|
71
|
+
* `MJ: AI Model Price Unit Types` drivers, and both `AIEngineBase.CalculateModelCost` and
|
|
72
|
+
* `MJAIPromptRunEntityServer` deliberately REFUSE to price a run whose kind no driver claims,
|
|
73
|
+
* rather than produce a plausible wrong number. `Characters` has no driver yet — per-character TTS
|
|
74
|
+
* billing is real and will arrive — so such a run is left uncosted with a logged reason, which is
|
|
75
|
+
* the intended safe behaviour rather than an oversight.
|
|
76
|
+
*/
|
|
77
|
+
export declare const MODEL_USAGE_UNIT_KINDS: readonly ["Tokens", "Seconds", "Characters", "Images"];
|
|
78
|
+
export type ModelUsageUnitKind = (typeof MODEL_USAGE_UNIT_KINDS)[number];
|
|
79
|
+
/**
|
|
80
|
+
* Represents usage and cost information for an AI model execution.
|
|
54
81
|
*
|
|
55
82
|
* This class tracks the number of tokens used in both the prompt (input) and
|
|
56
83
|
* completion (output) phases of an AI model execution, along with optional
|
|
57
84
|
* cost information when provided by the AI provider.
|
|
58
85
|
*
|
|
86
|
+
* For models whose unit of work is not a token — speech-to-text priced per minute of audio,
|
|
87
|
+
* image generation priced per image — the quantity lives in {@link inputUnits} /
|
|
88
|
+
* {@link outputUnits} with {@link unitKind} naming its measure. Continuous quantities are never
|
|
89
|
+
* folded into the token fields: a run that reports 90 "tokens" meaning 90 minutes corrupts every
|
|
90
|
+
* token rollup and dashboard downstream of it.
|
|
91
|
+
*
|
|
59
92
|
* @class ModelUsage
|
|
60
93
|
* @since 2.43.0
|
|
61
94
|
*/
|
|
@@ -154,6 +187,33 @@ export declare class ModelUsage {
|
|
|
154
187
|
* @returns {number} promptTokens + completionTokens
|
|
155
188
|
*/
|
|
156
189
|
get totalTokens(): number;
|
|
190
|
+
/**
|
|
191
|
+
* The base measure {@link inputUnits} / {@link outputUnits} are counted in. `undefined` means
|
|
192
|
+
* the execution was token-billed and only the token fields are meaningful.
|
|
193
|
+
*/
|
|
194
|
+
unitKind?: ModelUsageUnitKind;
|
|
195
|
+
/**
|
|
196
|
+
* Continuous input quantity consumed by the execution, in {@link unitKind}'s base measure —
|
|
197
|
+
* e.g. seconds of audio submitted for transcription. Undefined for token-billed executions.
|
|
198
|
+
*
|
|
199
|
+
* Left undefined rather than zeroed when a provider does not report the quantity: a zero here
|
|
200
|
+
* prices as free, which is a worse answer than "no usage recorded".
|
|
201
|
+
*/
|
|
202
|
+
inputUnits?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Continuous output quantity produced by the execution, in {@link unitKind}'s base measure —
|
|
205
|
+
* e.g. seconds of audio synthesized, or number of images generated. Undefined for
|
|
206
|
+
* token-billed executions.
|
|
207
|
+
*/
|
|
208
|
+
outputUnits?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Builds usage for a continuous-media execution, with the token fields zeroed.
|
|
211
|
+
*
|
|
212
|
+
* @param kind The base measure being counted — never the billing measure
|
|
213
|
+
* @param inputUnits Quantity consumed on the input side
|
|
214
|
+
* @param outputUnits Quantity produced on the output side; defaults to 0
|
|
215
|
+
*/
|
|
216
|
+
static ForMedia(kind: Exclude<ModelUsageUnitKind, 'Tokens'>, inputUnits: number, outputUnits?: number): ModelUsage;
|
|
157
217
|
}
|
|
158
218
|
/**
|
|
159
219
|
* Base AI model class, used for everything else in the MemberJunction AI environment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseModel.d.ts","sourceRoot":"","sources":["../../src/generic/baseModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,qBAAa,UAAU;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,OAAO,EAAE,IAAI,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,GAAG,CAAA;IACd;;OAEG;IACH,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,IAAI,WAAW,IAAI,MAAM,CAExB;gBACY,OAAO,EAAE,OAA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;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;;;;OAMG;WACW,QAAQ,CAClB,IAAI,EAAE,OAAO,CAAC,kBAAkB,EAAE,QAAQ,CAAC,EAC3C,UAAU,EAAE,MAAM,EAClB,WAAW,GAAE,MAAU,GACxB,UAAU;CAOhB;AAED;;GAEG;AACH,8BAAsB,SAAS;IAC3B,OAAO,CAAC,OAAO,CAAS;IACxB;;OAEG;IACH,SAAS,KAAK,MAAM,IAAI,MAAM,CAE7B;gBACY,MAAM,EAAE,MAAM;CAM9B"}
|
|
@@ -17,12 +17,44 @@ export class BaseParams {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* The base measure a model's usage is counted in.
|
|
21
|
+
*
|
|
22
|
+
* `Tokens` is the default and is carried by the token fields on {@link ModelUsage}. The other
|
|
23
|
+
* kinds are *continuous* measures — what a model bills for when tokens are not the unit of work —
|
|
24
|
+
* and are carried by {@link ModelUsage.inputUnits} / {@link ModelUsage.outputUnits}.
|
|
25
|
+
*
|
|
26
|
+
* Always the BASE measure, never the billing measure: audio billed per hour is still counted in
|
|
27
|
+
* `Seconds`, and the price unit type driver does the conversion. That keeps one recorded quantity
|
|
28
|
+
* valid across vendors who bill the same model per minute and per hour.
|
|
29
|
+
*
|
|
30
|
+
* **This union must stay a SUPERSET of the `AIUsageType` catalog.** Those rows are the source:
|
|
31
|
+
* `MJAIPromptRunEntityServer` resolves a run's `UsageTypeID` to its `Name` and hands the string
|
|
32
|
+
* straight to this type. Adding a usage-type row whose name is absent here means every run
|
|
33
|
+
* recorded in it becomes unpriceable at runtime — a data change breaking a type, with no compile
|
|
34
|
+
* error to warn you. `MODEL_USAGE_UNIT_KINDS` below exists so a test can assert the two agree;
|
|
35
|
+
* `Characters` is present for exactly that reason, ahead of any driver for it.
|
|
36
|
+
*
|
|
37
|
+
* A kind being listed here does NOT mean runs recorded in it can be priced. Pricing is driven by
|
|
38
|
+
* `MJ: AI Model Price Unit Types` drivers, and both `AIEngineBase.CalculateModelCost` and
|
|
39
|
+
* `MJAIPromptRunEntityServer` deliberately REFUSE to price a run whose kind no driver claims,
|
|
40
|
+
* rather than produce a plausible wrong number. `Characters` has no driver yet — per-character TTS
|
|
41
|
+
* billing is real and will arrive — so such a run is left uncosted with a logged reason, which is
|
|
42
|
+
* the intended safe behaviour rather than an oversight.
|
|
43
|
+
*/
|
|
44
|
+
export const MODEL_USAGE_UNIT_KINDS = ['Tokens', 'Seconds', 'Characters', 'Images'];
|
|
45
|
+
/**
|
|
46
|
+
* Represents usage and cost information for an AI model execution.
|
|
21
47
|
*
|
|
22
48
|
* This class tracks the number of tokens used in both the prompt (input) and
|
|
23
49
|
* completion (output) phases of an AI model execution, along with optional
|
|
24
50
|
* cost information when provided by the AI provider.
|
|
25
51
|
*
|
|
52
|
+
* For models whose unit of work is not a token — speech-to-text priced per minute of audio,
|
|
53
|
+
* image generation priced per image — the quantity lives in {@link inputUnits} /
|
|
54
|
+
* {@link outputUnits} with {@link unitKind} naming its measure. Continuous quantities are never
|
|
55
|
+
* folded into the token fields: a run that reports 90 "tokens" meaning 90 minutes corrupts every
|
|
56
|
+
* token rollup and dashboard downstream of it.
|
|
57
|
+
*
|
|
26
58
|
* @class ModelUsage
|
|
27
59
|
* @since 2.43.0
|
|
28
60
|
*/
|
|
@@ -88,6 +120,20 @@ export class ModelUsage {
|
|
|
88
120
|
get totalTokens() {
|
|
89
121
|
return this.promptTokens + this.completionTokens;
|
|
90
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Builds usage for a continuous-media execution, with the token fields zeroed.
|
|
125
|
+
*
|
|
126
|
+
* @param kind The base measure being counted — never the billing measure
|
|
127
|
+
* @param inputUnits Quantity consumed on the input side
|
|
128
|
+
* @param outputUnits Quantity produced on the output side; defaults to 0
|
|
129
|
+
*/
|
|
130
|
+
static ForMedia(kind, inputUnits, outputUnits = 0) {
|
|
131
|
+
const usage = new ModelUsage(0, 0);
|
|
132
|
+
usage.unitKind = kind;
|
|
133
|
+
usage.inputUnits = inputUnits;
|
|
134
|
+
usage.outputUnits = outputUnits;
|
|
135
|
+
return usage;
|
|
136
|
+
}
|
|
91
137
|
}
|
|
92
138
|
/**
|
|
93
139
|
* Base AI model class, used for everything else in the MemberJunction AI environment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseModel.js","sourceRoot":"","sources":["../../src/generic/baseModel.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAU;IAUnB,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7D,CAAC;IACD,YAAa,OAAgB,EAAE,SAAe,EAAE,OAAa;QACzD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CACJ;AAED,MAAM,OAAO,UAAU;IAAvB;QAWI;;WAEG;QACH,mBAAc,GAA4D,KAAK,CAAC;IA6BpF,CAAC;CAAA;AAED
|
|
1
|
+
{"version":3,"file":"baseModel.js","sourceRoot":"","sources":["../../src/generic/baseModel.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAU;IAUnB,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7D,CAAC;IACD,YAAa,OAAgB,EAAE,SAAe,EAAE,OAAa;QACzD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CACJ;AAED,MAAM,OAAO,UAAU;I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,IAAI,CAAC;QACtB,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;QAC9B,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;QAChC,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAgB,SAAS;IAE3B;;OAEG;IACH,IAAc,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IACD,YAAa,MAAc;QACvB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;QAE9F,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.1.0-edge.
|
|
4
|
+
"version": "6.1.0-edge.5",
|
|
5
5
|
"description": "MemberJunction: AI - core components for abstracting LLMs and other AI model types that are usable anywhere without ANY other MJ dependencies past @memberjunction/global which itself has zero additional dependencies.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"author": "MemberJunction.com",
|
|
12
12
|
"license": "BUSL-1.1",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@memberjunction/global": "6.1.0-edge.
|
|
14
|
+
"@memberjunction/global": "6.1.0-edge.5",
|
|
15
15
|
"dotenv": "^17.2.4",
|
|
16
16
|
"rxjs": "^7.8.2"
|
|
17
17
|
},
|