Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
165 lines
4.2 KiB
TypeScript
165 lines
4.2 KiB
TypeScript
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { type ModelsDevData } from 'src/engine/metadata-modules/ai/ai-models/types/models-dev-data.type';
|
|
import { type ModelsDevModel } from 'src/engine/metadata-modules/ai/ai-models/types/models-dev-model.type';
|
|
import { inferModelFamily } from 'src/engine/metadata-modules/ai/ai-models/utils/infer-model-family.util';
|
|
|
|
import { type GeneratedCatalog } from '../types/generated-catalog.type';
|
|
import { type GeneratedModel } from '../types/generated-model.type';
|
|
|
|
const EXCLUDED_MODEL_PREFIXES = [
|
|
'text-embedding',
|
|
'embedding',
|
|
'dall-e',
|
|
'tts-',
|
|
'whisper',
|
|
'moderation',
|
|
'davinci',
|
|
'babbage',
|
|
'ada',
|
|
'curie',
|
|
'text-search',
|
|
'text-similarity',
|
|
'code-search',
|
|
'text-davinci',
|
|
'text-curie',
|
|
'text-babbage',
|
|
'text-ada',
|
|
'ft:',
|
|
'canary',
|
|
];
|
|
|
|
const EXCLUDED_MODEL_SUFFIXES = ['-audio-preview', '-realtime-preview'];
|
|
|
|
const LONG_CONTEXT_THRESHOLD_TOKENS = 200000;
|
|
|
|
const isLanguageModel = (modelId: string): boolean => {
|
|
const lowerId = modelId.toLowerCase();
|
|
|
|
if (EXCLUDED_MODEL_PREFIXES.some((prefix) => lowerId.startsWith(prefix))) {
|
|
return false;
|
|
}
|
|
|
|
return !EXCLUDED_MODEL_SUFFIXES.some((suffix) => lowerId.endsWith(suffix));
|
|
};
|
|
|
|
const meetsInclusionCriteria = (modelData: ModelsDevModel): boolean =>
|
|
modelData.status !== 'beta' &&
|
|
(modelData.tool_call ?? false) &&
|
|
isDefined(modelData.cost?.input) &&
|
|
isDefined(modelData.limit?.context);
|
|
|
|
const extractCost = ({
|
|
modelData,
|
|
model,
|
|
}: {
|
|
modelData: ModelsDevModel;
|
|
model: GeneratedModel;
|
|
}): void => {
|
|
const cost = modelData.cost;
|
|
|
|
if (!isDefined(cost)) {
|
|
return;
|
|
}
|
|
|
|
model.inputCostPerMillionTokens = cost.input;
|
|
model.outputCostPerMillionTokens = cost.output;
|
|
model.cachedInputCostPerMillionTokens = cost.cache_read;
|
|
model.cacheCreationCostPerMillionTokens = cost.cache_write;
|
|
|
|
const longContextCost = cost.context_over_200k;
|
|
|
|
if (!isDefined(longContextCost?.input)) {
|
|
return;
|
|
}
|
|
|
|
model.longContextCost = {
|
|
inputCostPerMillionTokens: longContextCost.input,
|
|
outputCostPerMillionTokens:
|
|
longContextCost.output ?? model.outputCostPerMillionTokens ?? 0,
|
|
thresholdTokens: LONG_CONTEXT_THRESHOLD_TOKENS,
|
|
cachedInputCostPerMillionTokens: longContextCost.cache_read,
|
|
cacheCreationCostPerMillionTokens: longContextCost.cache_write,
|
|
};
|
|
};
|
|
|
|
const buildModel = ({
|
|
providerName,
|
|
modelId,
|
|
modelData,
|
|
}: {
|
|
providerName: string;
|
|
modelId: string;
|
|
modelData: ModelsDevModel;
|
|
}): GeneratedModel => {
|
|
const model: GeneratedModel = {
|
|
name: modelId,
|
|
label: modelData.name ?? modelId,
|
|
modelFamily: inferModelFamily(providerName, modelId),
|
|
};
|
|
|
|
extractCost({ modelData, model });
|
|
|
|
model.contextWindowTokens = modelData.limit?.context;
|
|
model.maxOutputTokens = modelData.limit?.output;
|
|
|
|
const modalities = (modelData.modalities?.input ?? []).filter(
|
|
(modality) => modality !== 'text',
|
|
);
|
|
|
|
if (modalities.length > 0) {
|
|
model.modalities = modalities;
|
|
}
|
|
|
|
if (modelData.reasoning) {
|
|
model.supportsReasoning = true;
|
|
}
|
|
|
|
if (modelData.status === 'deprecated') {
|
|
model.isDeprecated = true;
|
|
}
|
|
|
|
return model;
|
|
};
|
|
|
|
// Which vendors we carry is a deployment decision, so it is read from the
|
|
// spec that states it rather than inferred from how the SDK names a package.
|
|
export const buildCatalog = ({
|
|
data,
|
|
vendors,
|
|
}: {
|
|
data: ModelsDevData;
|
|
vendors: string[];
|
|
}): GeneratedCatalog => {
|
|
const catalog: GeneratedCatalog = {};
|
|
|
|
for (const providerName of vendors) {
|
|
const providerData = data[providerName];
|
|
|
|
if (!isDefined(providerData)) {
|
|
// oxlint-disable-next-line no-console
|
|
console.warn(`Provider "${providerName}" not found in models.dev`);
|
|
continue;
|
|
}
|
|
|
|
const models = Object.entries(providerData.models)
|
|
.filter(
|
|
([modelId, modelData]) =>
|
|
isLanguageModel(modelId) && meetsInclusionCriteria(modelData),
|
|
)
|
|
.map(([modelId, modelData]) =>
|
|
buildModel({ providerName, modelId, modelData }),
|
|
);
|
|
|
|
if (models.length === 0) {
|
|
// oxlint-disable-next-line no-console
|
|
console.warn(`No qualifying models for "${providerName}", skipping`);
|
|
continue;
|
|
}
|
|
|
|
catalog[providerName] = { models };
|
|
}
|
|
|
|
return catalog;
|
|
};
|