@aigne/aigne-hub 1.74.0-beta → 1.74.0-beta.10
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/{aigne-hub-model.cjs → aigne-hub-chat-model.cjs} +16 -10
- package/dist/aigne-hub-chat-model.d.cts +33 -0
- package/dist/aigne-hub-chat-model.d.cts.map +1 -0
- package/dist/aigne-hub-chat-model.d.mts +33 -0
- package/dist/aigne-hub-chat-model.d.mts.map +1 -0
- package/dist/{aigne-hub-model.mjs → aigne-hub-chat-model.mjs} +12 -6
- package/dist/aigne-hub-chat-model.mjs.map +1 -0
- package/dist/aigne-hub-embedding-model.cjs +98 -0
- package/dist/aigne-hub-embedding-model.d.cts +33 -0
- package/dist/aigne-hub-embedding-model.d.cts.map +1 -0
- package/dist/aigne-hub-embedding-model.d.mts +33 -0
- package/dist/aigne-hub-embedding-model.d.mts.map +1 -0
- package/dist/aigne-hub-embedding-model.mjs +99 -0
- package/dist/aigne-hub-embedding-model.mjs.map +1 -0
- package/dist/aigne-hub-image-model.cjs +15 -9
- package/dist/aigne-hub-image-model.d.cts +33 -0
- package/dist/aigne-hub-image-model.d.cts.map +1 -0
- package/dist/aigne-hub-image-model.d.mts +33 -0
- package/dist/aigne-hub-image-model.d.mts.map +1 -0
- package/dist/aigne-hub-image-model.mjs +10 -4
- package/dist/aigne-hub-image-model.mjs.map +1 -1
- package/dist/aigne-hub-video-model.cjs +15 -9
- package/dist/aigne-hub-video-model.d.cts +33 -0
- package/dist/aigne-hub-video-model.d.cts.map +1 -0
- package/dist/aigne-hub-video-model.d.mts +33 -0
- package/dist/aigne-hub-video-model.d.mts.map +1 -0
- package/dist/aigne-hub-video-model.mjs +10 -4
- package/dist/aigne-hub-video-model.mjs.map +1 -1
- package/dist/index.cjs +43 -4
- package/dist/index.d.cts +54 -19
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +54 -19
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +39 -4
- package/dist/index.mjs.map +1 -1
- package/dist/utils/blocklet.cjs +21 -3
- package/dist/utils/blocklet.d.cts.map +1 -1
- package/dist/utils/blocklet.d.mts.map +1 -1
- package/dist/utils/blocklet.mjs +20 -2
- package/dist/utils/blocklet.mjs.map +1 -1
- package/dist/utils/constants.cjs +2 -0
- package/dist/utils/constants.d.cts +2 -1
- package/dist/utils/constants.d.cts.map +1 -1
- package/dist/utils/constants.d.mts +2 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +2 -1
- package/dist/utils/constants.mjs.map +1 -1
- package/dist/utils/find-provider.d.cts.map +1 -1
- package/dist/utils/find-provider.d.mts.map +1 -1
- package/dist/utils/hub.cjs +2 -2
- package/dist/utils/hub.mjs +1 -1
- package/dist/utils/hub.mjs.map +1 -1
- package/dist/utils/model.cjs +46 -3
- package/dist/utils/model.d.cts +19 -4
- package/dist/utils/model.d.cts.map +1 -1
- package/dist/utils/model.d.mts +19 -4
- package/dist/utils/model.d.mts.map +1 -1
- package/dist/utils/model.mjs +45 -4
- package/dist/utils/model.mjs.map +1 -1
- package/dist/utils/type.d.cts +9 -2
- package/dist/utils/type.d.cts.map +1 -1
- package/dist/utils/type.d.mts +9 -2
- package/dist/utils/type.d.mts.map +1 -1
- package/dist/utils/type.mjs.map +1 -1
- package/package.json +29 -16
- package/LICENSE.md +0 -93
- package/dist/aigne-hub-model.mjs.map +0 -1
|
@@ -2,16 +2,16 @@ const require_blocklet = require('./utils/blocklet.cjs');
|
|
|
2
2
|
const require_constants = require('./utils/constants.cjs');
|
|
3
3
|
const require_hub = require('./utils/hub.cjs');
|
|
4
4
|
const require_type = require('./utils/type.cjs');
|
|
5
|
-
let
|
|
5
|
+
let _aigne_model_base = require("@aigne/model-base");
|
|
6
|
+
let _aigne_model_base_transport_base_client = require("@aigne/model-base/transport/base-client");
|
|
7
|
+
let _aigne_model_base_utils_nodejs = require("@aigne/model-base/utils/nodejs");
|
|
8
|
+
let _aigne_model_base_utils_type_utils = require("@aigne/model-base/utils/type-utils");
|
|
6
9
|
let ufo = require("ufo");
|
|
7
|
-
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
8
|
-
let _aigne_transport_http_client_base_client = require("@aigne/transport/http-client/base-client");
|
|
9
|
-
let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
|
|
10
10
|
|
|
11
|
-
//#region src/aigne-hub-model.ts
|
|
12
|
-
var AIGNEHubChatModel = class extends
|
|
11
|
+
//#region src/aigne-hub-chat-model.ts
|
|
12
|
+
var AIGNEHubChatModel = class extends _aigne_model_base.ChatModel {
|
|
13
13
|
constructor(options) {
|
|
14
|
-
(0,
|
|
14
|
+
(0, _aigne_model_base_utils_type_utils.checkArguments)("AIGNEHubChatModel", require_type.aigneHubModelOptionsSchema, options);
|
|
15
15
|
super();
|
|
16
16
|
this.options = options;
|
|
17
17
|
}
|
|
@@ -24,12 +24,15 @@ var AIGNEHubChatModel = class extends _aigne_core.ChatModel {
|
|
|
24
24
|
_client;
|
|
25
25
|
get client() {
|
|
26
26
|
this._client ??= this.credential.then(({ url, apiKey, model }) => {
|
|
27
|
-
return new
|
|
27
|
+
return new _aigne_model_base_transport_base_client.BaseClient({
|
|
28
28
|
...this.options,
|
|
29
29
|
url,
|
|
30
30
|
apiKey,
|
|
31
31
|
model
|
|
32
32
|
});
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
this._client = void 0;
|
|
35
|
+
throw err;
|
|
33
36
|
});
|
|
34
37
|
return this._client;
|
|
35
38
|
}
|
|
@@ -50,12 +53,15 @@ var AIGNEHubChatModel = class extends _aigne_core.ChatModel {
|
|
|
50
53
|
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
51
54
|
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || require_constants.AIGNE_HUB_DEFAULT_MODEL
|
|
52
55
|
};
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
this._credential = void 0;
|
|
58
|
+
throw err;
|
|
53
59
|
});
|
|
54
60
|
return this._credential;
|
|
55
61
|
}
|
|
56
62
|
async process(input, options) {
|
|
57
|
-
const { BLOCKLET_APP_PID, ABT_NODE_DID } =
|
|
58
|
-
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ?
|
|
63
|
+
const { BLOCKLET_APP_PID, ABT_NODE_DID } = _aigne_model_base_utils_nodejs.nodejs.env;
|
|
64
|
+
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? _aigne_model_base_utils_nodejs.nodejs.os.hostname() : "unknown"}`;
|
|
59
65
|
return await (await this.client).__invoke(void 0, {
|
|
60
66
|
...input,
|
|
61
67
|
modelOptions: {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIGNEHubChatModelOptions } from "./utils/type.cjs";
|
|
2
|
+
import { ChatModel, ChatModelInput, ChatModelOutput, ModelInvokeOptions, ModelProcessResult } from "@aigne/model-base";
|
|
3
|
+
import { BaseClient, BaseClientInvokeOptions } from "@aigne/model-base/transport/base-client";
|
|
4
|
+
|
|
5
|
+
//#region src/aigne-hub-chat-model.d.ts
|
|
6
|
+
declare class AIGNEHubChatModel extends ChatModel {
|
|
7
|
+
options: AIGNEHubChatModelOptions;
|
|
8
|
+
constructor(options: AIGNEHubChatModelOptions);
|
|
9
|
+
models(): Promise<{
|
|
10
|
+
model: string;
|
|
11
|
+
type: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
input_credits_per_token: string;
|
|
14
|
+
output_credits_per_token: string;
|
|
15
|
+
providerDisplayName: string;
|
|
16
|
+
status?: {
|
|
17
|
+
available: boolean;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
modelMetadata?: Record<string, unknown> | null | undefined;
|
|
20
|
+
}[]>;
|
|
21
|
+
protected _client?: Promise<BaseClient>;
|
|
22
|
+
get client(): Promise<BaseClient>;
|
|
23
|
+
private _credential?;
|
|
24
|
+
get credential(): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model: string;
|
|
28
|
+
}>;
|
|
29
|
+
process(input: ChatModelInput, options: BaseClientInvokeOptions & ModelInvokeOptions): Promise<ModelProcessResult<ChatModelOutput>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIGNEHubChatModel };
|
|
33
|
+
//# sourceMappingURL=aigne-hub-chat-model.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-chat-model.d.cts","names":[],"sources":["../src/aigne-hub-chat-model.ts"],"mappings":";;;;;cAoBa,iBAAA,SAA0B,SAAA;EACT,OAAA,EAAS,wBAAA;cAAT,OAAA,EAAS,wBAAA;EAK/B,MAAA,CAAA,GAAM,OAAA;;;;;;;;;;;;YAIF,OAAA,GAAU,OAAA,CAAQ,UAAA;EAAA,IAExB,MAAA,CAAA,GAAM,OAAA,CAAA,UAAA;EAAA,QAaF,WAAA;EAAA,IAMK,UAAA,CAAA,GAAU,OAAA;;;;;EAiCR,OAAA,CACb,KAAA,EAAO,cAAA,EACP,OAAA,EAAS,uBAAA,GAA0B,kBAAA,GAClC,OAAA,CAAQ,kBAAA,CAAmB,eAAA;AAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIGNEHubChatModelOptions } from "./utils/type.mjs";
|
|
2
|
+
import { ChatModel, ChatModelInput, ChatModelOutput, ModelInvokeOptions, ModelProcessResult } from "@aigne/model-base";
|
|
3
|
+
import { BaseClient, BaseClientInvokeOptions } from "@aigne/model-base/transport/base-client";
|
|
4
|
+
|
|
5
|
+
//#region src/aigne-hub-chat-model.d.ts
|
|
6
|
+
declare class AIGNEHubChatModel extends ChatModel {
|
|
7
|
+
options: AIGNEHubChatModelOptions;
|
|
8
|
+
constructor(options: AIGNEHubChatModelOptions);
|
|
9
|
+
models(): Promise<{
|
|
10
|
+
model: string;
|
|
11
|
+
type: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
input_credits_per_token: string;
|
|
14
|
+
output_credits_per_token: string;
|
|
15
|
+
providerDisplayName: string;
|
|
16
|
+
status?: {
|
|
17
|
+
available: boolean;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
modelMetadata?: Record<string, unknown> | null | undefined;
|
|
20
|
+
}[]>;
|
|
21
|
+
protected _client?: Promise<BaseClient>;
|
|
22
|
+
get client(): Promise<BaseClient>;
|
|
23
|
+
private _credential?;
|
|
24
|
+
get credential(): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model: string;
|
|
28
|
+
}>;
|
|
29
|
+
process(input: ChatModelInput, options: BaseClientInvokeOptions & ModelInvokeOptions): Promise<ModelProcessResult<ChatModelOutput>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIGNEHubChatModel };
|
|
33
|
+
//# sourceMappingURL=aigne-hub-chat-model.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-chat-model.d.mts","names":[],"sources":["../src/aigne-hub-chat-model.ts"],"mappings":";;;;;cAoBa,iBAAA,SAA0B,SAAA;EACT,OAAA,EAAS,wBAAA;cAAT,OAAA,EAAS,wBAAA;EAK/B,MAAA,CAAA,GAAM,OAAA;;;;;;;;;;;;YAIF,OAAA,GAAU,OAAA,CAAQ,UAAA;EAAA,IAExB,MAAA,CAAA,GAAM,OAAA,CAAA,UAAA;EAAA,QAaF,WAAA;EAAA,IAMK,UAAA,CAAA,GAAU,OAAA;;;;;EAiCR,OAAA,CACb,KAAA,EAAO,cAAA,EACP,OAAA,EAAS,uBAAA,GAA0B,kBAAA,GAClC,OAAA,CAAQ,kBAAA,CAAmB,eAAA;AAAA"}
|
|
@@ -2,13 +2,13 @@ import { getAIGNEHubMountPoint } from "./utils/blocklet.mjs";
|
|
|
2
2
|
import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_DEFAULT_MODEL, aigneHubBaseUrl } from "./utils/constants.mjs";
|
|
3
3
|
import { getModels } from "./utils/hub.mjs";
|
|
4
4
|
import { aigneHubModelOptionsSchema } from "./utils/type.mjs";
|
|
5
|
-
import { ChatModel } from "@aigne/
|
|
5
|
+
import { ChatModel } from "@aigne/model-base";
|
|
6
|
+
import { BaseClient } from "@aigne/model-base/transport/base-client";
|
|
7
|
+
import { nodejs } from "@aigne/model-base/utils/nodejs";
|
|
8
|
+
import { checkArguments } from "@aigne/model-base/utils/type-utils";
|
|
6
9
|
import { joinURL } from "ufo";
|
|
7
|
-
import { checkArguments } from "@aigne/core/utils/type-utils";
|
|
8
|
-
import { BaseClient } from "@aigne/transport/http-client/base-client";
|
|
9
|
-
import { nodejs } from "@aigne/utils/nodejs";
|
|
10
10
|
|
|
11
|
-
//#region src/aigne-hub-model.ts
|
|
11
|
+
//#region src/aigne-hub-chat-model.ts
|
|
12
12
|
var AIGNEHubChatModel = class extends ChatModel {
|
|
13
13
|
constructor(options) {
|
|
14
14
|
checkArguments("AIGNEHubChatModel", aigneHubModelOptionsSchema, options);
|
|
@@ -30,6 +30,9 @@ var AIGNEHubChatModel = class extends ChatModel {
|
|
|
30
30
|
apiKey,
|
|
31
31
|
model
|
|
32
32
|
});
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
this._client = void 0;
|
|
35
|
+
throw err;
|
|
33
36
|
});
|
|
34
37
|
return this._client;
|
|
35
38
|
}
|
|
@@ -50,6 +53,9 @@ var AIGNEHubChatModel = class extends ChatModel {
|
|
|
50
53
|
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
51
54
|
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_DEFAULT_MODEL
|
|
52
55
|
};
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
this._credential = void 0;
|
|
58
|
+
throw err;
|
|
53
59
|
});
|
|
54
60
|
return this._credential;
|
|
55
61
|
}
|
|
@@ -78,4 +84,4 @@ var AIGNEHubChatModel = class extends ChatModel {
|
|
|
78
84
|
|
|
79
85
|
//#endregion
|
|
80
86
|
export { AIGNEHubChatModel };
|
|
81
|
-
//# sourceMappingURL=aigne-hub-model.mjs.map
|
|
87
|
+
//# sourceMappingURL=aigne-hub-chat-model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-chat-model.mjs","names":[],"sources":["../src/aigne-hub-chat-model.ts"],"sourcesContent":["import {\n ChatModel,\n type ChatModelInput,\n type ChatModelOutput,\n type ModelInvokeOptions,\n type ModelProcessResult,\n} from \"@aigne/model-base\";\nimport { BaseClient, type BaseClientInvokeOptions } from \"@aigne/model-base/transport/base-client\";\nimport { nodejs } from \"@aigne/model-base/utils/nodejs\";\nimport { checkArguments } from \"@aigne/model-base/utils/type-utils\";\nimport { joinURL } from \"ufo\";\nimport { getAIGNEHubMountPoint } from \"./utils/blocklet.js\";\nimport {\n AIGNE_HUB_BLOCKLET_DID,\n AIGNE_HUB_DEFAULT_MODEL,\n aigneHubBaseUrl,\n} from \"./utils/constants.js\";\nimport { getModels } from \"./utils/hub.js\";\nimport { type AIGNEHubChatModelOptions, aigneHubModelOptionsSchema } from \"./utils/type.js\";\n\nexport class AIGNEHubChatModel extends ChatModel {\n constructor(public override options: AIGNEHubChatModelOptions) {\n checkArguments(\"AIGNEHubChatModel\", aigneHubModelOptionsSchema, options);\n super();\n }\n\n async models() {\n return getModels({ baseURL: (await this.credential).url, type: \"chat\" });\n }\n\n protected _client?: Promise<BaseClient>;\n\n get client() {\n this._client ??= this.credential\n .then(({ url, apiKey, model }) => {\n const options = { ...this.options, url, apiKey, model };\n return new BaseClient(options);\n })\n .catch((err) => {\n this._client = undefined;\n throw err;\n });\n return this._client;\n }\n\n private _credential?: Promise<{\n url: string;\n apiKey?: string;\n model: string;\n }>;\n\n override get credential() {\n this._credential ??= getAIGNEHubMountPoint(\n this.options.baseURL || aigneHubBaseUrl(),\n AIGNE_HUB_BLOCKLET_DID,\n )\n .then((url) => {\n const path = \"/api/v2/chat\";\n\n const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;\n let credentialOptions: Record<string, any> = {};\n try {\n credentialOptions =\n typeof rawCredential === \"string\" ? JSON.parse(rawCredential) : (rawCredential ?? {});\n } catch (err) {\n console.error(err);\n }\n\n return {\n ...credentialOptions,\n url: url.endsWith(path) ? url : joinURL(url, path),\n apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,\n model:\n this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_DEFAULT_MODEL,\n };\n })\n .catch((err) => {\n this._credential = undefined;\n throw err;\n });\n\n return this._credential;\n }\n\n override async process(\n input: ChatModelInput,\n options: BaseClientInvokeOptions & ModelInvokeOptions,\n ): Promise<ModelProcessResult<ChatModelOutput>> {\n const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;\n const clientId =\n this.options?.clientOptions?.clientId ||\n BLOCKLET_APP_PID ||\n ABT_NODE_DID ||\n `@aigne/aigne-hub:${typeof process !== \"undefined\" ? nodejs.os.hostname() : \"unknown\"}`;\n\n const response = await (await this.client).__invoke<ChatModelInput, ChatModelOutput>(\n undefined,\n {\n ...input,\n modelOptions: {\n ...input.modelOptions,\n model: input.modelOptions?.model || (await this.credential).model,\n },\n // Shouldn't use `local` output type for remote AIGNE Hub call, client can not access the remote filesystem\n outputFileType: \"url\",\n },\n {\n ...options,\n fetchOptions: {\n ...options.fetchOptions,\n headers: {\n ...options.fetchOptions?.headers,\n \"x-aigne-hub-client-did\": clientId,\n },\n },\n },\n );\n\n return response;\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,IAAa,oBAAb,cAAuC,UAAU;CAC/C,YAAY,AAAgB,SAAmC;AAC7D,iBAAe,qBAAqB,4BAA4B,QAAQ;AACxE,SAAO;EAFmB;;CAK5B,MAAM,SAAS;AACb,SAAO,UAAU;GAAE,UAAU,MAAM,KAAK,YAAY;GAAK,MAAM;GAAQ,CAAC;;CAG1E,AAAU;CAEV,IAAI,SAAS;AACX,OAAK,YAAY,KAAK,WACnB,MAAM,EAAE,KAAK,QAAQ,YAAY;AAEhC,UAAO,IAAI,WADK;IAAE,GAAG,KAAK;IAAS;IAAK;IAAQ;IAAO,CACzB;IAC9B,CACD,OAAO,QAAQ;AACd,QAAK,UAAU;AACf,SAAM;IACN;AACJ,SAAO,KAAK;;CAGd,AAAQ;CAMR,IAAa,aAAa;AACxB,OAAK,gBAAgB,sBACnB,KAAK,QAAQ,WAAW,iBAAiB,EACzC,uBACD,CACE,MAAM,QAAQ;GACb,MAAM,OAAO;GAEb,MAAM,gBAAgB,QAAQ,IAAI;GAClC,IAAI,oBAAyC,EAAE;AAC/C,OAAI;AACF,wBACE,OAAO,kBAAkB,WAAW,KAAK,MAAM,cAAc,GAAI,iBAAiB,EAAE;YAC/E,KAAK;AACZ,YAAQ,MAAM,IAAI;;AAGpB,UAAO;IACL,GAAG;IACH,KAAK,IAAI,SAAS,KAAK,GAAG,MAAM,QAAQ,KAAK,KAAK;IAClD,QAAQ,KAAK,QAAQ,UAAU,QAAQ,IAAI,qBAAqB,kBAAkB;IAClF,OACE,KAAK,QAAQ,SAAS,QAAQ,IAAI,4BAA4B;IACjE;IACD,CACD,OAAO,QAAQ;AACd,QAAK,cAAc;AACnB,SAAM;IACN;AAEJ,SAAO,KAAK;;CAGd,MAAe,QACb,OACA,SAC8C;EAC9C,MAAM,EAAE,kBAAkB,iBAAiB,OAAO;EAClD,MAAM,WACJ,KAAK,SAAS,eAAe,YAC7B,oBACA,gBACA,oBAAoB,OAAO,YAAY,cAAc,OAAO,GAAG,UAAU,GAAG;AAyB9E,SAvBiB,OAAO,MAAM,KAAK,QAAQ,SACzC,QACA;GACE,GAAG;GACH,cAAc;IACZ,GAAG,MAAM;IACT,OAAO,MAAM,cAAc,UAAU,MAAM,KAAK,YAAY;IAC7D;GAED,gBAAgB;GACjB,EACD;GACE,GAAG;GACH,cAAc;IACZ,GAAG,QAAQ;IACX,SAAS;KACP,GAAG,QAAQ,cAAc;KACzB,0BAA0B;KAC3B;IACF;GACF,CACF"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const require_blocklet = require('./utils/blocklet.cjs');
|
|
2
|
+
const require_constants = require('./utils/constants.cjs');
|
|
3
|
+
const require_hub = require('./utils/hub.cjs');
|
|
4
|
+
const require_type = require('./utils/type.cjs');
|
|
5
|
+
let _aigne_model_base = require("@aigne/model-base");
|
|
6
|
+
let _aigne_model_base_transport_base_client = require("@aigne/model-base/transport/base-client");
|
|
7
|
+
let _aigne_model_base_utils_nodejs = require("@aigne/model-base/utils/nodejs");
|
|
8
|
+
let _aigne_model_base_utils_type_utils = require("@aigne/model-base/utils/type-utils");
|
|
9
|
+
let ufo = require("ufo");
|
|
10
|
+
|
|
11
|
+
//#region src/aigne-hub-embedding-model.ts
|
|
12
|
+
var AIGNEHubEmbeddingModel = class extends _aigne_model_base.EmbeddingModel {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
(0, _aigne_model_base_utils_type_utils.checkArguments)("AIGNEHubEmbeddingModel", require_type.aigneHubModelOptionsSchema, options);
|
|
15
|
+
super();
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
async models() {
|
|
19
|
+
return require_hub.getModels({
|
|
20
|
+
baseURL: (await this.credential).url,
|
|
21
|
+
type: "embedding"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
_client;
|
|
25
|
+
get client() {
|
|
26
|
+
this._client ??= this.credential.then(({ url, apiKey, model }) => {
|
|
27
|
+
return new _aigne_model_base_transport_base_client.BaseClient({
|
|
28
|
+
...this.options,
|
|
29
|
+
url,
|
|
30
|
+
apiKey,
|
|
31
|
+
model
|
|
32
|
+
});
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
this._client = void 0;
|
|
35
|
+
throw err;
|
|
36
|
+
});
|
|
37
|
+
return this._client;
|
|
38
|
+
}
|
|
39
|
+
_credential;
|
|
40
|
+
get credential() {
|
|
41
|
+
this._credential ??= require_blocklet.getAIGNEHubMountPoint(this.options.baseURL || require_constants.aigneHubBaseUrl(), require_constants.AIGNE_HUB_BLOCKLET_DID).then((url) => {
|
|
42
|
+
const path = "/api/v2/embeddings";
|
|
43
|
+
const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
|
|
44
|
+
let credentialOptions = {};
|
|
45
|
+
try {
|
|
46
|
+
credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error(err);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...credentialOptions,
|
|
52
|
+
url: url.endsWith(path) ? url : (0, ufo.joinURL)(url, path),
|
|
53
|
+
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
54
|
+
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || require_constants.AIGNE_HUB_EMBEDDING_MODEL
|
|
55
|
+
};
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
this._credential = void 0;
|
|
58
|
+
throw err;
|
|
59
|
+
});
|
|
60
|
+
return this._credential;
|
|
61
|
+
}
|
|
62
|
+
async process(input, options) {
|
|
63
|
+
const { BLOCKLET_APP_PID, ABT_NODE_DID } = _aigne_model_base_utils_nodejs.nodejs.env;
|
|
64
|
+
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? _aigne_model_base_utils_nodejs.nodejs.os.hostname() : "unknown"}`;
|
|
65
|
+
const response = await (await this.client).__invoke(void 0, {
|
|
66
|
+
...input,
|
|
67
|
+
modelOptions: {
|
|
68
|
+
...input.modelOptions,
|
|
69
|
+
model: input.modelOptions?.model || (await this.credential).model
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
...options,
|
|
73
|
+
streaming: false,
|
|
74
|
+
fetchOptions: {
|
|
75
|
+
...options.fetchOptions,
|
|
76
|
+
headers: {
|
|
77
|
+
...options.fetchOptions?.headers,
|
|
78
|
+
"x-aigne-hub-client-did": clientId
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const usage = {
|
|
83
|
+
inputTokens: response.usage?.inputTokens ?? 0,
|
|
84
|
+
outputTokens: response.usage?.outputTokens ?? 0,
|
|
85
|
+
...response.usage
|
|
86
|
+
};
|
|
87
|
+
if (!usage.creditPrefix) delete usage.creditPrefix;
|
|
88
|
+
return {
|
|
89
|
+
...response,
|
|
90
|
+
embeddings: response.embeddings,
|
|
91
|
+
usage,
|
|
92
|
+
model: response?.model
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
exports.AIGNEHubEmbeddingModel = AIGNEHubEmbeddingModel;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIGNEHubEmbeddingModelOptions } from "./utils/type.cjs";
|
|
2
|
+
import { EmbeddingModel, EmbeddingModelInput, EmbeddingModelOutput, ModelProcessResult } from "@aigne/model-base";
|
|
3
|
+
import { BaseClient, BaseClientInvokeOptions } from "@aigne/model-base/transport/base-client";
|
|
4
|
+
|
|
5
|
+
//#region src/aigne-hub-embedding-model.d.ts
|
|
6
|
+
declare class AIGNEHubEmbeddingModel extends EmbeddingModel {
|
|
7
|
+
options: AIGNEHubEmbeddingModelOptions;
|
|
8
|
+
constructor(options: AIGNEHubEmbeddingModelOptions);
|
|
9
|
+
models(): Promise<{
|
|
10
|
+
model: string;
|
|
11
|
+
type: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
input_credits_per_token: string;
|
|
14
|
+
output_credits_per_token: string;
|
|
15
|
+
providerDisplayName: string;
|
|
16
|
+
status?: {
|
|
17
|
+
available: boolean;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
modelMetadata?: Record<string, unknown> | null | undefined;
|
|
20
|
+
}[]>;
|
|
21
|
+
protected _client?: Promise<BaseClient>;
|
|
22
|
+
get client(): Promise<BaseClient>;
|
|
23
|
+
private _credential?;
|
|
24
|
+
get credential(): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model: string;
|
|
28
|
+
}>;
|
|
29
|
+
process(input: EmbeddingModelInput, options: BaseClientInvokeOptions): Promise<ModelProcessResult<EmbeddingModelOutput>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIGNEHubEmbeddingModel };
|
|
33
|
+
//# sourceMappingURL=aigne-hub-embedding-model.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-embedding-model.d.cts","names":[],"sources":["../src/aigne-hub-embedding-model.ts"],"mappings":";;;;;cAmBa,sBAAA,SAA+B,cAAA;EACd,OAAA,EAAS,6BAAA;cAAT,OAAA,EAAS,6BAAA;EAK/B,MAAA,CAAA,GAAM,OAAA;;;;;;;;;;;;YAIF,OAAA,GAAU,OAAA,CAAQ,UAAA;EAAA,IAExB,MAAA,CAAA,GAAM,OAAA,CAAA,UAAA;EAAA,QAaF,WAAA;EAAA,IAMK,UAAA,CAAA,GAAU,OAAA;;;;;EAiCR,OAAA,CACb,KAAA,EAAO,mBAAA,EACP,OAAA,EAAS,uBAAA,GACR,OAAA,CAAQ,kBAAA,CAAmB,oBAAA;AAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIGNEHubEmbeddingModelOptions } from "./utils/type.mjs";
|
|
2
|
+
import { EmbeddingModel, EmbeddingModelInput, EmbeddingModelOutput, ModelProcessResult } from "@aigne/model-base";
|
|
3
|
+
import { BaseClient, BaseClientInvokeOptions } from "@aigne/model-base/transport/base-client";
|
|
4
|
+
|
|
5
|
+
//#region src/aigne-hub-embedding-model.d.ts
|
|
6
|
+
declare class AIGNEHubEmbeddingModel extends EmbeddingModel {
|
|
7
|
+
options: AIGNEHubEmbeddingModelOptions;
|
|
8
|
+
constructor(options: AIGNEHubEmbeddingModelOptions);
|
|
9
|
+
models(): Promise<{
|
|
10
|
+
model: string;
|
|
11
|
+
type: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
input_credits_per_token: string;
|
|
14
|
+
output_credits_per_token: string;
|
|
15
|
+
providerDisplayName: string;
|
|
16
|
+
status?: {
|
|
17
|
+
available: boolean;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
modelMetadata?: Record<string, unknown> | null | undefined;
|
|
20
|
+
}[]>;
|
|
21
|
+
protected _client?: Promise<BaseClient>;
|
|
22
|
+
get client(): Promise<BaseClient>;
|
|
23
|
+
private _credential?;
|
|
24
|
+
get credential(): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model: string;
|
|
28
|
+
}>;
|
|
29
|
+
process(input: EmbeddingModelInput, options: BaseClientInvokeOptions): Promise<ModelProcessResult<EmbeddingModelOutput>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIGNEHubEmbeddingModel };
|
|
33
|
+
//# sourceMappingURL=aigne-hub-embedding-model.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-embedding-model.d.mts","names":[],"sources":["../src/aigne-hub-embedding-model.ts"],"mappings":";;;;;cAmBa,sBAAA,SAA+B,cAAA;EACd,OAAA,EAAS,6BAAA;cAAT,OAAA,EAAS,6BAAA;EAK/B,MAAA,CAAA,GAAM,OAAA;;;;;;;;;;;;YAIF,OAAA,GAAU,OAAA,CAAQ,UAAA;EAAA,IAExB,MAAA,CAAA,GAAM,OAAA,CAAA,UAAA;EAAA,QAaF,WAAA;EAAA,IAMK,UAAA,CAAA,GAAU,OAAA;;;;;EAiCR,OAAA,CACb,KAAA,EAAO,mBAAA,EACP,OAAA,EAAS,uBAAA,GACR,OAAA,CAAQ,kBAAA,CAAmB,oBAAA;AAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getAIGNEHubMountPoint } from "./utils/blocklet.mjs";
|
|
2
|
+
import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_EMBEDDING_MODEL, aigneHubBaseUrl } from "./utils/constants.mjs";
|
|
3
|
+
import { getModels } from "./utils/hub.mjs";
|
|
4
|
+
import { aigneHubModelOptionsSchema } from "./utils/type.mjs";
|
|
5
|
+
import { EmbeddingModel } from "@aigne/model-base";
|
|
6
|
+
import { BaseClient } from "@aigne/model-base/transport/base-client";
|
|
7
|
+
import { nodejs } from "@aigne/model-base/utils/nodejs";
|
|
8
|
+
import { checkArguments } from "@aigne/model-base/utils/type-utils";
|
|
9
|
+
import { joinURL } from "ufo";
|
|
10
|
+
|
|
11
|
+
//#region src/aigne-hub-embedding-model.ts
|
|
12
|
+
var AIGNEHubEmbeddingModel = class extends EmbeddingModel {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
checkArguments("AIGNEHubEmbeddingModel", aigneHubModelOptionsSchema, options);
|
|
15
|
+
super();
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
async models() {
|
|
19
|
+
return getModels({
|
|
20
|
+
baseURL: (await this.credential).url,
|
|
21
|
+
type: "embedding"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
_client;
|
|
25
|
+
get client() {
|
|
26
|
+
this._client ??= this.credential.then(({ url, apiKey, model }) => {
|
|
27
|
+
return new BaseClient({
|
|
28
|
+
...this.options,
|
|
29
|
+
url,
|
|
30
|
+
apiKey,
|
|
31
|
+
model
|
|
32
|
+
});
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
this._client = void 0;
|
|
35
|
+
throw err;
|
|
36
|
+
});
|
|
37
|
+
return this._client;
|
|
38
|
+
}
|
|
39
|
+
_credential;
|
|
40
|
+
get credential() {
|
|
41
|
+
this._credential ??= getAIGNEHubMountPoint(this.options.baseURL || aigneHubBaseUrl(), AIGNE_HUB_BLOCKLET_DID).then((url) => {
|
|
42
|
+
const path = "/api/v2/embeddings";
|
|
43
|
+
const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
|
|
44
|
+
let credentialOptions = {};
|
|
45
|
+
try {
|
|
46
|
+
credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error(err);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...credentialOptions,
|
|
52
|
+
url: url.endsWith(path) ? url : joinURL(url, path),
|
|
53
|
+
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
54
|
+
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_EMBEDDING_MODEL
|
|
55
|
+
};
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
this._credential = void 0;
|
|
58
|
+
throw err;
|
|
59
|
+
});
|
|
60
|
+
return this._credential;
|
|
61
|
+
}
|
|
62
|
+
async process(input, options) {
|
|
63
|
+
const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;
|
|
64
|
+
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? nodejs.os.hostname() : "unknown"}`;
|
|
65
|
+
const response = await (await this.client).__invoke(void 0, {
|
|
66
|
+
...input,
|
|
67
|
+
modelOptions: {
|
|
68
|
+
...input.modelOptions,
|
|
69
|
+
model: input.modelOptions?.model || (await this.credential).model
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
...options,
|
|
73
|
+
streaming: false,
|
|
74
|
+
fetchOptions: {
|
|
75
|
+
...options.fetchOptions,
|
|
76
|
+
headers: {
|
|
77
|
+
...options.fetchOptions?.headers,
|
|
78
|
+
"x-aigne-hub-client-did": clientId
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const usage = {
|
|
83
|
+
inputTokens: response.usage?.inputTokens ?? 0,
|
|
84
|
+
outputTokens: response.usage?.outputTokens ?? 0,
|
|
85
|
+
...response.usage
|
|
86
|
+
};
|
|
87
|
+
if (!usage.creditPrefix) delete usage.creditPrefix;
|
|
88
|
+
return {
|
|
89
|
+
...response,
|
|
90
|
+
embeddings: response.embeddings,
|
|
91
|
+
usage,
|
|
92
|
+
model: response?.model
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { AIGNEHubEmbeddingModel };
|
|
99
|
+
//# sourceMappingURL=aigne-hub-embedding-model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-embedding-model.mjs","names":[],"sources":["../src/aigne-hub-embedding-model.ts"],"sourcesContent":["import {\n EmbeddingModel,\n type EmbeddingModelInput,\n type EmbeddingModelOutput,\n type ModelProcessResult,\n} from \"@aigne/model-base\";\nimport { BaseClient, type BaseClientInvokeOptions } from \"@aigne/model-base/transport/base-client\";\nimport { nodejs } from \"@aigne/model-base/utils/nodejs\";\nimport { checkArguments } from \"@aigne/model-base/utils/type-utils\";\nimport { joinURL } from \"ufo\";\nimport { getAIGNEHubMountPoint } from \"./utils/blocklet.js\";\nimport {\n AIGNE_HUB_BLOCKLET_DID,\n AIGNE_HUB_EMBEDDING_MODEL,\n aigneHubBaseUrl,\n} from \"./utils/constants.js\";\nimport { getModels } from \"./utils/hub.js\";\nimport { type AIGNEHubEmbeddingModelOptions, aigneHubModelOptionsSchema } from \"./utils/type.js\";\n\nexport class AIGNEHubEmbeddingModel extends EmbeddingModel {\n constructor(public override options: AIGNEHubEmbeddingModelOptions) {\n checkArguments(\"AIGNEHubEmbeddingModel\", aigneHubModelOptionsSchema, options);\n super();\n }\n\n async models() {\n return getModels({ baseURL: (await this.credential).url, type: \"embedding\" });\n }\n\n protected _client?: Promise<BaseClient>;\n\n get client() {\n this._client ??= this.credential\n .then(({ url, apiKey, model }) => {\n const options = { ...this.options, url, apiKey, model };\n return new BaseClient(options);\n })\n .catch((err) => {\n this._client = undefined;\n throw err;\n });\n return this._client;\n }\n\n private _credential?: Promise<{\n url: string;\n apiKey?: string;\n model: string;\n }>;\n\n override get credential() {\n this._credential ??= getAIGNEHubMountPoint(\n this.options.baseURL || aigneHubBaseUrl(),\n AIGNE_HUB_BLOCKLET_DID,\n )\n .then((url) => {\n const path = \"/api/v2/embeddings\";\n\n const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;\n let credentialOptions: Record<string, any> = {};\n try {\n credentialOptions =\n typeof rawCredential === \"string\" ? JSON.parse(rawCredential) : (rawCredential ?? {});\n } catch (err) {\n console.error(err);\n }\n\n return {\n ...credentialOptions,\n url: url.endsWith(path) ? url : joinURL(url, path),\n apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,\n model:\n this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_EMBEDDING_MODEL,\n };\n })\n .catch((err) => {\n this._credential = undefined;\n throw err;\n });\n\n return this._credential;\n }\n\n override async process(\n input: EmbeddingModelInput,\n options: BaseClientInvokeOptions,\n ): Promise<ModelProcessResult<EmbeddingModelOutput>> {\n const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;\n const clientId =\n this.options?.clientOptions?.clientId ||\n BLOCKLET_APP_PID ||\n ABT_NODE_DID ||\n `@aigne/aigne-hub:${typeof process !== \"undefined\" ? nodejs.os.hostname() : \"unknown\"}`;\n\n const response = await (await this.client).__invoke<EmbeddingModelInput, EmbeddingModelOutput>(\n undefined,\n {\n ...input,\n modelOptions: {\n ...input.modelOptions,\n model: input.modelOptions?.model || (await this.credential).model,\n },\n },\n {\n ...options,\n streaming: false,\n fetchOptions: {\n ...options.fetchOptions,\n headers: {\n ...options.fetchOptions?.headers,\n \"x-aigne-hub-client-did\": clientId,\n },\n },\n },\n );\n\n const usage = {\n inputTokens: response.usage?.inputTokens ?? 0,\n outputTokens: response.usage?.outputTokens ?? 0,\n ...response.usage,\n };\n\n // Remote Hub may return empty string for creditPrefix, which fails zod validation\n if (!usage.creditPrefix) delete usage.creditPrefix;\n\n return {\n ...response,\n embeddings: response.embeddings,\n usage,\n model: response?.model,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAa,yBAAb,cAA4C,eAAe;CACzD,YAAY,AAAgB,SAAwC;AAClE,iBAAe,0BAA0B,4BAA4B,QAAQ;AAC7E,SAAO;EAFmB;;CAK5B,MAAM,SAAS;AACb,SAAO,UAAU;GAAE,UAAU,MAAM,KAAK,YAAY;GAAK,MAAM;GAAa,CAAC;;CAG/E,AAAU;CAEV,IAAI,SAAS;AACX,OAAK,YAAY,KAAK,WACnB,MAAM,EAAE,KAAK,QAAQ,YAAY;AAEhC,UAAO,IAAI,WADK;IAAE,GAAG,KAAK;IAAS;IAAK;IAAQ;IAAO,CACzB;IAC9B,CACD,OAAO,QAAQ;AACd,QAAK,UAAU;AACf,SAAM;IACN;AACJ,SAAO,KAAK;;CAGd,AAAQ;CAMR,IAAa,aAAa;AACxB,OAAK,gBAAgB,sBACnB,KAAK,QAAQ,WAAW,iBAAiB,EACzC,uBACD,CACE,MAAM,QAAQ;GACb,MAAM,OAAO;GAEb,MAAM,gBAAgB,QAAQ,IAAI;GAClC,IAAI,oBAAyC,EAAE;AAC/C,OAAI;AACF,wBACE,OAAO,kBAAkB,WAAW,KAAK,MAAM,cAAc,GAAI,iBAAiB,EAAE;YAC/E,KAAK;AACZ,YAAQ,MAAM,IAAI;;AAGpB,UAAO;IACL,GAAG;IACH,KAAK,IAAI,SAAS,KAAK,GAAG,MAAM,QAAQ,KAAK,KAAK;IAClD,QAAQ,KAAK,QAAQ,UAAU,QAAQ,IAAI,qBAAqB,kBAAkB;IAClF,OACE,KAAK,QAAQ,SAAS,QAAQ,IAAI,4BAA4B;IACjE;IACD,CACD,OAAO,QAAQ;AACd,QAAK,cAAc;AACnB,SAAM;IACN;AAEJ,SAAO,KAAK;;CAGd,MAAe,QACb,OACA,SACmD;EACnD,MAAM,EAAE,kBAAkB,iBAAiB,OAAO;EAClD,MAAM,WACJ,KAAK,SAAS,eAAe,YAC7B,oBACA,gBACA,oBAAoB,OAAO,YAAY,cAAc,OAAO,GAAG,UAAU,GAAG;EAE9E,MAAM,WAAW,OAAO,MAAM,KAAK,QAAQ,SACzC,QACA;GACE,GAAG;GACH,cAAc;IACZ,GAAG,MAAM;IACT,OAAO,MAAM,cAAc,UAAU,MAAM,KAAK,YAAY;IAC7D;GACF,EACD;GACE,GAAG;GACH,WAAW;GACX,cAAc;IACZ,GAAG,QAAQ;IACX,SAAS;KACP,GAAG,QAAQ,cAAc;KACzB,0BAA0B;KAC3B;IACF;GACF,CACF;EAED,MAAM,QAAQ;GACZ,aAAa,SAAS,OAAO,eAAe;GAC5C,cAAc,SAAS,OAAO,gBAAgB;GAC9C,GAAG,SAAS;GACb;AAGD,MAAI,CAAC,MAAM,aAAc,QAAO,MAAM;AAEtC,SAAO;GACL,GAAG;GACH,YAAY,SAAS;GACrB;GACA,OAAO,UAAU;GAClB"}
|
|
@@ -2,16 +2,16 @@ const require_blocklet = require('./utils/blocklet.cjs');
|
|
|
2
2
|
const require_constants = require('./utils/constants.cjs');
|
|
3
3
|
const require_hub = require('./utils/hub.cjs');
|
|
4
4
|
const require_type = require('./utils/type.cjs');
|
|
5
|
-
let
|
|
5
|
+
let _aigne_model_base = require("@aigne/model-base");
|
|
6
|
+
let _aigne_model_base_transport_base_client = require("@aigne/model-base/transport/base-client");
|
|
7
|
+
let _aigne_model_base_utils_nodejs = require("@aigne/model-base/utils/nodejs");
|
|
8
|
+
let _aigne_model_base_utils_type_utils = require("@aigne/model-base/utils/type-utils");
|
|
6
9
|
let ufo = require("ufo");
|
|
7
|
-
let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
|
|
8
|
-
let _aigne_transport_http_client_base_client = require("@aigne/transport/http-client/base-client");
|
|
9
|
-
let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
|
|
10
10
|
|
|
11
11
|
//#region src/aigne-hub-image-model.ts
|
|
12
|
-
var AIGNEHubImageModel = class extends
|
|
12
|
+
var AIGNEHubImageModel = class extends _aigne_model_base.ImageModel {
|
|
13
13
|
constructor(options) {
|
|
14
|
-
(0,
|
|
14
|
+
(0, _aigne_model_base_utils_type_utils.checkArguments)("AIGNEHubImageModel", require_type.aigneHubModelOptionsSchema, options);
|
|
15
15
|
super();
|
|
16
16
|
this.options = options;
|
|
17
17
|
}
|
|
@@ -24,12 +24,15 @@ var AIGNEHubImageModel = class extends _aigne_core.ImageModel {
|
|
|
24
24
|
_client;
|
|
25
25
|
get client() {
|
|
26
26
|
this._client ??= this.credential.then(({ url, apiKey, model }) => {
|
|
27
|
-
return new
|
|
27
|
+
return new _aigne_model_base_transport_base_client.BaseClient({
|
|
28
28
|
...this.options,
|
|
29
29
|
url,
|
|
30
30
|
apiKey,
|
|
31
31
|
model
|
|
32
32
|
});
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
this._client = void 0;
|
|
35
|
+
throw err;
|
|
33
36
|
});
|
|
34
37
|
return this._client;
|
|
35
38
|
}
|
|
@@ -50,12 +53,15 @@ var AIGNEHubImageModel = class extends _aigne_core.ImageModel {
|
|
|
50
53
|
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
51
54
|
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || require_constants.AIGNE_HUB_IMAGE_MODEL
|
|
52
55
|
};
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
this._credential = void 0;
|
|
58
|
+
throw err;
|
|
53
59
|
});
|
|
54
60
|
return this._credential;
|
|
55
61
|
}
|
|
56
62
|
async process(input, options) {
|
|
57
|
-
const { BLOCKLET_APP_PID, ABT_NODE_DID } =
|
|
58
|
-
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ?
|
|
63
|
+
const { BLOCKLET_APP_PID, ABT_NODE_DID } = _aigne_model_base_utils_nodejs.nodejs.env;
|
|
64
|
+
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? _aigne_model_base_utils_nodejs.nodejs.os.hostname() : "unknown"}`;
|
|
59
65
|
const response = await (await this.client).__invoke(void 0, {
|
|
60
66
|
...input,
|
|
61
67
|
modelOptions: {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIGNEHubImageModelOptions } from "./utils/type.cjs";
|
|
2
|
+
import { ImageModel, ImageModelInput, ImageModelOutput, ModelProcessResult } from "@aigne/model-base";
|
|
3
|
+
import { BaseClient, BaseClientInvokeOptions } from "@aigne/model-base/transport/base-client";
|
|
4
|
+
|
|
5
|
+
//#region src/aigne-hub-image-model.d.ts
|
|
6
|
+
declare class AIGNEHubImageModel extends ImageModel {
|
|
7
|
+
options: AIGNEHubImageModelOptions;
|
|
8
|
+
constructor(options: AIGNEHubImageModelOptions);
|
|
9
|
+
models(): Promise<{
|
|
10
|
+
model: string;
|
|
11
|
+
type: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
input_credits_per_token: string;
|
|
14
|
+
output_credits_per_token: string;
|
|
15
|
+
providerDisplayName: string;
|
|
16
|
+
status?: {
|
|
17
|
+
available: boolean;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
modelMetadata?: Record<string, unknown> | null | undefined;
|
|
20
|
+
}[]>;
|
|
21
|
+
protected _client?: Promise<BaseClient>;
|
|
22
|
+
get client(): Promise<BaseClient>;
|
|
23
|
+
private _credential?;
|
|
24
|
+
get credential(): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model: string;
|
|
28
|
+
}>;
|
|
29
|
+
process(input: ImageModelInput, options: BaseClientInvokeOptions): Promise<ModelProcessResult<ImageModelOutput>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIGNEHubImageModel };
|
|
33
|
+
//# sourceMappingURL=aigne-hub-image-model.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-image-model.d.cts","names":[],"sources":["../src/aigne-hub-image-model.ts"],"mappings":";;;;;cAmBa,kBAAA,SAA2B,UAAA;EACV,OAAA,EAAS,yBAAA;cAAT,OAAA,EAAS,yBAAA;EAK/B,MAAA,CAAA,GAAM,OAAA;;;;;;;;;;;;YAIF,OAAA,GAAU,OAAA,CAAQ,UAAA;EAAA,IAExB,MAAA,CAAA,GAAM,OAAA,CAAA,UAAA;EAAA,QAaF,WAAA;EAAA,IAMK,UAAA,CAAA,GAAU,OAAA;;;;;EAiCR,OAAA,CACb,KAAA,EAAO,eAAA,EACP,OAAA,EAAS,uBAAA,GACR,OAAA,CAAQ,kBAAA,CAAmB,gBAAA;AAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIGNEHubImageModelOptions } from "./utils/type.mjs";
|
|
2
|
+
import { ImageModel, ImageModelInput, ImageModelOutput, ModelProcessResult } from "@aigne/model-base";
|
|
3
|
+
import { BaseClient, BaseClientInvokeOptions } from "@aigne/model-base/transport/base-client";
|
|
4
|
+
|
|
5
|
+
//#region src/aigne-hub-image-model.d.ts
|
|
6
|
+
declare class AIGNEHubImageModel extends ImageModel {
|
|
7
|
+
options: AIGNEHubImageModelOptions;
|
|
8
|
+
constructor(options: AIGNEHubImageModelOptions);
|
|
9
|
+
models(): Promise<{
|
|
10
|
+
model: string;
|
|
11
|
+
type: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
input_credits_per_token: string;
|
|
14
|
+
output_credits_per_token: string;
|
|
15
|
+
providerDisplayName: string;
|
|
16
|
+
status?: {
|
|
17
|
+
available: boolean;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
modelMetadata?: Record<string, unknown> | null | undefined;
|
|
20
|
+
}[]>;
|
|
21
|
+
protected _client?: Promise<BaseClient>;
|
|
22
|
+
get client(): Promise<BaseClient>;
|
|
23
|
+
private _credential?;
|
|
24
|
+
get credential(): Promise<{
|
|
25
|
+
url: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model: string;
|
|
28
|
+
}>;
|
|
29
|
+
process(input: ImageModelInput, options: BaseClientInvokeOptions): Promise<ModelProcessResult<ImageModelOutput>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AIGNEHubImageModel };
|
|
33
|
+
//# sourceMappingURL=aigne-hub-image-model.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aigne-hub-image-model.d.mts","names":[],"sources":["../src/aigne-hub-image-model.ts"],"mappings":";;;;;cAmBa,kBAAA,SAA2B,UAAA;EACV,OAAA,EAAS,yBAAA;cAAT,OAAA,EAAS,yBAAA;EAK/B,MAAA,CAAA,GAAM,OAAA;;;;;;;;;;;;YAIF,OAAA,GAAU,OAAA,CAAQ,UAAA;EAAA,IAExB,MAAA,CAAA,GAAM,OAAA,CAAA,UAAA;EAAA,QAaF,WAAA;EAAA,IAMK,UAAA,CAAA,GAAU,OAAA;;;;;EAiCR,OAAA,CACb,KAAA,EAAO,eAAA,EACP,OAAA,EAAS,uBAAA,GACR,OAAA,CAAQ,kBAAA,CAAmB,gBAAA;AAAA"}
|
|
@@ -2,11 +2,11 @@ import { getAIGNEHubMountPoint } from "./utils/blocklet.mjs";
|
|
|
2
2
|
import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_IMAGE_MODEL, aigneHubBaseUrl } from "./utils/constants.mjs";
|
|
3
3
|
import { getModels } from "./utils/hub.mjs";
|
|
4
4
|
import { aigneHubModelOptionsSchema } from "./utils/type.mjs";
|
|
5
|
-
import { ImageModel } from "@aigne/
|
|
5
|
+
import { ImageModel } from "@aigne/model-base";
|
|
6
|
+
import { BaseClient } from "@aigne/model-base/transport/base-client";
|
|
7
|
+
import { nodejs } from "@aigne/model-base/utils/nodejs";
|
|
8
|
+
import { checkArguments } from "@aigne/model-base/utils/type-utils";
|
|
6
9
|
import { joinURL } from "ufo";
|
|
7
|
-
import { checkArguments } from "@aigne/core/utils/type-utils";
|
|
8
|
-
import { BaseClient } from "@aigne/transport/http-client/base-client";
|
|
9
|
-
import { nodejs } from "@aigne/utils/nodejs";
|
|
10
10
|
|
|
11
11
|
//#region src/aigne-hub-image-model.ts
|
|
12
12
|
var AIGNEHubImageModel = class extends ImageModel {
|
|
@@ -30,6 +30,9 @@ var AIGNEHubImageModel = class extends ImageModel {
|
|
|
30
30
|
apiKey,
|
|
31
31
|
model
|
|
32
32
|
});
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
this._client = void 0;
|
|
35
|
+
throw err;
|
|
33
36
|
});
|
|
34
37
|
return this._client;
|
|
35
38
|
}
|
|
@@ -50,6 +53,9 @@ var AIGNEHubImageModel = class extends ImageModel {
|
|
|
50
53
|
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
51
54
|
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_IMAGE_MODEL
|
|
52
55
|
};
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
this._credential = void 0;
|
|
58
|
+
throw err;
|
|
53
59
|
});
|
|
54
60
|
return this._credential;
|
|
55
61
|
}
|