@fraqjs/plugin-ai 0.1.0 → 0.1.1
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/index.d.mts +3 -1
- package/dist/index.mjs +9 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -21,6 +21,7 @@ interface AiServiceOptions {
|
|
|
21
21
|
}
|
|
22
22
|
declare class AiService {
|
|
23
23
|
private readonly options;
|
|
24
|
+
private defaultModel;
|
|
24
25
|
constructor(options: AiServiceOptions);
|
|
25
26
|
hasModel(name: string): boolean;
|
|
26
27
|
model(name?: string): LanguageModel;
|
|
@@ -28,8 +29,9 @@ declare class AiService {
|
|
|
28
29
|
}
|
|
29
30
|
//#endregion
|
|
30
31
|
//#region src/index.d.ts
|
|
32
|
+
type LanguageModelInstance = Exclude<LanguageModel, string>;
|
|
31
33
|
interface AiPluginOptions {
|
|
32
|
-
providers: Record<string, ProviderConfig | Record<string,
|
|
34
|
+
providers: Record<string, ProviderConfig | Record<string, LanguageModelInstance>>;
|
|
33
35
|
aliases?: Record<string, string>;
|
|
34
36
|
defaultModel?: string;
|
|
35
37
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -24,19 +24,23 @@ async function resolveLanguageModels(config) {
|
|
|
24
24
|
//#region src/service.ts
|
|
25
25
|
var AiService = class {
|
|
26
26
|
options;
|
|
27
|
+
defaultModel;
|
|
27
28
|
constructor(options) {
|
|
28
29
|
this.options = options;
|
|
29
|
-
|
|
30
|
+
const defaultModel = options.models[options.defaultModel] ?? options.models[options.aliases[options.defaultModel]];
|
|
31
|
+
if (!defaultModel) throw new Error(`Invalid default model "${options.defaultModel}": model does not exist.`);
|
|
32
|
+
this.defaultModel = defaultModel;
|
|
30
33
|
for (const [alias, target] of Object.entries(options.aliases)) if (!options.models[target]) throw new Error(`Invalid alias "${alias}": target model "${target}" does not exist.`);
|
|
31
34
|
}
|
|
32
35
|
hasModel(name) {
|
|
33
36
|
return !!this.options.models[name] || !!this.options.aliases[name];
|
|
34
37
|
}
|
|
35
38
|
model(name) {
|
|
36
|
-
|
|
39
|
+
if (!name) return this.defaultModel;
|
|
40
|
+
const modelByName = this.options.models[name];
|
|
37
41
|
if (modelByName) return modelByName;
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
42
|
+
const modelByAlias = this.options.aliases[name];
|
|
43
|
+
if (modelByAlias) return this.options.models[modelByAlias];
|
|
40
44
|
throw new Error(`Model not found: ${name}`);
|
|
41
45
|
}
|
|
42
46
|
models() {
|
|
@@ -46,7 +50,7 @@ var AiService = class {
|
|
|
46
50
|
//#endregion
|
|
47
51
|
//#region src/index.ts
|
|
48
52
|
function isProviderConfig(config) {
|
|
49
|
-
return "sdk" in config &&
|
|
53
|
+
return "sdk" in config && typeof config.sdk === "string";
|
|
50
54
|
}
|
|
51
55
|
const AiPlugin = definePlugin({
|
|
52
56
|
name: "ai",
|