@mcowger/pi-plexus 1.0.0 → 1.0.2
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/extension.js +18 -6
- package/package.json +1 -1
package/dist/extension.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../plexus-models/src/convert.ts
|
|
3
3
|
var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
|
|
4
|
+
var NON_CHAT_ID_PATTERN = /embedding|embed|tts|whisper|image-[0-9]|image\b.*gen|diffusion|dall-e|stable-diff|sdxl|dream/i;
|
|
4
5
|
var API_DIALECT_MAP = {
|
|
5
6
|
chat_completions: "openai-completions",
|
|
6
7
|
"openai-completions": "openai-completions",
|
|
@@ -44,6 +45,12 @@ function mapInputModalities(model) {
|
|
|
44
45
|
}
|
|
45
46
|
return result.length > 0 ? result : ["text"];
|
|
46
47
|
}
|
|
48
|
+
function isChatModel(model) {
|
|
49
|
+
const outputModalities = model.architecture?.output_modalities;
|
|
50
|
+
if (outputModalities !== undefined)
|
|
51
|
+
return outputModalities.includes("text");
|
|
52
|
+
return !NON_CHAT_ID_PATTERN.test(model.id);
|
|
53
|
+
}
|
|
47
54
|
function inferReasoning(model) {
|
|
48
55
|
const params = model.supported_parameters;
|
|
49
56
|
if (!params)
|
|
@@ -116,7 +123,7 @@ function convertToDescriptor(raw, baseUrl) {
|
|
|
116
123
|
function convertDescriptors(models, baseUrl) {
|
|
117
124
|
const result = [];
|
|
118
125
|
for (const m of models) {
|
|
119
|
-
if (!m.id)
|
|
126
|
+
if (!m.id || !isChatModel(m))
|
|
120
127
|
continue;
|
|
121
128
|
result.push(convertToDescriptor(m, baseUrl));
|
|
122
129
|
}
|
|
@@ -399,12 +406,12 @@ async function writeLogLine(message, data) {
|
|
|
399
406
|
}
|
|
400
407
|
|
|
401
408
|
// src/mapper.ts
|
|
402
|
-
import {
|
|
409
|
+
import { getModel } from "@earendil-works/pi-ai/compat";
|
|
403
410
|
function descriptorToPiModel(descriptor) {
|
|
404
411
|
let builtinModel;
|
|
405
412
|
if (descriptor.piProvider && descriptor.piModel) {
|
|
406
413
|
try {
|
|
407
|
-
builtinModel =
|
|
414
|
+
builtinModel = getModel(descriptor.piProvider, descriptor.piModel);
|
|
408
415
|
} catch {
|
|
409
416
|
builtinModel = undefined;
|
|
410
417
|
}
|
|
@@ -455,11 +462,16 @@ function descriptorToPiModel(descriptor) {
|
|
|
455
462
|
var PROVIDER_NAME = "plexus";
|
|
456
463
|
var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
|
|
457
464
|
var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
|
|
465
|
+
function getPlexusModelBaseUrl(baseUrl, api) {
|
|
466
|
+
const normalized = baseUrl.trim().replace(/\/+$/, "");
|
|
467
|
+
const apiBase = normalized.endsWith("/v1") ? normalized : `${normalized}/v1`;
|
|
468
|
+
return adjustBaseUrl(apiBase, api);
|
|
469
|
+
}
|
|
458
470
|
var currentModels = [];
|
|
459
471
|
function plexusExtension(pi) {
|
|
460
472
|
const cached = readCachedModelsSync();
|
|
461
473
|
const startupBaseUrl = getBaseUrl() ?? "http://localhost/v1";
|
|
462
|
-
const startupModels = cached?.models.map(descriptorToPiModel) ?? [];
|
|
474
|
+
const startupModels = cached?.models.filter(isChatModel).map(descriptorToPiModel) ?? [];
|
|
463
475
|
log("startup", {
|
|
464
476
|
cachedModelCount: startupModels.length,
|
|
465
477
|
startupBaseUrl
|
|
@@ -532,8 +544,7 @@ function createPlexusLoginProvider(pi) {
|
|
|
532
544
|
const baseUrl = credentials.plexusBaseUrl;
|
|
533
545
|
if (!baseUrl)
|
|
534
546
|
return models;
|
|
535
|
-
|
|
536
|
-
return models.map((model) => model.provider === PROVIDER_NAME ? { ...model, baseUrl: apiBase } : model);
|
|
547
|
+
return models.map((model) => model.provider === PROVIDER_NAME ? { ...model, baseUrl: getPlexusModelBaseUrl(baseUrl, model.api) } : model);
|
|
537
548
|
}
|
|
538
549
|
};
|
|
539
550
|
}
|
|
@@ -594,5 +605,6 @@ async function trySetDefaultModel(pi, models) {
|
|
|
594
605
|
log("trySetDefaultModel", { defaultModelId, ok });
|
|
595
606
|
}
|
|
596
607
|
export {
|
|
608
|
+
getPlexusModelBaseUrl,
|
|
597
609
|
plexusExtension as default
|
|
598
610
|
};
|