Files
FastGPT/packages/service/core/ai/model.ts
T
Archer 3f4400a500 V4.14.10 dev (#6674)
* feat: model config with brand-new price calculate machanism (#6616)

* fix: image read and json error (Agent) (#6502)

* fix:
1.image read
2.JSON parsing error

* dataset cite and pause

* perf: plancall second parse

* add test

---------

Co-authored-by: archer <545436317@qq.com>

* master message

* remove invalid code

* wip: model config

* feat: model config with brand-new price calculate machanism

* merge main branch

* ajust calculate way

* ajust priceTiers resolve procession

* perf: price config code

* fix: default price

* fix: test

* fix: comment

* fix test

---------

Co-authored-by: YeYuheng <57035043+YYH211@users.noreply.github.com>
Co-authored-by: archer <545436317@qq.com>

* wip: fix modal UI (#6634)

* wip: fix modal UI

* fix: maxInputToken set

* chore: add price unit for non llm models

* chore: replace question mark icon with beta tag (#6672)

* feat:rerank too long; fix:rerank ui(agent),embedding returns 0 (#6663)

* feat:rerank too long; fix:rerank ui(agent),embedding returns 0

* rerank

* fix:rerank function

* perf: rerank code

* fix rerank

* perf: model price ui

---------

Co-authored-by: archer <545436317@qq.com>

* remove llmtype field

* revert model init

* fix: filed

* fix: model select filter

* perf: multiple selector render

* remove invalid checker

* remove invalid i18n

* perf: model selector tip

* perf: model selector tip

* fix cr

* limit pnpm version

* fix: i18n

* fix action

* set default mintoken

* update i18n

* perf: usage push

* fix:rerank model ui (#6677)

* fix: tier match error

* fix: testr

---------

Co-authored-by: Ryo <whoeverimf5@gmail.com>
Co-authored-by: YeYuheng <57035043+YYH211@users.noreply.github.com>
2026-03-30 10:05:42 +08:00

74 lines
2.6 KiB
TypeScript

import { cloneDeep } from 'lodash';
import { type SystemModelItemType } from './type';
import type { LLMModelItemType } from '@fastgpt/global/core/ai/model.schema';
export const getDefaultLLMModel = () => global?.systemDefaultModel.llm!;
export const getLLMModel = (model?: string | LLMModelItemType) => {
if (!model) return getDefaultLLMModel();
return typeof model === 'string' ? global.llmModelMap.get(model) || getDefaultLLMModel() : model;
};
export const getDatasetModel = (model?: string) => {
return (
Array.from(global.llmModelMap.values())?.find(
(item) => item.model === model || item.name === model
) ?? getDefaultLLMModel()
);
};
export const getVlmModelList = () => {
return Array.from(global.llmModelMap.values())?.filter((item) => item.vision) || [];
};
export const getDefaultVLMModel = () => global?.systemDefaultModel.datasetImageLLM;
export const getVlmModel = (model?: string) => {
const list = getVlmModelList();
return list.find((item) => item.model === model || item.name === model) || list[0];
};
export const getDefaultHelperBotModel = (): LLMModelItemType =>
global?.systemDefaultModel.helperBotLLM || getDefaultLLMModel();
export const getDefaultEmbeddingModel = () => global?.systemDefaultModel.embedding!;
export const getEmbeddingModel = (model?: string) => {
if (!model) return getDefaultEmbeddingModel();
return global.embeddingModelMap.get(model) || getDefaultEmbeddingModel();
};
export const getDefaultTTSModel = () => global?.systemDefaultModel.tts!;
export function getTTSModel(model?: string) {
if (!model) return getDefaultTTSModel();
return global.ttsModelMap.get(model) || getDefaultTTSModel();
}
export const getDefaultSTTModel = () => global?.systemDefaultModel.stt!;
export function getSTTModel(model?: string) {
if (!model) return getDefaultSTTModel();
return global.sttModelMap.get(model) || getDefaultSTTModel();
}
export const getDefaultRerankModel = () => global?.systemDefaultModel.rerank!;
export function getRerankModel(model?: string) {
if (!model) return getDefaultRerankModel();
return global.reRankModelMap.get(model) || getDefaultRerankModel();
}
export const findAIModel = (
model: string | SystemModelItemType
): SystemModelItemType | undefined => {
if (typeof model === 'object') {
return model;
}
return (
global.llmModelMap.get(model) ||
global.embeddingModelMap.get(model) ||
global.ttsModelMap.get(model) ||
global.sttModelMap.get(model) ||
global.reRankModelMap.get(model)
);
};
export const findModelFromAlldata = (model: string) => {
return cloneDeep(global.systemModelList.find((item) => item.model === model));
};