@memberjunction/ai 2.133.0 → 3.0.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.
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BaseModel, BaseResult, ModelUsage } from "./baseModel";
|
|
3
|
+
export declare class GeneratedImage {
|
|
4
|
+
data?: Buffer;
|
|
5
|
+
base64?: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
format: 'png' | 'jpg' | 'jpeg' | 'webp' | 'gif';
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
index?: number;
|
|
11
|
+
contentFilterResults?: ContentFilterResult;
|
|
12
|
+
}
|
|
13
|
+
export interface ContentFilterResult {
|
|
14
|
+
filtered: boolean;
|
|
15
|
+
reason?: string;
|
|
16
|
+
categories?: Record<string, boolean>;
|
|
17
|
+
}
|
|
18
|
+
export declare class ImageGenerationResult extends BaseResult {
|
|
19
|
+
images: GeneratedImage[];
|
|
20
|
+
revisedPrompt?: string;
|
|
21
|
+
usage?: ModelUsage;
|
|
22
|
+
metadata?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export type ImageSize = '256x256' | '512x512' | '1024x1024' | '1024x1792' | '1792x1024' | '1536x1024' | '1024x1536' | string;
|
|
25
|
+
export type ImageQuality = 'standard' | 'hd' | 'low' | 'medium' | 'high';
|
|
26
|
+
export type ImageStyle = 'vivid' | 'natural' | 'photorealistic' | 'artistic' | 'anime' | string;
|
|
27
|
+
export type ImageResponseFormat = 'url' | 'b64_json' | 'buffer';
|
|
28
|
+
export declare class ImageGenerationParams {
|
|
29
|
+
model?: string;
|
|
30
|
+
prompt: string;
|
|
31
|
+
negativePrompt?: string;
|
|
32
|
+
n?: number;
|
|
33
|
+
size?: ImageSize;
|
|
34
|
+
quality?: ImageQuality;
|
|
35
|
+
style?: ImageStyle;
|
|
36
|
+
outputFormat?: ImageResponseFormat;
|
|
37
|
+
seed?: number;
|
|
38
|
+
aspectRatio?: string;
|
|
39
|
+
user?: string;
|
|
40
|
+
providerOptions?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export declare class ImageEditParams {
|
|
43
|
+
model?: string;
|
|
44
|
+
image: Buffer | string;
|
|
45
|
+
prompt: string;
|
|
46
|
+
mask?: Buffer | string;
|
|
47
|
+
negativePrompt?: string;
|
|
48
|
+
n?: number;
|
|
49
|
+
size?: ImageSize;
|
|
50
|
+
outputFormat?: ImageResponseFormat;
|
|
51
|
+
providerOptions?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
export declare class ImageVariationParams {
|
|
54
|
+
model?: string;
|
|
55
|
+
image: Buffer | string;
|
|
56
|
+
prompt?: string;
|
|
57
|
+
n?: number;
|
|
58
|
+
size?: ImageSize;
|
|
59
|
+
outputFormat?: ImageResponseFormat;
|
|
60
|
+
strength?: number;
|
|
61
|
+
providerOptions?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
export declare class ImageModelInfo {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
supportedSizes?: ImageSize[];
|
|
68
|
+
maxImages?: number;
|
|
69
|
+
supportsEditing?: boolean;
|
|
70
|
+
supportsVariations?: boolean;
|
|
71
|
+
supportsNegativePrompt?: boolean;
|
|
72
|
+
supportsSeed?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export declare abstract class BaseImageGenerator extends BaseModel {
|
|
75
|
+
abstract GenerateImage(params: ImageGenerationParams): Promise<ImageGenerationResult>;
|
|
76
|
+
abstract EditImage(params: ImageEditParams): Promise<ImageGenerationResult>;
|
|
77
|
+
abstract CreateVariation(params: ImageVariationParams): Promise<ImageGenerationResult>;
|
|
78
|
+
abstract GetModels(): Promise<ImageModelInfo[]>;
|
|
79
|
+
abstract GetSupportedMethods(): Promise<string[]>;
|
|
80
|
+
protected normalizeImageInput(input: Buffer | string): Promise<{
|
|
81
|
+
buffer: Buffer;
|
|
82
|
+
base64: string;
|
|
83
|
+
}>;
|
|
84
|
+
protected createSuccessResult(startTime: Date, images: GeneratedImage[]): ImageGenerationResult;
|
|
85
|
+
protected createErrorResult(startTime: Date, errorMessage: string): ImageGenerationResult;
|
|
86
|
+
}
|
|
87
|
+
export declare abstract class BaseDiffusion extends BaseImageGenerator {
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=baseImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseImage.d.ts","sourceRoot":"","sources":["../../src/generic/baseImage.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMhE,qBAAa,cAAc;IAIvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAMd,MAAM,CAAC,EAAE,MAAM,CAAC;IAOhB,GAAG,CAAC,EAAE,MAAM,CAAC;IAKb,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAS;IAKxD,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,oBAAoB,CAAC,EAAE,mBAAmB,CAAC;CAC9C;AAKD,MAAM,WAAW,mBAAmB;IAIhC,QAAQ,EAAE,OAAO,CAAC;IAKlB,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAKD,qBAAa,qBAAsB,SAAQ,UAAU;IAIjD,MAAM,EAAE,cAAc,EAAE,CAAM;IAM9B,aAAa,CAAC,EAAE,MAAM,CAAC;IAKvB,KAAK,CAAC,EAAE,UAAU,CAAC;IAKnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAMD,MAAM,MAA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AM,CAAA;KAAE,CAAC;IA+BxG,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,qBAAqB;IAS/F,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,GAAG,qBAAqB;CAK5F;AAKD,8BAAsB,aAAc,SAAQ,kBAAkB;CAC7D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseDiffusion = exports.BaseImageGenerator = exports.ImageModelInfo = exports.ImageVariationParams = exports.ImageEditParams = exports.ImageGenerationParams = exports.ImageGenerationResult = exports.GeneratedImage = void 0;
|
|
4
|
+
const baseModel_1 = require("./baseModel");
|
|
5
|
+
class GeneratedImage {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.format = 'png';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.GeneratedImage = GeneratedImage;
|
|
11
|
+
class ImageGenerationResult extends baseModel_1.BaseResult {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.images = [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ImageGenerationResult = ImageGenerationResult;
|
|
18
|
+
class ImageGenerationParams {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.n = 1;
|
|
21
|
+
this.size = '1024x1024';
|
|
22
|
+
this.quality = 'standard';
|
|
23
|
+
this.outputFormat = 'b64_json';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ImageGenerationParams = ImageGenerationParams;
|
|
27
|
+
class ImageEditParams {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.n = 1;
|
|
30
|
+
this.outputFormat = 'b64_json';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ImageEditParams = ImageEditParams;
|
|
34
|
+
class ImageVariationParams {
|
|
35
|
+
constructor() {
|
|
36
|
+
this.n = 1;
|
|
37
|
+
this.outputFormat = 'b64_json';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ImageVariationParams = ImageVariationParams;
|
|
41
|
+
class ImageModelInfo {
|
|
42
|
+
}
|
|
43
|
+
exports.ImageModelInfo = ImageModelInfo;
|
|
44
|
+
class BaseImageGenerator extends baseModel_1.BaseModel {
|
|
45
|
+
async normalizeImageInput(input) {
|
|
46
|
+
let buffer;
|
|
47
|
+
if (Buffer.isBuffer(input)) {
|
|
48
|
+
buffer = input;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof input === 'string') {
|
|
51
|
+
if (input.startsWith('http://') || input.startsWith('https://')) {
|
|
52
|
+
const response = await fetch(input);
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new Error(`Failed to fetch image from URL: ${response.statusText}`);
|
|
55
|
+
}
|
|
56
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
57
|
+
buffer = Buffer.from(arrayBuffer);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
buffer = Buffer.from(input, 'base64');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error('Image input must be a Buffer, base64 string, or URL');
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
buffer,
|
|
68
|
+
base64: buffer.toString('base64')
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
createSuccessResult(startTime, images) {
|
|
72
|
+
const result = new ImageGenerationResult(true, startTime, new Date());
|
|
73
|
+
result.images = images;
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
createErrorResult(startTime, errorMessage) {
|
|
77
|
+
const result = new ImageGenerationResult(false, startTime, new Date());
|
|
78
|
+
result.errorMessage = errorMessage;
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.BaseImageGenerator = BaseImageGenerator;
|
|
83
|
+
class BaseDiffusion extends BaseImageGenerator {
|
|
84
|
+
}
|
|
85
|
+
exports.BaseDiffusion = BaseDiffusion;
|
|
86
|
+
//# sourceMappingURL=baseImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseImage.js","sourceRoot":"","sources":["../../src/generic/baseImage.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAMhE,MAAa,cAAc;IAA3B;QAsBI,WAAM,GAA4C,KAAK,CAAC;IAqB5D,CAAC;CAAA;AA3CD,wCA2CC;AAyBD,MAAa,qBAAsB,SAAQ,sBAAU;IAArD;;QAII,WAAM,GAAqB,EAAE,CAAC;IAiBlC,CAAC;CAAA;AArBD,sDAqBC;AAkCD,MAAa,qBAAqB;IAAlC;QAqBI,MAAC,GAAY,CAAC,CAAC;QAKf,SAAI,GAAe,WAAW,CAAC;QAK/B,YAAO,GAAkB,UAAU,CAAC;QAUpC,iBAAY,GAAyB,UAAU,CAAC;IAuBpD,CAAC;CAAA;AAhED,sDAgEC;AAKD,MAAa,eAAe;IAA5B;QA+BI,MAAC,GAAY,CAAC,CAAC;QAUf,iBAAY,GAAyB,UAAU,CAAC;IAMpD,CAAC;CAAA;AA/CD,0CA+CC;AAKD,MAAa,oBAAoB;IAAjC;QAoBI,MAAC,GAAY,CAAC,CAAC;QAUf,iBAAY,GAAyB,UAAU,CAAC;IAWpD,CAAC;CAAA;AAzCD,oDAyCC;AAKD,MAAa,cAAc;CA6C1B;AA7CD,wCA6CC;AAQD,MAAsB,kBAAmB,SAAQ,qBAAS;IAoD5C,KAAK,CAAC,mBAAmB,CAAC,KAAsB;QACtD,IAAI,MAAc,CAAC;QAEnB,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,GAAG,KAAK,CAAC;QACnB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAI,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,KAAK,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|
{
|
|
2
2
|
"name": "@memberjunction/ai",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"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.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "MemberJunction.com",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@memberjunction/global": "
|
|
18
|
+
"@memberjunction/global": "3.0.0",
|
|
19
19
|
"dotenv": "^16.4.1",
|
|
20
20
|
"rxjs": "^7.8.1"
|
|
21
21
|
},
|