@memberjunction/ai 3.4.0 → 4.1.0
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/README.md +242 -0
- package/dist/generic/apiKeyDictionary.d.ts +22 -0
- package/dist/generic/apiKeyDictionary.d.ts.map +1 -1
- package/dist/generic/apiKeyDictionary.js +20 -13
- package/dist/generic/apiKeyDictionary.js.map +1 -1
- package/dist/generic/baseAudio.d.ts +107 -2
- package/dist/generic/baseAudio.d.ts.map +1 -1
- package/dist/generic/baseAudio.js +26 -20
- package/dist/generic/baseAudio.js.map +1 -1
- package/dist/generic/baseDiffusion.d.ts +5 -1
- package/dist/generic/baseDiffusion.d.ts.map +1 -1
- package/dist/generic/baseDiffusion.js +5 -17
- package/dist/generic/baseDiffusion.js.map +1 -1
- package/dist/generic/baseEmbeddings.d.ts +25 -2
- package/dist/generic/baseEmbeddings.d.ts.map +1 -1
- package/dist/generic/baseEmbeddings.js +26 -8
- package/dist/generic/baseEmbeddings.js.map +1 -1
- package/dist/generic/baseImage.d.ts +262 -2
- package/dist/generic/baseImage.d.ts.map +1 -1
- package/dist/generic/baseImage.js +83 -20
- package/dist/generic/baseImage.js.map +1 -1
- package/dist/generic/baseLLM.d.ts +100 -4
- package/dist/generic/baseLLM.d.ts.map +1 -1
- package/dist/generic/baseLLM.js +122 -14
- package/dist/generic/baseLLM.js.map +1 -1
- package/dist/generic/baseModel.d.ts +91 -0
- package/dist/generic/baseModel.d.ts.map +1 -1
- package/dist/generic/baseModel.js +37 -11
- package/dist/generic/baseModel.js.map +1 -1
- package/dist/generic/baseReranker.d.ts +81 -2
- package/dist/generic/baseReranker.d.ts.map +1 -1
- package/dist/generic/baseReranker.js +73 -6
- package/dist/generic/baseReranker.js.map +1 -1
- package/dist/generic/baseVideo.d.ts +24 -1
- package/dist/generic/baseVideo.d.ts.map +1 -1
- package/dist/generic/baseVideo.js +11 -14
- package/dist/generic/baseVideo.js.map +1 -1
- package/dist/generic/chat.types.d.ts +291 -2
- package/dist/generic/chat.types.d.ts.map +1 -1
- package/dist/generic/chat.types.js +105 -32
- package/dist/generic/chat.types.js.map +1 -1
- package/dist/generic/classify.types.d.ts +5 -2
- package/dist/generic/classify.types.d.ts.map +1 -1
- package/dist/generic/classify.types.js +8 -11
- package/dist/generic/classify.types.js.map +1 -1
- package/dist/generic/embed.types.d.ts +1 -1
- package/dist/generic/embed.types.js +1 -2
- package/dist/generic/errorAnalyzer.d.ts +94 -0
- package/dist/generic/errorAnalyzer.d.ts.map +1 -1
- package/dist/generic/errorAnalyzer.js +160 -28
- package/dist/generic/errorAnalyzer.js.map +1 -1
- package/dist/generic/errorTypes.d.ts +116 -0
- package/dist/generic/errorTypes.d.ts.map +1 -1
- package/dist/generic/errorTypes.js +1 -2
- package/dist/generic/reranker.types.d.ts +74 -0
- package/dist/generic/reranker.types.d.ts.map +1 -1
- package/dist/generic/reranker.types.js +10 -2
- package/dist/generic/reranker.types.js.map +1 -1
- package/dist/generic/summarize.types.d.ts +5 -2
- package/dist/generic/summarize.types.d.ts.map +1 -1
- package/dist/generic/summarize.types.js +8 -9
- package/dist/generic/summarize.types.js.map +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.js +15 -31
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/readme.md +167 -967
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"baseModel.d.ts","sourceRoot":"","sources":["../../src/generic/baseModel.ts"],"names":[],"mappings":"AAAA,O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CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;OAKG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;CACJ;AAED;;GAEG;AACH,8BAAsB,SAAS;IAC3B,OAAO,CAAC,OAAO,CAAS;IACxB;;OAEG;IACH,SAAS,KAAK,MAAM,IAAI,MAAM,CAE7B;gBACY,MAAM,EAAE,MAAM;CAM9B"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseModel = exports.ModelUsage = exports.BaseParams = exports.BaseResult = void 0;
|
|
4
|
-
class BaseResult {
|
|
1
|
+
export class BaseResult {
|
|
5
2
|
get timeElapsed() {
|
|
6
3
|
return this.endTime.getTime() - this.startTime.getTime();
|
|
7
4
|
}
|
|
@@ -11,14 +8,33 @@ class BaseResult {
|
|
|
11
8
|
this.endTime = endTime;
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
class BaseParams {
|
|
11
|
+
export class BaseParams {
|
|
16
12
|
constructor() {
|
|
13
|
+
/**
|
|
14
|
+
* Specifies the format that the model should output. Not all models support all formats. If not specified, the default is 'Any'.
|
|
15
|
+
*/
|
|
17
16
|
this.responseFormat = 'Any';
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Represents token usage and cost information for an AI model execution.
|
|
21
|
+
*
|
|
22
|
+
* This class tracks the number of tokens used in both the prompt (input) and
|
|
23
|
+
* completion (output) phases of an AI model execution, along with optional
|
|
24
|
+
* cost information when provided by the AI provider.
|
|
25
|
+
*
|
|
26
|
+
* @class ModelUsage
|
|
27
|
+
* @since 2.43.0
|
|
28
|
+
*/
|
|
29
|
+
export class ModelUsage {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new ModelUsage instance.
|
|
32
|
+
*
|
|
33
|
+
* @param {number} promptTokens - Number of tokens used in the prompt/input
|
|
34
|
+
* @param {number} completionTokens - Number of tokens generated in the completion/output
|
|
35
|
+
* @param {number} [cost] - Optional cost of the execution
|
|
36
|
+
* @param {string} [costCurrency] - Optional currency code for the cost (e.g., 'USD', 'EUR', 'GBP')
|
|
37
|
+
*/
|
|
22
38
|
constructor(promptTokens, completionTokens, cost, costCurrency) {
|
|
23
39
|
this.promptTokens = promptTokens;
|
|
24
40
|
this.completionTokens = completionTokens;
|
|
@@ -29,12 +45,23 @@ class ModelUsage {
|
|
|
29
45
|
this.costCurrency = costCurrency;
|
|
30
46
|
}
|
|
31
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Calculated total number of tokens (prompt + completion).
|
|
50
|
+
* This is useful for tracking overall token usage against limits.
|
|
51
|
+
*
|
|
52
|
+
* @returns {number} The sum of promptTokens and completionTokens
|
|
53
|
+
*/
|
|
32
54
|
get totalTokens() {
|
|
33
55
|
return this.promptTokens + this.completionTokens;
|
|
34
56
|
}
|
|
35
57
|
}
|
|
36
|
-
|
|
37
|
-
class
|
|
58
|
+
/**
|
|
59
|
+
* Base AI model class, used for everything else in the MemberJunction AI environment
|
|
60
|
+
*/
|
|
61
|
+
export class BaseModel {
|
|
62
|
+
/**
|
|
63
|
+
* Only sub-classes can access the API key
|
|
64
|
+
*/
|
|
38
65
|
get apiKey() {
|
|
39
66
|
return this._apiKey;
|
|
40
67
|
}
|
|
@@ -44,5 +71,4 @@ class BaseModel {
|
|
|
44
71
|
this._apiKey = apiKey;
|
|
45
72
|
}
|
|
46
73
|
}
|
|
47
|
-
exports.BaseModel = BaseModel;
|
|
48
74
|
//# sourceMappingURL=baseModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseModel.js","sourceRoot":"","sources":["../../src/generic/baseModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseModel.js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O,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;QAE9F,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -1,13 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Abstract base class for AI reranker implementations.
|
|
3
|
+
*
|
|
4
|
+
* Provides the foundation for semantic reranking providers (Cohere, LLM-based, etc.)
|
|
5
|
+
* following the same patterns as BaseLLM and BaseEmbeddings.
|
|
6
|
+
*
|
|
7
|
+
* Implementations should:
|
|
8
|
+
* 1. Register with @RegisterClass(BaseReranker, 'ProviderName')
|
|
9
|
+
* 2. Implement the protected doRerank() method
|
|
10
|
+
* 3. Handle provider-specific API calls and response mapping
|
|
11
|
+
*
|
|
12
|
+
* @module @memberjunction/ai
|
|
13
|
+
* @since 3.0.0
|
|
14
|
+
*/
|
|
15
|
+
import { BaseModel } from './baseModel.js';
|
|
16
|
+
import { RerankParams, RerankResponse, RerankResult } from './reranker.types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Abstract base class for all reranker implementations.
|
|
19
|
+
* Extends BaseModel to follow MJ conventions for AI model classes.
|
|
20
|
+
*
|
|
21
|
+
* Provides common functionality including:
|
|
22
|
+
* - Input validation
|
|
23
|
+
* - Response standardization
|
|
24
|
+
* - Utility methods for sorting and filtering results
|
|
25
|
+
*
|
|
26
|
+
* Example usage:
|
|
27
|
+
* ```typescript
|
|
28
|
+
* @RegisterClass(BaseReranker, 'CohereReranker')
|
|
29
|
+
* export class CohereReranker extends BaseReranker {
|
|
30
|
+
* protected async doRerank(params: RerankParams): Promise<RerankResult[]> {
|
|
31
|
+
* // Call Cohere API and return results
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
3
36
|
export declare abstract class BaseReranker extends BaseModel {
|
|
4
37
|
protected _modelName: string;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new reranker instance.
|
|
40
|
+
* @param apiKey - API key for the reranking service (e.g., Cohere API key)
|
|
41
|
+
* @param modelName - Optional model name to use (provider-specific)
|
|
42
|
+
*/
|
|
5
43
|
constructor(apiKey: string, modelName?: string);
|
|
44
|
+
/**
|
|
45
|
+
* Get the model name used for this reranker
|
|
46
|
+
*/
|
|
6
47
|
get ModelName(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Rerank documents based on their relevance to a query.
|
|
50
|
+
* This is the main entry point for reranking operations.
|
|
51
|
+
*
|
|
52
|
+
* The method:
|
|
53
|
+
* 1. Validates input parameters
|
|
54
|
+
* 2. Calls the provider-specific doRerank() implementation
|
|
55
|
+
* 3. Applies topK limit if specified
|
|
56
|
+
* 4. Returns standardized RerankResponse
|
|
57
|
+
*
|
|
58
|
+
* @param params - Reranking parameters including query and documents
|
|
59
|
+
* @returns Promise resolving to RerankResponse with reranked results
|
|
60
|
+
*/
|
|
7
61
|
Rerank(params: RerankParams): Promise<RerankResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Provider-specific reranking implementation.
|
|
64
|
+
* Subclasses must implement this method to perform the actual reranking.
|
|
65
|
+
*
|
|
66
|
+
* Implementation requirements:
|
|
67
|
+
* - Call the provider's reranking API
|
|
68
|
+
* - Map results to RerankResult format
|
|
69
|
+
* - Sort results by relevance score (highest first)
|
|
70
|
+
* - Preserve document metadata for zero-copy retrieval
|
|
71
|
+
*
|
|
72
|
+
* @param params - Reranking parameters
|
|
73
|
+
* @returns Promise resolving to array of RerankResult sorted by relevance
|
|
74
|
+
*/
|
|
8
75
|
protected abstract doRerank(params: RerankParams): Promise<RerankResult[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Create a standardized error response.
|
|
78
|
+
* Used internally when validation fails or an exception occurs.
|
|
79
|
+
*/
|
|
9
80
|
protected createErrorResponse(message: string, startTime: number): RerankResponse;
|
|
81
|
+
/**
|
|
82
|
+
* Sort results by relevance score in descending order.
|
|
83
|
+
* Utility method for implementations.
|
|
84
|
+
*/
|
|
10
85
|
protected sortByRelevance(results: RerankResult[]): RerankResult[];
|
|
86
|
+
/**
|
|
87
|
+
* Filter results by minimum relevance threshold.
|
|
88
|
+
* Utility method for implementations that need to filter low-scoring results.
|
|
89
|
+
*/
|
|
11
90
|
protected filterByThreshold(results: RerankResult[], minScore: number): RerankResult[];
|
|
12
91
|
}
|
|
13
92
|
//# sourceMappingURL=baseReranker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseReranker.d.ts","sourceRoot":"","sources":["../../src/generic/baseReranker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseReranker.d.ts","sourceRoot":"","sources":["../../src/generic/baseReranker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,8BAAsB,YAAa,SAAQ,SAAS;IAChD,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;gBACS,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAK9C;;OAEG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED;;;;;;;;;;;;OAYG;IACU,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAuDlE;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAE1E;;;OAGG;IACH,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc;IAUjF;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE;IAIlE;;;OAGG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE;CAGzF"}
|
|
@@ -1,18 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Abstract base class for AI reranker implementations.
|
|
3
|
+
*
|
|
4
|
+
* Provides the foundation for semantic reranking providers (Cohere, LLM-based, etc.)
|
|
5
|
+
* following the same patterns as BaseLLM and BaseEmbeddings.
|
|
6
|
+
*
|
|
7
|
+
* Implementations should:
|
|
8
|
+
* 1. Register with @RegisterClass(BaseReranker, 'ProviderName')
|
|
9
|
+
* 2. Implement the protected doRerank() method
|
|
10
|
+
* 3. Handle provider-specific API calls and response mapping
|
|
11
|
+
*
|
|
12
|
+
* @module @memberjunction/ai
|
|
13
|
+
* @since 3.0.0
|
|
14
|
+
*/
|
|
15
|
+
import { BaseModel } from './baseModel.js';
|
|
16
|
+
/**
|
|
17
|
+
* Abstract base class for all reranker implementations.
|
|
18
|
+
* Extends BaseModel to follow MJ conventions for AI model classes.
|
|
19
|
+
*
|
|
20
|
+
* Provides common functionality including:
|
|
21
|
+
* - Input validation
|
|
22
|
+
* - Response standardization
|
|
23
|
+
* - Utility methods for sorting and filtering results
|
|
24
|
+
*
|
|
25
|
+
* Example usage:
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @RegisterClass(BaseReranker, 'CohereReranker')
|
|
28
|
+
* export class CohereReranker extends BaseReranker {
|
|
29
|
+
* protected async doRerank(params: RerankParams): Promise<RerankResult[]> {
|
|
30
|
+
* // Call Cohere API and return results
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class BaseReranker extends BaseModel {
|
|
36
|
+
/**
|
|
37
|
+
* Create a new reranker instance.
|
|
38
|
+
* @param apiKey - API key for the reranking service (e.g., Cohere API key)
|
|
39
|
+
* @param modelName - Optional model name to use (provider-specific)
|
|
40
|
+
*/
|
|
6
41
|
constructor(apiKey, modelName) {
|
|
7
42
|
super(apiKey);
|
|
8
43
|
this._modelName = modelName || '';
|
|
9
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the model name used for this reranker
|
|
47
|
+
*/
|
|
10
48
|
get ModelName() {
|
|
11
49
|
return this._modelName;
|
|
12
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Rerank documents based on their relevance to a query.
|
|
53
|
+
* This is the main entry point for reranking operations.
|
|
54
|
+
*
|
|
55
|
+
* The method:
|
|
56
|
+
* 1. Validates input parameters
|
|
57
|
+
* 2. Calls the provider-specific doRerank() implementation
|
|
58
|
+
* 3. Applies topK limit if specified
|
|
59
|
+
* 4. Returns standardized RerankResponse
|
|
60
|
+
*
|
|
61
|
+
* @param params - Reranking parameters including query and documents
|
|
62
|
+
* @returns Promise resolving to RerankResponse with reranked results
|
|
63
|
+
*/
|
|
13
64
|
async Rerank(params) {
|
|
14
65
|
const startTime = Date.now();
|
|
15
66
|
try {
|
|
67
|
+
// Validate input
|
|
16
68
|
if (!params.query || params.query.trim().length === 0) {
|
|
17
69
|
return this.createErrorResponse('Query cannot be empty', startTime);
|
|
18
70
|
}
|
|
@@ -24,15 +76,19 @@ class BaseReranker extends baseModel_1.BaseModel {
|
|
|
24
76
|
modelName: this._modelName
|
|
25
77
|
};
|
|
26
78
|
}
|
|
79
|
+
// Validate all documents have required fields
|
|
27
80
|
for (let i = 0; i < params.documents.length; i++) {
|
|
28
81
|
const doc = params.documents[i];
|
|
29
82
|
if (!doc.id || !doc.text) {
|
|
30
83
|
return this.createErrorResponse(`Document at index ${i} missing required field (id or text)`, startTime);
|
|
31
84
|
}
|
|
32
85
|
}
|
|
86
|
+
// Call provider-specific implementation
|
|
33
87
|
const results = await this.doRerank(params);
|
|
88
|
+
// Apply topK limit if specified
|
|
34
89
|
const topK = params.topK || results.length;
|
|
35
90
|
const limitedResults = results.slice(0, topK);
|
|
91
|
+
// Update rank values after limiting
|
|
36
92
|
const rankedResults = limitedResults.map((r, idx) => ({
|
|
37
93
|
...r,
|
|
38
94
|
rank: idx
|
|
@@ -50,6 +106,10 @@ class BaseReranker extends baseModel_1.BaseModel {
|
|
|
50
106
|
return this.createErrorResponse(message, startTime);
|
|
51
107
|
}
|
|
52
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a standardized error response.
|
|
111
|
+
* Used internally when validation fails or an exception occurs.
|
|
112
|
+
*/
|
|
53
113
|
createErrorResponse(message, startTime) {
|
|
54
114
|
return {
|
|
55
115
|
success: false,
|
|
@@ -59,12 +119,19 @@ class BaseReranker extends baseModel_1.BaseModel {
|
|
|
59
119
|
modelName: this._modelName
|
|
60
120
|
};
|
|
61
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Sort results by relevance score in descending order.
|
|
124
|
+
* Utility method for implementations.
|
|
125
|
+
*/
|
|
62
126
|
sortByRelevance(results) {
|
|
63
127
|
return [...results].sort((a, b) => b.relevanceScore - a.relevanceScore);
|
|
64
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Filter results by minimum relevance threshold.
|
|
131
|
+
* Utility method for implementations that need to filter low-scoring results.
|
|
132
|
+
*/
|
|
65
133
|
filterByThreshold(results, minScore) {
|
|
66
134
|
return results.filter(r => r.relevanceScore >= minScore);
|
|
67
135
|
}
|
|
68
136
|
}
|
|
69
|
-
exports.BaseReranker = BaseReranker;
|
|
70
137
|
//# sourceMappingURL=baseReranker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseReranker.js","sourceRoot":"","sources":["../../src/generic/baseReranker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseReranker.js","sourceRoot":"","sources":["../../src/generic/baseReranker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGx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ACN,CAAC;IAED;;;OAGG;IACO,eAAe,CAAC,OAAuB;QAC7C,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,OAAuB,EAAE,QAAgB;QACjE,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,IAAI,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACJ"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { BaseModel } from "./baseModel";
|
|
1
|
+
import { BaseModel } from "./baseModel.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all video generation models. Each AI model will have a sub-class implementing the abstract methods in this base class. Not all
|
|
4
|
+
* sub-classes will support all methods. If a method is not supported an exception will be thrown, use the GetSupportedMethods method to determine
|
|
5
|
+
* what methods are supported by a specific sub-class.
|
|
6
|
+
*/
|
|
2
7
|
export declare abstract class BaseVideoGenerator extends BaseModel {
|
|
3
8
|
abstract CreateAvatarVideo(params: AvatarVideoParams): Promise<VideoResult>;
|
|
4
9
|
abstract CreateVideoTranslation(params: VideoTranslationParams): Promise<VideoResult>;
|
|
@@ -7,7 +12,13 @@ export declare abstract class BaseVideoGenerator extends BaseModel {
|
|
|
7
12
|
}
|
|
8
13
|
export declare class VideoResult {
|
|
9
14
|
success: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* When success == false, this will contain the error message
|
|
17
|
+
*/
|
|
10
18
|
errorMessage?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Platform-specific video ID for the generated video when success == true
|
|
21
|
+
*/
|
|
11
22
|
videoId: string;
|
|
12
23
|
}
|
|
13
24
|
export declare class AvatarInfo {
|
|
@@ -21,9 +32,21 @@ export declare class AvatarInfo {
|
|
|
21
32
|
export declare class VideoTranslationParams {
|
|
22
33
|
}
|
|
23
34
|
export declare class AvatarVideoParams {
|
|
35
|
+
/**
|
|
36
|
+
* Title of the video for storage in the provider's history
|
|
37
|
+
*/
|
|
24
38
|
title: string;
|
|
39
|
+
/**
|
|
40
|
+
* Generate captions for the video if true, otherwise do not generate captions
|
|
41
|
+
*/
|
|
25
42
|
caption?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Width of the requested video such as 1280 for 1280 pixels
|
|
45
|
+
*/
|
|
26
46
|
outputWidth: number;
|
|
47
|
+
/**
|
|
48
|
+
* Height of the requested video such as 720 for 720 pixels
|
|
49
|
+
*/
|
|
27
50
|
outputHeight: number;
|
|
28
51
|
avatarId: string;
|
|
29
52
|
scale: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseVideo.d.ts","sourceRoot":"","sources":["../../src/generic/baseVideo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"baseVideo.d.ts","sourceRoot":"","sources":["../../src/generic/baseVideo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AACH,8BAAsB,kBAAmB,SAAQ,SAAS;aACtC,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;aAClE,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;aAC5E,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;aACnC,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAC3D;AAED,qBAAa,WAAW;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,qBAAa,UAAU;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,sBAAsB;CAElC;AAED,qBAAa,iBAAiB;IAC1B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB,QAAQ,EAAE,MAAM,CAAC;IAEjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { BaseModel } from "./baseModel.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all video generation models. Each AI model will have a sub-class implementing the abstract methods in this base class. Not all
|
|
4
|
+
* sub-classes will support all methods. If a method is not supported an exception will be thrown, use the GetSupportedMethods method to determine
|
|
5
|
+
* what methods are supported by a specific sub-class.
|
|
6
|
+
*/
|
|
7
|
+
export class BaseVideoGenerator extends BaseModel {
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
class VideoResult {
|
|
9
|
+
export class VideoResult {
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
class AvatarInfo {
|
|
11
|
+
export class AvatarInfo {
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
class VideoTranslationParams {
|
|
13
|
+
export class VideoTranslationParams {
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
class AvatarVideoParams {
|
|
15
|
+
export class AvatarVideoParams {
|
|
18
16
|
}
|
|
19
|
-
exports.AvatarVideoParams = AvatarVideoParams;
|
|
20
17
|
//# sourceMappingURL=baseVideo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseVideo.js","sourceRoot":"","sources":["../../src/generic/baseVideo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseVideo.js","sourceRoot":"","sources":["../../src/generic/baseVideo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,SAAS;CAKzD;AAED,MAAM,OAAO,WAAW;CAUvB;AAED,MAAM,OAAO,UAAU;CAOtB;AAED,MAAM,OAAO,sBAAsB;CAElC;AAED,MAAM,OAAO,iBAAiB;CA2B7B"}
|