Skip to content

Commit

Permalink
♻️ refactor: refactor tokens to contextWindowTokens (#5185)
Browse files Browse the repository at this point in the history
* refactor

* fix test
  • Loading branch information
arvinxx authored Dec 26, 2024
1 parent 6460378 commit a2aa99a
Show file tree
Hide file tree
Showing 104 changed files with 1,412 additions and 1,677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ModelActions = memo<ModelActionsProps>(({ identifier, providerData, data }
tags: (
<ModelFeatureTags
functionCall={data.meta.functionCall}
tokens={data.meta.tokens}
tokens={data.meta.contextWindowTokens}
vision={data.meta.vision}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Header = memo<HeaderProps>(({ identifier, data, mobile }) => {
{data.meta.description && <div>{t(`${identifier}.description`, { ns: 'models' })}</div>}
<ModelFeatureTags
functionCall={data.meta.functionCall}
tokens={data.meta.tokens}
tokens={data.meta.contextWindowTokens}
vision={data.meta.vision}
/>
</Flexbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface SuggestionItemProps
FlexboxProps {}

const SuggestionItem = memo<SuggestionItemProps>(({ className, meta, identifier, ...rest }) => {
const { title, description, tokens, vision, functionCall } = meta;
const { title, description, contextWindowTokens, vision, functionCall } = meta;
const { t } = useTranslation('models');
const { cx, styles } = useStyles();

Expand All @@ -67,7 +67,7 @@ const SuggestionItem = memo<SuggestionItemProps>(({ className, meta, identifier,
{t(`${identifier}.description`)}
</Paragraph>
)}
<ModelFeatureTags functionCall={functionCall} tokens={tokens} vision={vision} />
<ModelFeatureTags functionCall={functionCall} tokens={contextWindowTokens} vision={vision} />
</Flexbox>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ProviderItem = memo<ProviderItemProps>(({ mobile, modelId, identifier }) =
const items: StatisticProps[] = [
{
title: t('models.contentLength'),
value: model?.tokens ? formatTokenNumber(model.tokens) : '--',
value: model?.contextWindowTokens ? formatTokenNumber(model.contextWindowTokens) : '--',
},
{
title: t('models.providerInfo.maxOutput'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface SuggestionItemProps
}

const ModelItem = memo<SuggestionItemProps>(({ mobile, meta, identifier }) => {
const { title, tokens, vision, functionCall } = meta;
const { title, contextWindowTokens, vision, functionCall } = meta;
const { xl = true } = useResponsive();
const { t } = useTranslation('discover');
const { styles, theme } = useStyles();
Expand All @@ -57,7 +57,7 @@ const ModelItem = memo<SuggestionItemProps>(({ mobile, meta, identifier }) => {
const items: StatisticProps[] = [
{
title: t('models.contentLength'),
value: meta?.tokens ? formatTokenNumber(meta.tokens) : '--',
value: meta?.contextWindowTokens ? formatTokenNumber(meta.contextWindowTokens) : '--',
},
{
title: t('models.providerInfo.maxOutput'),
Expand Down Expand Up @@ -98,7 +98,7 @@ const ModelItem = memo<SuggestionItemProps>(({ mobile, meta, identifier }) => {
</Flexbox>
</Flexbox>
</Link>
<ModelFeatureTags functionCall={functionCall} tokens={tokens} vision={vision} />
<ModelFeatureTags functionCall={functionCall} tokens={contextWindowTokens} vision={vision} />
</Flexbox>
);

Expand Down
8 changes: 6 additions & 2 deletions src/app/(main)/discover/(list)/models/features/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ModelCardProps extends DiscoverModelItem, FlexboxProps {
}

const ModelCard = memo<ModelCardProps>(({ className, meta, identifier, ...rest }) => {
const { description, title, functionCall, vision, tokens } = meta;
const { description, title, functionCall, vision, contextWindowTokens } = meta;
const { t } = useTranslation('models');
const { cx, styles } = useStyles();

Expand Down Expand Up @@ -107,7 +107,11 @@ const ModelCard = memo<ModelCardProps>(({ className, meta, identifier, ...rest }
</Paragraph>
)}

<ModelFeatureTags functionCall={functionCall} tokens={tokens} vision={vision} />
<ModelFeatureTags
functionCall={functionCall}
tokens={contextWindowTokens}
vision={vision}
/>
</Flexbox>
</Flexbox>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export const useCloudflareProvider = (): ProviderItem => {
name: [KeyVaultsConfigKey, providerKey, 'apiKey'],
},
{
children: (
<Input
placeholder={t(`${providerKey}.baseURLOrAccountID.placeholder`)}
/>
),
children: <Input placeholder={t(`${providerKey}.baseURLOrAccountID.placeholder`)} />,
desc: t(`${providerKey}.baseURLOrAccountID.desc`),
label: t(`${providerKey}.baseURLOrAccountID.title`),
name: [KeyVaultsConfigKey, providerKey, 'baseURLOrAccountID'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ const ModelFetcher = memo<ModelFetcherProps>(({ provider }) => {
title={
latestFetchTime
? t('llm.fetcher.latestTime', {
time: dayjs(latestFetchTime).format('YYYY-MM-DD HH:mm:ss'),
})
time: dayjs(latestFetchTime).format('YYYY-MM-DD HH:mm:ss'),
})
: t('llm.fetcher.noLatestTime')
}
>
Expand Down
11 changes: 7 additions & 4 deletions src/components/ModelSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@ export const ModelInfoTags = memo<ModelInfoTagsProps>(
</div>
</Tooltip>
)}
{model.tokens !== undefined && (
{model.contextWindowTokens !== undefined && (
<Tooltip
overlayStyle={{ maxWidth: 'unset', pointerEvents: 'none' }}
placement={placement}
title={t('ModelSelect.featureTag.tokens', {
tokens: model.tokens === 0 ? '∞' : numeral(model.tokens).format('0,0'),
tokens:
model.contextWindowTokens === 0
? '∞'
: numeral(model.contextWindowTokens).format('0,0'),
})}
>
<Center className={styles.token} title="">
{model.tokens === 0 ? (
{model.contextWindowTokens === 0 ? (
<Infinity size={17} strokeWidth={1.6} />
) : (
formatTokenNumber(model.tokens)
formatTokenNumber(model.contextWindowTokens)
)}
</Center>
</Tooltip>
Expand Down
8 changes: 6 additions & 2 deletions src/config/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ describe('getServerConfig', () => {
describe('index url', () => {
it('should return default URLs when no environment variables are set', () => {
const config = getAppConfig();
expect(config.AGENTS_INDEX_URL).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public');
expect(config.AGENTS_INDEX_URL).toBe(
'https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public',
);
expect(config.PLUGINS_INDEX_URL).toBe('https://chat-plugins.lobehub.com');
});

Expand All @@ -41,7 +43,9 @@ describe('getServerConfig', () => {
process.env.PLUGINS_INDEX_URL = '';

const config = getAppConfig();
expect(config.AGENTS_INDEX_URL).toBe('https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public');
expect(config.AGENTS_INDEX_URL).toBe(
'https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public',
);
expect(config.PLUGINS_INDEX_URL).toBe('https://chat-plugins.lobehub.com');
});
});
Expand Down
3 changes: 1 addition & 2 deletions src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ if (typeof window === 'undefined' && isServerMode && !APP_URL) {
throw new Error('`APP_URL` is required in server mode');
}

const ASSISTANT_INDEX_URL =
'https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public';
const ASSISTANT_INDEX_URL = 'https://registry.npmmirror.com/@lobehub/agents-index/v1/files/public';

const PLUGINS_INDEX_URL = 'https://chat-plugins.lobehub.com';

Expand Down
4 changes: 2 additions & 2 deletions src/config/modelProviders/ai21.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModelProviderCard } from '@/types/llm';
const Ai21: ModelProviderCard = {
chatModels: [
{
contextWindowTokens: 256_000,
displayName: 'Jamba 1.5 Mini',
enabled: true,
functionCall: true,
Expand All @@ -12,9 +13,9 @@ const Ai21: ModelProviderCard = {
input: 0.2,
output: 0.4,
},
tokens: 256_000,
},
{
contextWindowTokens: 256_000,
displayName: 'Jamba 1.5 Large',
enabled: true,
functionCall: true,
Expand All @@ -23,7 +24,6 @@ const Ai21: ModelProviderCard = {
input: 2,
output: 8,
},
tokens: 256_000,
},
],
checkModel: 'jamba-1.5-mini',
Expand Down
8 changes: 4 additions & 4 deletions src/config/modelProviders/ai360.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModelProviderCard } from '@/types/llm';
const Ai360: ModelProviderCard = {
chatModels: [
{
contextWindowTokens: 8192,
description:
'360GPT2 Pro 是 360 公司推出的高级自然语言处理模型,具备卓越的文本生成和理解能力,尤其在生成与创作领域表现出色,能够处理复杂的语言转换和角色演绎任务。',
displayName: '360GPT2 Pro',
Expand All @@ -15,9 +16,9 @@ const Ai360: ModelProviderCard = {
input: 5,
output: 5,
},
tokens: 8192,
},
{
contextWindowTokens: 8192,
description:
'360GPT Pro 作为 360 AI 模型系列的重要成员,以高效的文本处理能力满足多样化的自然语言应用场景,支持长文本理解和多轮对话等功能。',
displayName: '360GPT Pro',
Expand All @@ -30,9 +31,9 @@ const Ai360: ModelProviderCard = {
input: 5,
output: 5,
},
tokens: 8192,
},
{
contextWindowTokens: 8192,
description:
'360GPT Turbo 提供强大的计算和对话能力,具备出色的语义理解和生成效率,是企业和开发者理想的智能助理解决方案。',
displayName: '360GPT Turbo',
Expand All @@ -44,9 +45,9 @@ const Ai360: ModelProviderCard = {
input: 2,
output: 2,
},
tokens: 8192,
},
{
contextWindowTokens: 8192,
description:
'360GPT Turbo Responsibility 8K 强调语义安全和责任导向,专为对内容安全有高度要求的应用场景设计,确保用户体验的准确性与稳健性。',
displayName: '360GPT Turbo Responsibility 8K',
Expand All @@ -58,7 +59,6 @@ const Ai360: ModelProviderCard = {
input: 2,
output: 2,
},
tokens: 8192,
},
],
checkModel: '360gpt-turbo',
Expand Down
16 changes: 8 additions & 8 deletions src/config/modelProviders/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModelProviderCard } from '@/types/llm';
const Anthropic: ModelProviderCard = {
chatModels: [
{
contextWindowTokens: 200_000,
description:
'Claude 3.5 Haiku 是 Anthropic 最快的下一代模型。与 Claude 3 Haiku 相比,Claude 3.5 Haiku 在各项技能上都有所提升,并在许多智力基准测试中超越了上一代最大的模型 Claude 3 Opus。',
displayName: 'Claude 3.5 Haiku',
Expand All @@ -18,9 +19,9 @@ const Anthropic: ModelProviderCard = {
writeCacheInput: 1.25,
},
releasedAt: '2024-11-05',
tokens: 200_000,
},
{
contextWindowTokens: 200_000,
description:
'Claude 3.5 Sonnet 提供了超越 Opus 的能力和比 Sonnet 更快的速度,同时保持与 Sonnet 相同的价格。Sonnet 特别擅长编程、数据科学、视觉处理、代理任务。',
displayName: 'Claude 3.5 Sonnet',
Expand All @@ -35,10 +36,10 @@ const Anthropic: ModelProviderCard = {
writeCacheInput: 3.75,
},
releasedAt: '2024-10-22',
tokens: 200_000,
vision: true,
},
{
contextWindowTokens: 200_000,
description:
'Claude 3.5 Sonnet 提供了超越 Opus 的能力和比 Sonnet 更快的速度,同时保持与 Sonnet 相同的价格。Sonnet 特别擅长编程、数据科学、视觉处理、代理任务。',
displayName: 'Claude 3.5 Sonnet 0620',
Expand All @@ -52,10 +53,10 @@ const Anthropic: ModelProviderCard = {
writeCacheInput: 3.75,
},
releasedAt: '2024-06-20',
tokens: 200_000,
vision: true,
},
{
contextWindowTokens: 200_000,
description:
'Claude 3 Haiku 是 Anthropic 的最快且最紧凑的模型,旨在实现近乎即时的响应。它具有快速且准确的定向性能。',
displayName: 'Claude 3 Haiku',
Expand All @@ -67,10 +68,10 @@ const Anthropic: ModelProviderCard = {
output: 1.25,
},
releasedAt: '2024-03-07',
tokens: 200_000,
vision: true,
},
{
contextWindowTokens: 200_000,
description:
'Claude 3 Sonnet 在智能和速度方面为企业工作负载提供了理想的平衡。它以更低的价格提供最大效用,可靠且适合大规模部署。',
displayName: 'Claude 3 Sonnet',
Expand All @@ -82,10 +83,10 @@ const Anthropic: ModelProviderCard = {
output: 15,
},
releasedAt: '2024-02-29',
tokens: 200_000,
vision: true,
},
{
contextWindowTokens: 200_000,
description:
'Claude 3 Opus 是 Anthropic 用于处理高度复杂任务的最强大模型。它在性能、智能、流畅性和理解力方面表现卓越。',
displayName: 'Claude 3 Opus',
Expand All @@ -98,10 +99,10 @@ const Anthropic: ModelProviderCard = {
output: 75,
},
releasedAt: '2024-02-29',
tokens: 200_000,
vision: true,
},
{
contextWindowTokens: 200_000,
description:
'Claude 2 为企业提供了关键能力的进步,包括业界领先的 200K token 上下文、大幅降低模型幻觉的发生率、系统提示以及一个新的测试功能:工具调用。',
displayName: 'Claude 2.1',
Expand All @@ -112,9 +113,9 @@ const Anthropic: ModelProviderCard = {
output: 24,
},
releasedAt: '2023-11-21',
tokens: 200_000,
},
{
contextWindowTokens: 100_000,
description:
'Claude 2 为企业提供了关键能力的进步,包括业界领先的 200K token 上下文、大幅降低模型幻觉的发生率、系统提示以及一个新的测试功能:工具调用。',
displayName: 'Claude 2.0',
Expand All @@ -125,7 +126,6 @@ const Anthropic: ModelProviderCard = {
output: 24,
},
releasedAt: '2023-07-11',
tokens: 100_000,
},
],
checkModel: 'claude-3-haiku-20240307',
Expand Down
Loading

0 comments on commit a2aa99a

Please sign in to comment.