@memberjunction/ai 6.2.0-edge.0 → 6.2.0-edge.2
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 +33 -0
- package/dist/generic/apiKeyDictionary.d.ts.map +1 -1
- package/dist/generic/apiKeyDictionary.js +19 -0
- package/dist/generic/apiKeyDictionary.js.map +1 -1
- package/dist/generic/baseAudio.d.ts +31 -14
- package/dist/generic/baseAudio.d.ts.map +1 -1
- package/dist/generic/baseAudio.js +20 -49
- package/dist/generic/baseAudio.js.map +1 -1
- package/dist/generic/baseDecision.d.ts +125 -0
- package/dist/generic/baseDecision.d.ts.map +1 -0
- package/dist/generic/baseDecision.js +387 -0
- package/dist/generic/baseDecision.js.map +1 -0
- package/dist/generic/baseEmbeddings.d.ts +8 -0
- package/dist/generic/baseEmbeddings.d.ts.map +1 -1
- package/dist/generic/baseEmbeddings.js +10 -0
- package/dist/generic/baseEmbeddings.js.map +1 -1
- package/dist/generic/baseImage.js +10 -10
- package/dist/generic/baseImage.js.map +1 -1
- package/dist/generic/baseLLM.d.ts +55 -1
- package/dist/generic/baseLLM.d.ts.map +1 -1
- package/dist/generic/baseLLM.js +44 -2
- package/dist/generic/baseLLM.js.map +1 -1
- package/dist/generic/baseModel.js +3 -3
- package/dist/generic/baseModel.js.map +1 -1
- package/dist/generic/baseSpeechToText.d.ts +47 -0
- package/dist/generic/baseSpeechToText.d.ts.map +1 -0
- package/dist/generic/baseSpeechToText.js +84 -0
- package/dist/generic/baseSpeechToText.js.map +1 -0
- package/dist/generic/baseTextToSpeech.d.ts +26 -0
- package/dist/generic/baseTextToSpeech.d.ts.map +1 -0
- package/dist/generic/baseTextToSpeech.js +12 -0
- package/dist/generic/baseTextToSpeech.js.map +1 -0
- package/dist/generic/baseVideo.d.ts +15 -1
- package/dist/generic/baseVideo.d.ts.map +1 -1
- package/dist/generic/baseVideo.js.map +1 -1
- package/dist/generic/chat.types.d.ts +28 -0
- package/dist/generic/chat.types.d.ts.map +1 -1
- package/dist/generic/chat.types.js +51 -11
- package/dist/generic/chat.types.js.map +1 -1
- package/dist/generic/classify.types.d.ts +11 -0
- package/dist/generic/classify.types.d.ts.map +1 -1
- package/dist/generic/classify.types.js +11 -0
- package/dist/generic/classify.types.js.map +1 -1
- package/dist/generic/decision.types.d.ts +225 -0
- package/dist/generic/decision.types.d.ts.map +1 -0
- package/dist/generic/decision.types.js +43 -0
- package/dist/generic/decision.types.js.map +1 -0
- package/dist/generic/errorAnalyzer.d.ts +2 -0
- package/dist/generic/errorAnalyzer.d.ts.map +1 -1
- package/dist/generic/errorAnalyzer.js +16 -8
- package/dist/generic/errorAnalyzer.js.map +1 -1
- package/dist/generic/linearTextScan.d.ts +18 -0
- package/dist/generic/linearTextScan.d.ts.map +1 -0
- package/dist/generic/linearTextScan.js +70 -0
- package/dist/generic/linearTextScan.js.map +1 -0
- package/dist/generic/modelConfiguration.d.ts +68 -3
- package/dist/generic/modelConfiguration.d.ts.map +1 -1
- package/dist/generic/modelConfiguration.js +26 -5
- package/dist/generic/modelConfiguration.js.map +1 -1
- package/dist/generic/openAICompatibleTools.d.ts +10 -0
- package/dist/generic/openAICompatibleTools.d.ts.map +1 -1
- package/dist/generic/openAICompatibleTools.js +27 -7
- package/dist/generic/openAICompatibleTools.js.map +1 -1
- package/dist/generic/reranker.types.d.ts +6 -0
- package/dist/generic/reranker.types.d.ts.map +1 -1
- package/dist/generic/summarize.types.d.ts +7 -0
- package/dist/generic/summarize.types.d.ts.map +1 -1
- package/dist/generic/summarize.types.js +7 -0
- package/dist/generic/summarize.types.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +12 -6
|
@@ -36,4 +36,37 @@ export declare class AIAPIKeys {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function GetAIAPIKey(AIDriverName: string, apiKeys?: AIAPIKey[], verbose?: boolean): string;
|
|
38
38
|
export declare function GetAIAPIKeyGlobal(AIDriverName: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the API key to use for ONE AI driver class.
|
|
41
|
+
*
|
|
42
|
+
* A shape for handing a *scoped* key-resolution capability to code that spends an AI key without
|
|
43
|
+
* handing over the key list itself. A holder can ask for the one driver class it needs; it cannot
|
|
44
|
+
* enumerate the run's credentials, and whoever built the resolver decides whether to answer.
|
|
45
|
+
* Realtime uses it. `@memberjunction/actions-base` declares the same signature separately as
|
|
46
|
+
* `RuntimeAPIKeyResolver` (it does not depend on this package), and the prompt runner still takes
|
|
47
|
+
* the key list (`AIPromptParams.apiKeys`).
|
|
48
|
+
*
|
|
49
|
+
* `undefined` means "no key for that driver class" — which is also how a deliberate refusal reads,
|
|
50
|
+
* so a caller treats both the same way: fall back to the platform key, or skip that vendor.
|
|
51
|
+
*
|
|
52
|
+
* Build one with {@link MakeAIAPIKeyResolver}.
|
|
53
|
+
*/
|
|
54
|
+
export type AIAPIKeyResolver = (driverClass: string) => string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Builds an {@link AIAPIKeyResolver} over a runtime key list: the list's key for the driver class
|
|
57
|
+
* first, then the platform (environment) key — the same precedence as `GetAIAPIKey`. For prompts
|
|
58
|
+
* that is only the legacy tier: `AIPromptRunner` tries MJ Credentials first (a per-request
|
|
59
|
+
* `credentialId`, then `AICredentialBinding`s, then the vendor's default credential) and reaches
|
|
60
|
+
* this order only when none of them resolves. This resolver never consults credentials.
|
|
61
|
+
*
|
|
62
|
+
* Pass the run's `apiKeys` and the resolver honours a customer's own credentials; pass nothing and
|
|
63
|
+
* it is exactly the platform lookup, so a caller never has to special-case "this run has no keys".
|
|
64
|
+
*
|
|
65
|
+
* A caller with its own platform-key seam should layer run keys over that seam rather than use this
|
|
66
|
+
* resolver, whose environment fallback would answer first and bypass the seam.
|
|
67
|
+
*
|
|
68
|
+
* @param apiKeys The runtime keys for a run, if any (`ExecuteAgentParams.apiKeys`).
|
|
69
|
+
* @param verbose Log which source answered — never the key itself.
|
|
70
|
+
*/
|
|
71
|
+
export declare function MakeAIAPIKeyResolver(apiKeys?: AIAPIKey[], verbose?: boolean): AIAPIKeyResolver;
|
|
39
72
|
//# sourceMappingURL=apiKeyDictionary.d.ts.map
|
|
@@ -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;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"}
|
|
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;AACD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAE9F"}
|
|
@@ -82,4 +82,23 @@ export function GetAIAPIKeyGlobal(AIDriverName) {
|
|
|
82
82
|
else
|
|
83
83
|
throw new Error('Could not instantiate AIAPIKeys class');
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Builds an {@link AIAPIKeyResolver} over a runtime key list: the list's key for the driver class
|
|
87
|
+
* first, then the platform (environment) key — the same precedence as `GetAIAPIKey`. For prompts
|
|
88
|
+
* that is only the legacy tier: `AIPromptRunner` tries MJ Credentials first (a per-request
|
|
89
|
+
* `credentialId`, then `AICredentialBinding`s, then the vendor's default credential) and reaches
|
|
90
|
+
* this order only when none of them resolves. This resolver never consults credentials.
|
|
91
|
+
*
|
|
92
|
+
* Pass the run's `apiKeys` and the resolver honours a customer's own credentials; pass nothing and
|
|
93
|
+
* it is exactly the platform lookup, so a caller never has to special-case "this run has no keys".
|
|
94
|
+
*
|
|
95
|
+
* A caller with its own platform-key seam should layer run keys over that seam rather than use this
|
|
96
|
+
* resolver, whose environment fallback would answer first and bypass the seam.
|
|
97
|
+
*
|
|
98
|
+
* @param apiKeys The runtime keys for a run, if any (`ExecuteAgentParams.apiKeys`).
|
|
99
|
+
* @param verbose Log which source answered — never the key itself.
|
|
100
|
+
*/
|
|
101
|
+
export function MakeAIAPIKeyResolver(apiKeys, verbose) {
|
|
102
|
+
return (driverClass) => GetAIAPIKey(driverClass, apiKeys, verbose) || undefined;
|
|
103
|
+
}
|
|
85
104
|
//# sourceMappingURL=apiKeyDictionary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiKeyDictionary.js","sourceRoot":"","sources":["../../src/generic/apiKeyDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAmBlD;;;GAGG;AACH,MAAM,OAAO,SAAS;aACM,kBAAa,GAAG,qBAAqB,CAAC;IAE9D,6DAA6D;aAC5C,mBAAc,GAA8B,EAAE,CAAC;IACtD,eAAe,CAAC,YAAoB;QAC1C,MAAM,aAAa,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAES,eAAe,CAAC,YAAoB,EAAE,KAAa;QACzD,MAAM,aAAa,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AC,OAAoB,EAAE,OAAiB;IACxE,OAAO,CAAC,WAAmB,EAAsB,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC;AAChH,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { BaseModel, BaseParams, ModelUsage } from "./baseModel.js";
|
|
2
|
+
import type { AIErrorInfo } from "./errorTypes.js";
|
|
3
|
+
import type { BaseSpeechToText } from "./baseSpeechToText.js";
|
|
4
|
+
import type { BaseTextToSpeech } from "./baseTextToSpeech.js";
|
|
2
5
|
/**
|
|
3
6
|
* One piece of a transcription: the text, plus the audio duration the provider reported for it.
|
|
4
7
|
*
|
|
@@ -11,11 +14,24 @@ export type TranscriptionPiece = {
|
|
|
11
14
|
durationSeconds?: number;
|
|
12
15
|
};
|
|
13
16
|
/**
|
|
14
|
-
* Base class for
|
|
15
|
-
* sub-classes
|
|
16
|
-
*
|
|
17
|
+
* Base class for audio models that carries both text-to-speech and speech-to-text. Not all
|
|
18
|
+
* sub-classes support all methods: an unsupported method throws, and `GetSupportedMethods` names
|
|
19
|
+
* the ones a sub-class implements.
|
|
20
|
+
*
|
|
21
|
+
* It spans two model types (`TTS` and `Speech to Text`), so it has been split. It stays, and keeps
|
|
22
|
+
* working, for drivers and callers that already use it: it implements both halves, so any of its
|
|
23
|
+
* drivers can be used where either new base class is expected. The drivers MemberJunction ships
|
|
24
|
+
* still extend it and are also registered against the new class or classes they implement, under
|
|
25
|
+
* the same keys.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use {@link BaseTextToSpeech} for text-to-speech and {@link BaseSpeechToText} for
|
|
28
|
+
* speech-to-text. An application that overrides a shipped audio driver must also register the
|
|
29
|
+
* override against the new class or classes that driver implements, under the same key, for example
|
|
30
|
+
* `@RegisterClass(BaseTextToSpeech, 'OpenAIAudioGenerator')`. The ClassFactory keeps registrations
|
|
31
|
+
* per base class, and the text-to-speech and speech-to-text runners resolve drivers through the new
|
|
32
|
+
* classes, so an override registered only against `BaseAudioGenerator` is not used by them.
|
|
17
33
|
*/
|
|
18
|
-
export declare abstract class BaseAudioGenerator extends BaseModel {
|
|
34
|
+
export declare abstract class BaseAudioGenerator extends BaseModel implements BaseTextToSpeech, BaseSpeechToText {
|
|
19
35
|
abstract CreateSpeech(params: TextToSpeechParams): Promise<SpeechResult>;
|
|
20
36
|
abstract SpeechToText(params: SpeechToTextParams): Promise<SpeechResult>;
|
|
21
37
|
abstract GetVoices(): Promise<VoiceInfo[]>;
|
|
@@ -23,16 +39,8 @@ export declare abstract class BaseAudioGenerator extends BaseModel {
|
|
|
23
39
|
abstract GetPronounciationDictionaries(): Promise<PronounciationDictionary[]>;
|
|
24
40
|
abstract GetSupportedMethods(): Promise<string[]>;
|
|
25
41
|
/**
|
|
26
|
-
* Transcribes audio that may exceed the provider's upload ceiling, splitting it first when
|
|
27
|
-
*
|
|
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.
|
|
42
|
+
* Transcribes audio that may exceed the provider's upload ceiling, splitting it first when it
|
|
43
|
+
* does. See {@link TranscribeAudioWithSplitting}, which this calls, for the behavior.
|
|
36
44
|
*
|
|
37
45
|
* @param audio The full audio to transcribe
|
|
38
46
|
* @param maxUploadBytes The provider's hard upload ceiling
|
|
@@ -70,6 +78,15 @@ export declare class SpeechResult {
|
|
|
70
78
|
* cost calculation declines rather than billing the request as free.
|
|
71
79
|
*/
|
|
72
80
|
usage?: ModelUsage;
|
|
81
|
+
/**
|
|
82
|
+
* How a failure is classified, when the request failed: `ErrorAnalyzer`'s reading of the error
|
|
83
|
+
* the provider's SDK threw, which keeps its HTTP status. A caller deciding whether to try another
|
|
84
|
+
* vendor reads this, as the failover loop reads `BaseResult.errorInfo`: a rate limit or an outage
|
|
85
|
+
* is worth another vendor, and a request the vendor rejected as invalid is not. The message alone
|
|
86
|
+
* cannot tell them apart. Undefined on success, and from a driver that reports only
|
|
87
|
+
* `errorMessage`.
|
|
88
|
+
*/
|
|
89
|
+
errorInfo?: AIErrorInfo;
|
|
73
90
|
}
|
|
74
91
|
export declare class SpeechToTextParams extends BaseParams {
|
|
75
92
|
/**
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAEhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,8BAAsB,kBAAmB,SAAQ,SAAU,YAAW,gBAAgB,EAAE,gBAAgB;aACpF,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;aAC/D,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC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AAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC7B"}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { BaseModel, BaseParams } from "./baseModel.js";
|
|
2
|
+
import { TranscribeAudioWithSplitting } from "./baseSpeechToText.js";
|
|
2
3
|
/**
|
|
3
|
-
* Base class for
|
|
4
|
-
* sub-classes
|
|
5
|
-
*
|
|
4
|
+
* Base class for audio models that carries both text-to-speech and speech-to-text. Not all
|
|
5
|
+
* sub-classes support all methods: an unsupported method throws, and `GetSupportedMethods` names
|
|
6
|
+
* the ones a sub-class implements.
|
|
7
|
+
*
|
|
8
|
+
* It spans two model types (`TTS` and `Speech to Text`), so it has been split. It stays, and keeps
|
|
9
|
+
* working, for drivers and callers that already use it: it implements both halves, so any of its
|
|
10
|
+
* drivers can be used where either new base class is expected. The drivers MemberJunction ships
|
|
11
|
+
* still extend it and are also registered against the new class or classes they implement, under
|
|
12
|
+
* the same keys.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Use {@link BaseTextToSpeech} for text-to-speech and {@link BaseSpeechToText} for
|
|
15
|
+
* speech-to-text. An application that overrides a shipped audio driver must also register the
|
|
16
|
+
* override against the new class or classes that driver implements, under the same key, for example
|
|
17
|
+
* `@RegisterClass(BaseTextToSpeech, 'OpenAIAudioGenerator')`. The ClassFactory keeps registrations
|
|
18
|
+
* per base class, and the text-to-speech and speech-to-text runners resolve drivers through the new
|
|
19
|
+
* classes, so an override registered only against `BaseAudioGenerator` is not used by them.
|
|
6
20
|
*/
|
|
7
21
|
export class BaseAudioGenerator extends BaseModel {
|
|
8
22
|
/**
|
|
9
|
-
* Transcribes audio that may exceed the provider's upload ceiling, splitting it first when
|
|
10
|
-
*
|
|
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.
|
|
23
|
+
* Transcribes audio that may exceed the provider's upload ceiling, splitting it first when it
|
|
24
|
+
* does. See {@link TranscribeAudioWithSplitting}, which this calls, for the behavior.
|
|
19
25
|
*
|
|
20
26
|
* @param audio The full audio to transcribe
|
|
21
27
|
* @param maxUploadBytes The provider's hard upload ceiling
|
|
@@ -25,42 +31,7 @@ export class BaseAudioGenerator extends BaseModel {
|
|
|
25
31
|
* @param transcribeOne Transcribes a single piece already known to be within the ceiling
|
|
26
32
|
*/
|
|
27
33
|
async TranscribeWithSplitting(audio, maxUploadBytes, splitTargetBytes, splitter, providerLabel, transcribeOne) {
|
|
28
|
-
|
|
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
|
-
};
|
|
34
|
+
return TranscribeAudioWithSplitting(audio, maxUploadBytes, splitTargetBytes, splitter, providerLabel, transcribeOne);
|
|
64
35
|
}
|
|
65
36
|
}
|
|
66
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseAudio.js","sourceRoot":"","sources":["../../src/generic/baseAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"baseAudio.js","sourceRoot":"","sources":["../../src/generic/baseAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAGhE,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAgBlE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,SAAS;IAQtD;;;;;;;;;;OAUG;IACO,KAAK,CAAC,uBAAuB,CACnC,KAAa,EACb,cAAsB,EACtB,gBAAwB,EACxB,QAA8B,EAC9B,aAAqB,EACrB,aAA6D;QAE7D,OAAO,4BAA4B,CAAC,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IACzH,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;CAmCxB;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"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Base class for MemberJunction AI Decision providers.
|
|
3
|
+
*
|
|
4
|
+
* This abstract class defines the contract for typed decision models that return
|
|
5
|
+
* enumerated answers with probabilities instead of free text.
|
|
6
|
+
*
|
|
7
|
+
* @module @memberjunction/ai
|
|
8
|
+
*/
|
|
9
|
+
import { BaseModel } from './baseModel.js';
|
|
10
|
+
import { DecisionParams, DecisionResult } from './decision.types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Abstract base class for typed decision model implementations.
|
|
13
|
+
* Subclasses wrap provider APIs to produce structured Likelihood, Choice, and Score answers.
|
|
14
|
+
*
|
|
15
|
+
* Implementations should:
|
|
16
|
+
* 1. Register with `@RegisterClass(BaseDecision, 'ProviderName')`
|
|
17
|
+
* 2. Implement the protected `DoDecide()` method
|
|
18
|
+
* 3. Honor `params.CancellationToken`, which the base does not check
|
|
19
|
+
*
|
|
20
|
+
* `Decide()` validates the request before calling `DoDecide()` and the answers after it,
|
|
21
|
+
* so a driver does not repeat those checks.
|
|
22
|
+
*
|
|
23
|
+
* Example:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* @RegisterClass(BaseDecision, 'ExampleDecision')
|
|
26
|
+
* export class ExampleDecision extends BaseDecision {
|
|
27
|
+
* protected async DoDecide(params: DecisionParams): Promise<DecisionResult> {
|
|
28
|
+
* // Call the provider and map its output onto DecisionAnswer shapes
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const decider = MJGlobal.Instance.ClassFactory.CreateInstance<BaseDecision>(BaseDecision, 'ExampleDecision', apiKey);
|
|
33
|
+
* const result = await decider.Decide(params);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare abstract class BaseDecision extends BaseModel {
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of BaseDecision.
|
|
39
|
+
* @param apiKey The API key for the decision service provider.
|
|
40
|
+
*/
|
|
41
|
+
constructor(apiKey: string);
|
|
42
|
+
/**
|
|
43
|
+
* Executes a typed decision request across one or more questions about a given state.
|
|
44
|
+
* This method wraps driver execution with input validation, output verification,
|
|
45
|
+
* execution timing, and structured error handling. It never throws.
|
|
46
|
+
*
|
|
47
|
+
* @param params Decision request parameters including state, questions, and model.
|
|
48
|
+
* @returns A Promise resolving to a DecisionResult.
|
|
49
|
+
*/
|
|
50
|
+
Decide(params: DecisionParams): Promise<DecisionResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Driver-specific implementation of the decision logic.
|
|
53
|
+
* Must be implemented by concrete provider subclasses.
|
|
54
|
+
* Returned probabilities must already be normalised, in range, and keyed correctly.
|
|
55
|
+
*
|
|
56
|
+
* The driver owns cancellation: `Decide()` passes `params.CancellationToken` through
|
|
57
|
+
* unchecked, so the driver should check it before calling the provider and hand it to
|
|
58
|
+
* the provider's HTTP client.
|
|
59
|
+
*
|
|
60
|
+
* @param params Decision parameters to evaluate.
|
|
61
|
+
* @returns A Promise resolving to a DecisionResult.
|
|
62
|
+
*/
|
|
63
|
+
protected abstract DoDecide(params: DecisionParams): Promise<DecisionResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Validates input DecisionParams against the decision contract.
|
|
66
|
+
*
|
|
67
|
+
* @param params Parameters to validate.
|
|
68
|
+
* @returns An array of error descriptions, empty if valid.
|
|
69
|
+
*/
|
|
70
|
+
protected ValidateParams(params: DecisionParams): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Validates that State is a non-empty string once trimmed, or an object with at least one key.
|
|
73
|
+
*/
|
|
74
|
+
private validateState;
|
|
75
|
+
/**
|
|
76
|
+
* Validates the Questions map.
|
|
77
|
+
*/
|
|
78
|
+
private validateQuestions;
|
|
79
|
+
/**
|
|
80
|
+
* Validates a single question definition.
|
|
81
|
+
*/
|
|
82
|
+
private validateSingleQuestion;
|
|
83
|
+
/**
|
|
84
|
+
* Validates a ChoiceQuestion's options (>= 2 options, unique non-empty Values, non-empty Descriptions).
|
|
85
|
+
*/
|
|
86
|
+
private validateChoiceQuestion;
|
|
87
|
+
/**
|
|
88
|
+
* Validates a ScoreQuestion's levels (>= 2 levels, unique non-empty levels).
|
|
89
|
+
*/
|
|
90
|
+
private validateScoreQuestion;
|
|
91
|
+
/**
|
|
92
|
+
* Validates driver output DecisionResult against the requested questions.
|
|
93
|
+
*
|
|
94
|
+
* @param params Original decision request parameters.
|
|
95
|
+
* @param result Result returned by the driver.
|
|
96
|
+
* @returns An array of error descriptions, empty if valid.
|
|
97
|
+
*/
|
|
98
|
+
protected ValidateAnswers(params: DecisionParams, result: DecisionResult): string[];
|
|
99
|
+
/**
|
|
100
|
+
* Validates a single answer against its corresponding question.
|
|
101
|
+
*/
|
|
102
|
+
private validateSingleAnswer;
|
|
103
|
+
/**
|
|
104
|
+
* Validates a LikelihoodAnswer (Probability in [0, 1]).
|
|
105
|
+
*/
|
|
106
|
+
private validateLikelihoodAnswer;
|
|
107
|
+
/**
|
|
108
|
+
* Validates a ChoiceAnswer (Value in options, Confidence in [0, 1], Probabilities match options and sum to 1 +-0.01).
|
|
109
|
+
*/
|
|
110
|
+
private validateChoiceAnswer;
|
|
111
|
+
/**
|
|
112
|
+
* Validates a ScoreAnswer (Value in [0, Levels.length - 1], Confidence in [0, 1], Probabilities match levels and sum to 1 +-0.01).
|
|
113
|
+
*/
|
|
114
|
+
private validateScoreAnswer;
|
|
115
|
+
/**
|
|
116
|
+
* Validates that a probability distribution exactly matches the expected keys,
|
|
117
|
+
* has valid numbers in [0, 1], and sums to 1 within +-0.01 tolerance.
|
|
118
|
+
*/
|
|
119
|
+
private validateProbabilityDistribution;
|
|
120
|
+
/**
|
|
121
|
+
* Checks if a value is a finite number in [0, 1].
|
|
122
|
+
*/
|
|
123
|
+
private isProbabilityInUnitInterval;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=baseDecision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseDecision.d.ts","sourceRoot":"","sources":["../../src/generic/baseDecision.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAIH,cAAc,EAEd,cAAc,EAIjB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8BAAsB,YAAa,SAAQ,SAAS;IAChD;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;;OAOG;IACU,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAsDpE;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAE5E;;;;;OAKG;IACH,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE;IAW1D;;OAEG;IACH,OAAO,CAAC,aAAa;IAgBrB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA2B9B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA4B9B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAoB7B;;;;;;OAMG;IACH,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE;IAyCnF;;OAEG;IAC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