@coreviz/sdk 1.0.3 → 1.0.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/coreviz.d.ts +2 -0
- package/dist/coreviz.js +56 -0
- package/package.json +3 -2
package/dist/coreviz.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface TagResponse {
|
|
|
21
21
|
}
|
|
22
22
|
export interface EmbedOptions {
|
|
23
23
|
type?: 'image' | 'text';
|
|
24
|
+
mode?: 'api' | 'local';
|
|
24
25
|
}
|
|
25
26
|
export interface EmbedResponse {
|
|
26
27
|
embedding: number[];
|
|
@@ -35,5 +36,6 @@ export declare class CoreViz {
|
|
|
35
36
|
edit(image: string, options: EditOptions): Promise<string>;
|
|
36
37
|
tag(image: string, options: TagOptions): Promise<TagResponse>;
|
|
37
38
|
embed(input: string, options?: EmbedOptions): Promise<EmbedResponse>;
|
|
39
|
+
private embedLocal;
|
|
38
40
|
resize(input: string | File, maxWidth?: number, maxHeight?: number): Promise<string>;
|
|
39
41
|
}
|
package/dist/coreviz.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.CoreViz = void 0;
|
|
4
37
|
const resize_1 = require("./resize");
|
|
@@ -102,6 +135,10 @@ class CoreViz {
|
|
|
102
135
|
}
|
|
103
136
|
}
|
|
104
137
|
async embed(input, options) {
|
|
138
|
+
const mode = options?.mode || 'api';
|
|
139
|
+
if (mode === 'local') {
|
|
140
|
+
return this.embedLocal(input, options);
|
|
141
|
+
}
|
|
105
142
|
try {
|
|
106
143
|
const headers = this.getHeaders();
|
|
107
144
|
let body = {};
|
|
@@ -134,6 +171,25 @@ class CoreViz {
|
|
|
134
171
|
throw err instanceof Error ? err : new Error("An unexpected error occurred.");
|
|
135
172
|
}
|
|
136
173
|
}
|
|
174
|
+
async embedLocal(input, options) {
|
|
175
|
+
try {
|
|
176
|
+
// Dynamic import to avoid loading transformers if not used
|
|
177
|
+
const { pipeline } = await Promise.resolve().then(() => __importStar(require('@huggingface/transformers')));
|
|
178
|
+
// Initialize the pipeline with the specified model
|
|
179
|
+
// This will automatically download and cache the model if not present
|
|
180
|
+
const extractor = await pipeline('feature-extraction', 'Xenova/clip-vit-large-patch14');
|
|
181
|
+
// Generate embeddings
|
|
182
|
+
// transformers.js handles text strings, image URLs, and image paths automatically
|
|
183
|
+
const output = await extractor(input, { pooling: 'mean', normalize: true });
|
|
184
|
+
// Convert Float32Array to regular array
|
|
185
|
+
// @ts-ignore - Output type inference might fail with dynamic import
|
|
186
|
+
const embedding = Array.from(output.data);
|
|
187
|
+
return { embedding };
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
throw err instanceof Error ? err : new Error("Local embedding failed: " + String(err));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
137
193
|
async resize(input, maxWidth, maxHeight) {
|
|
138
194
|
return (0, resize_1.resize)(input, maxWidth, maxHeight);
|
|
139
195
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreviz/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "CoreViz SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"typescript": "^5.9.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"sharp": "^0.34.5"
|
|
35
|
+
"sharp": "^0.34.5",
|
|
36
|
+
"@huggingface/transformers": "^3.8.0"
|
|
36
37
|
}
|
|
37
38
|
}
|