Skip to content

Commit

Permalink
perf: io price computed
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Dec 30, 2024
1 parent 9901daf commit 56750cb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 70 deletions.
25 changes: 12 additions & 13 deletions packages/global/core/ai/model.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { ModelProviderIdType } from './provider';

export type LLMModelItemType = {
type PriceType = {
charsPointsPrice?: number; // 1k chars=n points; 60s=n points;

// If inputPrice is set, the input-output charging scheme is adopted
inputPrice?: number; // 1k tokens=n points
outputPrice?: number; // 1k tokens=n points
};
export type LLMModelItemType = PriceType & {
provider: ModelProviderIdType;
model: string;
name: string;
Expand All @@ -10,10 +17,6 @@ export type LLMModelItemType = {
quoteMaxToken: number;
maxTemperature: number;

charsPointsPrice: number; // 1k chars=n points
inputPrice?: number; // 1k tokens=n points
outputPrice?: number; // 1k tokens=n points

censor?: boolean;
vision?: boolean;

Expand All @@ -35,13 +38,12 @@ export type LLMModelItemType = {
fieldMap?: Record<string, string>;
};

export type VectorModelItemType = {
export type VectorModelItemType = PriceType & {
provider: ModelProviderIdType;
model: string; // model name
name: string; // show name
avatar?: string;
defaultToken: number; // split text default token
charsPointsPrice: number; // 1k tokens=n points
maxToken: number; // model max token
weight: number; // training weight
hidden?: boolean; // Disallow creation
Expand All @@ -50,25 +52,22 @@ export type VectorModelItemType = {
queryConfig?: Record<string, any>; // Custom parameters for query
};

export type ReRankModelItemType = {
export type ReRankModelItemType = PriceType & {
model: string;
name: string;
charsPointsPrice: number;
requestUrl: string;
requestAuth: string;
};

export type AudioSpeechModelType = {
export type AudioSpeechModelType = PriceType & {
provider: ModelProviderIdType;
model: string;
name: string;
charsPointsPrice: number;
voices: { label: string; value: string; bufferId: string }[];
};

export type STTModelType = {
export type STTModelType = PriceType & {
provider: ModelProviderIdType;
model: string;
name: string;
charsPointsPrice: number; // 60s = n points
};
2 changes: 1 addition & 1 deletion packages/service/support/wallet/usage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const formatModelChars2Points = ({
};
}

const isIOPriceType = modelType === ModelTypeEnum.llm && global.llmModelPriceType === 'IO';
const isIOPriceType = typeof modelData.inputPrice === 'number';

const totalPoints = isIOPriceType
? (modelData.inputPrice || 0) * (inputTokens / multiple) +
Expand Down
45 changes: 23 additions & 22 deletions projects/app/src/components/core/ai/AISettingModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
Thead,
Tr,
Table,
useDisclosure,
FlexProps
} from '@chakra-ui/react';
import { useSystemStore } from '@/web/common/system/useSystemStore';
Expand All @@ -28,7 +27,7 @@ import { getDocPath } from '@/web/common/system/doc';
import AIModelSelector from '@/components/Select/AIModelSelector';
import { LLMModelItemType } from '@fastgpt/global/core/ai/model.d';
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
import { getWebLLMModel, getWebLLMModelPriceType } from '@/web/common/system/utils';
import { getWebLLMModel } from '@/web/common/system/utils';
import MyIcon from '@fastgpt/web/components/common/Icon';
import dynamic from 'next/dynamic';
import InputSlider from '@fastgpt/web/components/common/MySlider/InputSlider';
Expand Down Expand Up @@ -82,7 +81,6 @@ const AIChatSettingsModal = ({
const useVision = watch('aiChatVision');

const selectedModel = getWebLLMModel(model);
const isIOType = getWebLLMModelPriceType();
const llmSupportVision = !!selectedModel?.vision;

const tokenLimit = useMemo(() => {
Expand Down Expand Up @@ -175,26 +173,29 @@ const AIChatSettingsModal = ({
</Thead>
<Tbody>
<Tr color={'myGray.900'}>
{!isIOType ? (
<Td pt={0} pb={2}>
{t('common:support.wallet.Ai point every thousand tokens', {
points: selectedModel?.charsPointsPrice || 0
})}
</Td>
) : (
<Td pt={0} pb={2}>
<Box>
{t('common:support.wallet.Ai point every thousand tokens_input', {
points: selectedModel?.inputPrice || 0
})}
</Box>
<Box>
{t('common:support.wallet.Ai point every thousand tokens_output', {
points: selectedModel?.outputPrice || 0
<Td pt={0} pb={2}>
{typeof selectedModel?.inputPrice === 'number' ? (
<>
<Box>
{t('common:support.wallet.Ai point every thousand tokens_input', {
points: selectedModel?.inputPrice || 0
})}
</Box>
<Box>
{t('common:support.wallet.Ai point every thousand tokens_output', {
points: selectedModel?.outputPrice || 0
})}
</Box>
</>
) : (
<>
{t('common:support.wallet.Ai point every thousand tokens', {
points: selectedModel?.charsPointsPrice || 0
})}
</Box>
</Td>
)}
</>
)}
</Td>

<Td pt={0} pb={2}>
{Math.round((selectedModel?.maxContext || 4096) / 1000)}K
</Td>
Expand Down
51 changes: 25 additions & 26 deletions projects/app/src/components/core/ai/ModelTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Avatar from '@fastgpt/web/components/common/Avatar';
import MyTag from '@fastgpt/web/components/common/Tag/index';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import dynamic from 'next/dynamic';
import { getWebLLMModelPriceType } from '@/web/common/system/utils';

const MyModal = dynamic(() => import('@fastgpt/web/components/common/MyModal'));

Expand Down Expand Up @@ -56,37 +55,37 @@ const ModelTable = () => {
const [search, setSearch] = useState('');

const { llmModelList, audioSpeechModelList, vectorModelList, whisperModel } = useSystemStore();
const isIOType = getWebLLMModelPriceType();

const modelList = useMemo(() => {
const formatLLMModelList = llmModelList.map((item) => ({
...item,
typeLabel: t('common:model.type.chat'),
priceLabel: isIOType ? (
<Box>
<Flex>
{`${t('common:common.Input')}:`}
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5} ml={2}>
{item.inputPrice || 0}
</Box>
{`${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
<Flex>
{`${t('common:common.Output')}:`}
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5} ml={2}>
{item.outputPrice || 0}
priceLabel:
typeof item.inputPrice === 'number' ? (
<Box>
<Flex>
{`${t('common:common.Input')}:`}
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5} ml={2}>
{item.inputPrice || 0}
</Box>
{`${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
<Flex>
{`${t('common:common.Output')}:`}
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5} ml={2}>
{item.outputPrice || 0}
</Box>
{`${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
</Box>
) : (
<Flex color={'myGray.700'}>
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5}>
{item.charsPointsPrice}
</Box>
{`${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
</Box>
) : (
<Flex color={'myGray.700'}>
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5}>
{item.charsPointsPrice}
</Box>
{`${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
),
),
tagColor: 'blue'
}));
const formatVectorModelList = vectorModelList.map((item) => ({
Expand Down Expand Up @@ -168,13 +167,13 @@ const ModelTable = () => {

return filterList;
}, [
provider,
modelType,
llmModelList,
vectorModelList,
audioSpeechModelList,
whisperModel,
t,
modelType,
provider,
search
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const DatasetImportContextProvider = ({ children }: { children: React.ReactNode
chunkSize: vectorModel?.defaultToken ? vectorModel?.defaultToken * 2 : 1024,
showChunkInput: false,
showPromptInput: false,
charsPointsPrice: agentModel.charsPointsPrice,
charsPointsPrice: agentModel.charsPointsPrice || 0,
priceTip: t('dataset:import.Auto mode Estimated Price Tips', {
price: agentModel.charsPointsPrice
}),
Expand All @@ -211,7 +211,7 @@ const DatasetImportContextProvider = ({ children }: { children: React.ReactNode
chunkSize: embeddingChunkSize,
showChunkInput: true,
showPromptInput: false,
charsPointsPrice: vectorModel.charsPointsPrice,
charsPointsPrice: vectorModel.charsPointsPrice || 0,
priceTip: t('dataset:import.Embedding Estimated Price Tips', {
price: vectorModel.charsPointsPrice
}),
Expand All @@ -226,7 +226,7 @@ const DatasetImportContextProvider = ({ children }: { children: React.ReactNode
chunkSize: qaChunkSize,
showChunkInput: true,
showPromptInput: true,
charsPointsPrice: agentModel.charsPointsPrice,
charsPointsPrice: agentModel.charsPointsPrice || 0,
priceTip: t('dataset:import.Auto mode Estimated Price Tips', {
price: agentModel.charsPointsPrice
}),
Expand Down
5 changes: 0 additions & 5 deletions projects/app/src/web/common/system/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ export const getWebLLMModel = (model?: string) => {
const list = useSystemStore.getState().llmModelList;
return list.find((item) => item.model === model || item.name === model) ?? list[0];
};

export const getWebLLMModelPriceType = () => {
const list = useSystemStore.getState().llmModelList;
return list.some((item) => item.inputPrice || item.outputPrice);
};

0 comments on commit 56750cb

Please sign in to comment.