Skip to content

Commit

Permalink
🐛 fix: fix some providers issues (lobehub#5429)
Browse files Browse the repository at this point in the history
* Update package.json

* Update package.json

* fix null issue

* update locale

* fix model ability display

* update locale
  • Loading branch information
arvinxx authored Jan 14, 2025
1 parent 8a8eabc commit b7edbd3
Show file tree
Hide file tree
Showing 35 changed files with 166 additions and 39 deletions.
3 changes: 3 additions & 0 deletions locales/ar/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "إضافة نموذج",
"disabled": "غير مفعل",
"disabledActions": {
"showMore": "عرض الكل"
},
"empty": {
"desc": "يرجى إنشاء نموذج مخصص أو سحب نموذج للبدء في الاستخدام",
"title": "لا توجد نماذج متاحة"
Expand Down
3 changes: 3 additions & 0 deletions locales/bg-BG/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Добавяне на модел",
"disabled": "Неактивен",
"disabledActions": {
"showMore": "Покажи всичко"
},
"empty": {
"desc": "Моля, създайте персонализиран модел или изтеглете модел, за да започнете да го използвате",
"title": "Няма налични модели"
Expand Down
3 changes: 3 additions & 0 deletions locales/de-DE/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Modell hinzufügen",
"disabled": "Nicht aktiviert",
"disabledActions": {
"showMore": "Alle anzeigen"
},
"empty": {
"desc": "Bitte erstellen Sie ein benutzerdefiniertes Modell oder ziehen Sie ein Modell, um zu beginnen.",
"title": "Keine verfügbaren Modelle"
Expand Down
3 changes: 3 additions & 0 deletions locales/en-US/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Add Model",
"disabled": "Disabled",
"disabledActions": {
"showMore": "Show All"
},
"empty": {
"desc": "Please create a custom model or pull a model to get started.",
"title": "No available models"
Expand Down
3 changes: 3 additions & 0 deletions locales/es-ES/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Agregar modelo",
"disabled": "No habilitado",
"disabledActions": {
"showMore": "Mostrar todo"
},
"empty": {
"desc": "Por favor, crea un modelo personalizado o importa un modelo para comenzar a usarlo.",
"title": "No hay modelos disponibles"
Expand Down
3 changes: 3 additions & 0 deletions locales/fa-IR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "مدل جدید اضافه کنید",
"disabled": "غیرفعال",
"disabledActions": {
"showMore": "نمایش همه"
},
"empty": {
"desc": "لطفاً یک مدل سفارشی ایجاد کنید یا پس از بارگذاری مدل‌ها، شروع به استفاده کنید",
"title": "مدل قابل استفاده‌ای وجود ندارد"
Expand Down
3 changes: 3 additions & 0 deletions locales/fr-FR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Ajouter un modèle",
"disabled": "Non activé",
"disabledActions": {
"showMore": "Afficher tout"
},
"empty": {
"desc": "Veuillez créer un modèle personnalisé ou importer un modèle pour commencer à l'utiliser.",
"title": "Aucun modèle disponible"
Expand Down
3 changes: 3 additions & 0 deletions locales/it-IT/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Aggiungi modello",
"disabled": "Non attivato",
"disabledActions": {
"showMore": "Mostra tutto"
},
"empty": {
"desc": "Si prega di creare un modello personalizzato o di importare un modello per iniziare a utilizzarlo",
"title": "Nessun modello disponibile"
Expand Down
3 changes: 3 additions & 0 deletions locales/ja-JP/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "モデルを追加",
"disabled": "無効",
"disabledActions": {
"showMore": "すべて表示"
},
"empty": {
"desc": "カスタムモデルを作成するか、モデルを取得してから使用を開始してください",
"title": "利用可能なモデルはありません"
Expand Down
3 changes: 3 additions & 0 deletions locales/ko-KR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "모델 추가",
"disabled": "비활성화",
"disabledActions": {
"showMore": "모두 보기"
},
"empty": {
"desc": "사용할 수 있는 모델이 없습니다. 사용자 정의 모델을 생성하거나 모델을 가져온 후 시작하세요.",
"title": "사용 가능한 모델이 없습니다."
Expand Down
3 changes: 3 additions & 0 deletions locales/nl-NL/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Model toevoegen",
"disabled": "Niet ingeschakeld",
"disabledActions": {
"showMore": "Toon alles"
},
"empty": {
"desc": "Maak een aangepast model of haal een model op om te beginnen met gebruiken.",
"title": "Geen beschikbare modellen"
Expand Down
3 changes: 3 additions & 0 deletions locales/pl-PL/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Dodaj model",
"disabled": "Nieaktywne",
"disabledActions": {
"showMore": "Pokaż więcej"
},
"empty": {
"desc": "Proszę utworzyć model niestandardowy lub pobrać model, aby rozpocząć korzystanie.",
"title": "Brak dostępnych modeli"
Expand Down
3 changes: 3 additions & 0 deletions locales/pt-BR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Adicionar Modelo",
"disabled": "Não habilitado",
"disabledActions": {
"showMore": "Mostrar tudo"
},
"empty": {
"desc": "Por favor, crie um modelo personalizado ou importe um modelo para começar a usar.",
"title": "Nenhum modelo disponível"
Expand Down
3 changes: 3 additions & 0 deletions locales/ru-RU/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Добавить модель",
"disabled": "Не активирован",
"disabledActions": {
"showMore": "Показать все"
},
"empty": {
"desc": "Пожалуйста, создайте пользовательскую модель или загрузите модель, чтобы начать использовать.",
"title": "Нет доступных моделей"
Expand Down
3 changes: 3 additions & 0 deletions locales/tr-TR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Model Ekle",
"disabled": "Devre dışı",
"disabledActions": {
"showMore": "Hepsini Göster"
},
"empty": {
"desc": "Lütfen özel bir model oluşturun veya kullanmaya başlamadan önce bir model çekin",
"title": "Kullanılabilir model yok"
Expand Down
3 changes: 3 additions & 0 deletions locales/vi-VN/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "Thêm mô hình",
"disabled": "Chưa được kích hoạt",
"disabledActions": {
"showMore": "Hiển thị tất cả"
},
"empty": {
"desc": "Vui lòng tạo mô hình tùy chỉnh hoặc kéo mô hình để bắt đầu sử dụng",
"title": "Chưa có mô hình nào khả dụng"
Expand Down
3 changes: 3 additions & 0 deletions locales/zh-CN/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "添加模型",
"disabled": "未启用",
"disabledActions": {
"showMore": "显示全部"
},
"empty": {
"desc": "请创建自定义模型或拉取模型后开始使用吧",
"title": "暂无可用模型"
Expand Down
3 changes: 3 additions & 0 deletions locales/zh-TW/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
"list": {
"addNew": "新增模型",
"disabled": "未啟用",
"disabledActions": {
"showMore": "顯示全部"
},
"empty": {
"desc": "請創建自定義模型或拉取模型後開始使用吧",
"title": "暫無可用模型"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@
"yaml": "^2.7.0",
"yjs": "^13.6.21",
"zod": "^3.24.1",
"zustand": "5.0.1",
"zustand-utils": "^1.3.2"
"zustand": "^5.0.3",
"zustand-utils": "^2"
},
"devDependencies": {
"@commitlint/cli": "^19.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import PluginTag from '../../../features/PluginTag';
import KnowledgeTag from './KnowledgeTag';

const TitleTags = memo(() => {
const [model, hasKnowledge] = useAgentStore((s) => [
const [model, provider, hasKnowledge] = useAgentStore((s) => [
agentSelectors.currentAgentModel(s),
agentSelectors.currentAgentModelProvider(s),
agentSelectors.hasKnowledge(s),
]);
const plugins = useAgentStore(agentSelectors.currentAgentPlugins, isEqual);
const enabledKnowledge = useAgentStore(agentSelectors.currentEnabledKnowledge, isEqual);

const showPlugin = useModelSupportToolUse(model);
const showPlugin = useModelSupportToolUse(model, provider);

return (
<Flexbox align={'center'} horizontal>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Typography } from 'antd';
import { Icon } from '@lobehub/ui';
import { Button, Typography } from 'antd';
import isEqual from 'fast-deep-equal';
import { memo } from 'react';
import { ChevronDown } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

Expand All @@ -12,16 +14,32 @@ import ModelItem from './ModelItem';
const DisabledModels = memo(() => {
const { t } = useTranslation('modelProvider');

const [showMore, setShowMore] = useState(false);
const disabledModels = useAiInfraStore(aiModelSelectors.disabledAiProviderModelList, isEqual);

const displayModels = showMore ? disabledModels : disabledModels.slice(0, 10);
return (
<Flexbox>
<Typography.Text style={{ fontSize: 12, marginTop: 8 }} type={'secondary'}>
{t('providerModels.list.disabled')}
</Typography.Text>
{disabledModels.map((item) => (
{displayModels.map((item) => (
<ModelItem {...item} key={item.id} />
))}
{!showMore && (
<Button
block
color={'default'}
icon={<Icon icon={ChevronDown} />}
onClick={() => {
setShowMore(true);
}}
size={'small'}
variant={'filled'}
>
{t('providerModels.list.disabledActions.showMore')}
</Button>
)}
</Flexbox>
);
});
Expand Down
10 changes: 5 additions & 5 deletions src/features/ChatInput/ActionBar/Token/TokenTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';

import { useModelContextWindowTokens } from '@/hooks/useModelContextWindowTokens';
import { useModelSupportToolUse } from '@/hooks/useModelSupportToolUse';
import { useTokenCount } from '@/hooks/useTokenCount';
import { useAgentStore } from '@/store/agent';
Expand All @@ -14,8 +15,6 @@ import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/selectors';
import { useToolStore } from '@/store/tool';
import { toolSelectors } from '@/store/tool/selectors';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';

import TokenProgress from './TokenProgress';

Expand All @@ -31,22 +30,23 @@ const Token = memo<TokenTagProps>(({ total: messageString }) => {
topicSelectors.currentActiveTopicSummary(s)?.content || '',
]);

const [systemRole, model] = useAgentStore((s) => {
const [systemRole, model, provider] = useAgentStore((s) => {
const config = agentSelectors.currentAgentChatConfig(s);

return [
agentSelectors.currentAgentSystemRole(s),
agentSelectors.currentAgentModel(s) as string,
agentSelectors.currentAgentModelProvider(s) as string,
// add these two params to enable the component to re-render
config.historyCount,
config.enableHistoryCount,
];
});

const maxTokens = useUserStore(modelProviderSelectors.modelMaxToken(model));
const maxTokens = useModelContextWindowTokens(model, provider);

// Tool usage token
const canUseTool = useModelSupportToolUse(model);
const canUseTool = useModelSupportToolUse(model, provider);
const plugins = useAgentStore(agentSelectors.currentAgentPlugins);
const toolsString = useToolStore((s) => {
const pluginSystemRoles = toolSelectors.enabledSystemRoles(plugins)(s);
Expand Down
9 changes: 3 additions & 6 deletions src/features/ChatInput/ActionBar/Token/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import dynamic from 'next/dynamic';
import { PropsWithChildren, memo } from 'react';

import { useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/selectors';
import { useModelHasContextWindowToken } from '@/hooks/useModelHasContextWindowToken';
import { useChatStore } from '@/store/chat';
import { chatSelectors, threadSelectors } from '@/store/chat/selectors';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';

const LargeTokenContent = dynamic(() => import('./TokenTag'), { ssr: false });

const Token = memo<PropsWithChildren>(({ children }) => {
const model = useAgentStore(agentSelectors.currentAgentModel);
const showTag = useUserStore(modelProviderSelectors.isModelHasMaxToken(model));
const showTag = useModelHasContextWindowToken();

return showTag && children;
});

export const MainToken = memo(() => {
const total = useChatStore(chatSelectors.mainAIChatsMessageString);

Expand Down
4 changes: 3 additions & 1 deletion src/features/ChatInput/ActionBar/Tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const Tools = memo(() => {
const { enablePlugins } = useServerConfigStore(featureFlagsSelectors);

const model = useAgentStore(agentSelectors.currentAgentModel);
const enableFC = useModelSupportToolUse(model);
const provider = useAgentStore(agentSelectors.currentAgentModelProvider);

const enableFC = useModelSupportToolUse(model, provider);

return (
enablePlugins && (
Expand Down
3 changes: 2 additions & 1 deletion src/features/ChatInput/ActionBar/Upload/ServerMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const FileUpload = memo(() => {
const upload = useFileStore((s) => s.uploadChatFiles);

const model = useAgentStore(agentSelectors.currentAgentModel);
const provider = useAgentStore(agentSelectors.currentAgentModelProvider);

const canUploadImage = useModelSupportVision(model);
const canUploadImage = useModelSupportVision(model, provider);

const items: MenuProps['items'] = [
{
Expand Down
6 changes: 3 additions & 3 deletions src/features/ChatInput/Desktop/FilePreview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { memo } from 'react';

import DragUpload from '@/components/DragUpload';
import { useModelSupportVision } from '@/hooks/useModelSupportVision';
import { useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/slices/chat';
import { useFileStore } from '@/store/file';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';

import FileItemList from './FileList';

const FilePreview = memo(() => {
const model = useAgentStore(agentSelectors.currentAgentModel);
const provider = useAgentStore(agentSelectors.currentAgentModelProvider);

const canUploadImage = useUserStore(modelProviderSelectors.isModelEnabledUpload(model));
const canUploadImage = useModelSupportVision(model, provider);

const [uploadFiles] = useFileStore((s) => [s.uploadChatFiles]);

Expand Down
15 changes: 15 additions & 0 deletions src/hooks/useModelContextWindowTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isServerMode } from '@/const/version';
import { aiModelSelectors, useAiInfraStore } from '@/store/aiInfra';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';

export const useModelContextWindowTokens = (model: string, provider: string) => {
const newValue = useAiInfraStore(aiModelSelectors.modelContextWindowTokens(model, provider));

// TODO: remove this in V2.0
const oldValue = useUserStore(modelProviderSelectors.modelMaxToken(model));
if (!isServerMode) return oldValue;
//

return newValue as number;
};
Loading

0 comments on commit b7edbd3

Please sign in to comment.