Skip to content

Commit

Permalink
✨ feat: support topic agent (lobehub#2683)
Browse files Browse the repository at this point in the history
* ✨ feat: support topic agent

* ✅ test: fix test

* ✅ test: fix test

* ✅ test: add tests

* 🌐 chore: add i18n
  • Loading branch information
arvinxx authored May 27, 2024
1 parent 48da563 commit 56865fe
Show file tree
Hide file tree
Showing 36 changed files with 383 additions and 127 deletions.
5 changes: 5 additions & 0 deletions locales/ar/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "مساعد النظام",
"topic": {
"label": "نموذج تسمية الموضوع",
"modelDesc": "يحدد النموذج المستخدم لإعادة تسمية الموضوع تلقائيًا",
"title": "إعادة تسمية الموضوع"
},
"translation": {
"label": "نموذج الترجمة",
"modelDesc": "النموذج المحدد للاستخدام في الترجمة",
Expand Down
5 changes: 5 additions & 0 deletions locales/bg-BG/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Системен асистент",
"topic": {
"label": "Модел за именуване на теми",
"modelDesc": "Модел, определен за автоматично преименуване на теми",
"title": "Автоматично именуване на теми"
},
"translation": {
"label": "Модел за превод",
"modelDesc": "Определя модела, използван за превод",
Expand Down
5 changes: 5 additions & 0 deletions locales/de-DE/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Systemassistent",
"topic": {
"label": "Themenbenennungsmodell",
"modelDesc": "Das Modell, das für die automatische Umbenennung von Themen verwendet wird",
"title": "Automatische Themenbenennung"
},
"translation": {
"label": "Übersetzungsmodell",
"modelDesc": "Das für die Übersetzung verwendete Modell",
Expand Down
5 changes: 5 additions & 0 deletions locales/en-US/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "System Agents",
"topic": {
"label": "Topic Naming Model",
"modelDesc": "Model designated for automatic topic renaming",
"title": "Automatic Topic Naming"
},
"translation": {
"label": "Translation Agent",
"modelDesc": "Specific model for translate message",
Expand Down
5 changes: 5 additions & 0 deletions locales/es-ES/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Asistente del sistema",
"topic": {
"label": "Modelo de nombramiento de temas",
"modelDesc": "Modelo designado para el renombramiento automático de temas",
"title": "Renombramiento automático de temas"
},
"translation": {
"label": "Modelo de traducción",
"modelDesc": "Especifica el modelo a utilizar para la traducción",
Expand Down
5 changes: 5 additions & 0 deletions locales/fr-FR/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Assistant système",
"topic": {
"label": "Modèle de nommage des sujets",
"modelDesc": "Modèle spécifié pour le renommage automatique des sujets",
"title": "Renommage automatique des sujets"
},
"translation": {
"label": "Modèle de traduction",
"modelDesc": "Modèle spécifié pour la traduction",
Expand Down
5 changes: 5 additions & 0 deletions locales/it-IT/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Assistente di sistema",
"topic": {
"label": "Modello di denominazione degli argomenti",
"modelDesc": "Modello designato per la ridenominazione automatica degli argomenti",
"title": "Ridenominazione automatica degli argomenti"
},
"translation": {
"label": "Modello di traduzione",
"modelDesc": "Modello specificato per la traduzione",
Expand Down
5 changes: 5 additions & 0 deletions locales/ja-JP/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "システムアシスタント",
"topic": {
"label": "トピックネーミングモデル",
"modelDesc": "トピックの自動リネームに使用されるモデルを指定します",
"title": "トピックの自動リネーム"
},
"translation": {
"label": "翻訳モデル",
"modelDesc": "翻訳に使用するモデルを指定します",
Expand Down
5 changes: 5 additions & 0 deletions locales/ko-KR/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "시스템 도우미",
"topic": {
"label": "주제 명명 모델",
"modelDesc": "주제 자동 재명명에 사용되는 모델 지정",
"title": "주제 자동 명명"
},
"translation": {
"label": "번역 모델",
"modelDesc": "번역에 사용되는 모델 지정",
Expand Down
5 changes: 5 additions & 0 deletions locales/nl-NL/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Systeemassistent",
"topic": {
"label": "Onderwerp Naamgevingsmodel",
"modelDesc": "Specificeer het model dat wordt gebruikt voor automatische hernoeming van onderwerpen",
"title": "Automatische Onderwerpnaamgeving"
},
"translation": {
"label": "Vertaalmodel",
"modelDesc": "Specificeer het model voor vertaling",
Expand Down
5 changes: 5 additions & 0 deletions locales/pl-PL/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Asystent Systemowy",
"topic": {
"label": "Model nazewnictwa tematów",
"modelDesc": "Określa model używany do automatycznego zmieniania nazw tematów",
"title": "Automatyczne nadawanie nazw tematom"
},
"translation": {
"label": "Model Tłumaczenia",
"modelDesc": "Określ model używany do tłumaczenia",
Expand Down
5 changes: 5 additions & 0 deletions locales/pt-BR/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Assistente do Sistema",
"topic": {
"label": "Modelo de Nomeação de Tópicos",
"modelDesc": "Especifica o modelo usado para renomeação automática de tópicos",
"title": "Renomeação Automática de Tópicos"
},
"translation": {
"label": "Modelo de Tradução",
"modelDesc": "Especifica o modelo usado para tradução",
Expand Down
5 changes: 5 additions & 0 deletions locales/ru-RU/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Системный агент",
"topic": {
"label": "Модель именования тем",
"modelDesc": "Модель, используемая для автоматического переименования тем",
"title": "Автоматическое именование тем"
},
"translation": {
"label": "Модель перевода",
"modelDesc": "Модель, используемая для перевода",
Expand Down
5 changes: 5 additions & 0 deletions locales/tr-TR/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Sistem Asistanı",
"topic": {
"label": "Konu Adlandırma Modeli",
"modelDesc": "Konuların otomatik olarak yeniden adlandırılması için belirlenen model",
"title": "Konu Otomatik Adlandırma"
},
"translation": {
"label": "Çeviri Modeli",
"modelDesc": "Çeviri için belirlenen model",
Expand Down
5 changes: 5 additions & 0 deletions locales/vi-VN/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "Trợ lý hệ thống",
"topic": {
"label": "Mô hình đặt tên chủ đề",
"modelDesc": "Mô hình được chỉ định để tự động đặt tên chủ đề",
"title": "Tự động đặt tên chủ đề"
},
"translation": {
"label": "Mô hình dịch",
"modelDesc": "Chọn mô hình để dịch",
Expand Down
7 changes: 6 additions & 1 deletion locales/zh-CN/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,15 @@
},
"systemAgent": {
"title": "系统助手",
"topic": {
"label": "话题命名模型",
"modelDesc": "指定用于话题自动重命名的模型",
"title": "话题自动命名"
},
"translation": {
"label": "翻译模型",
"modelDesc": "指定用于翻译的模型",
"title": "翻译助手设置"
"title": "消息内容翻译"
}
},
"tab": {
Expand Down
5 changes: 5 additions & 0 deletions locales/zh-TW/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
},
"systemAgent": {
"title": "系統助手",
"topic": {
"label": "話題命名模型",
"modelDesc": "指定用於話題自動重命名的模型",
"title": "話題自動命名"
},
"translation": {
"label": "翻譯模型",
"modelDesc": "指定用於翻譯的模型",
Expand Down
56 changes: 56 additions & 0 deletions src/app/(main)/settings/system-agent/features/Topic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use client';

import { Form, type ItemGroup } from '@lobehub/ui';
import { Form as AntForm } from 'antd';
import isEqual from 'fast-deep-equal';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { FORM_STYLE } from '@/const/layoutTokens';
import ModelSelect from '@/features/ModelSelect';
import { useUserStore } from '@/store/user';
import { settingsSelectors } from '@/store/user/selectors';

import { useSyncSystemAgent } from './useSync';

type SettingItemGroup = ItemGroup;

const Topic = memo(() => {
const { t } = useTranslation('setting');
const [form] = AntForm.useForm();

const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual);
const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]);

const systemAgentSettings: SettingItemGroup = {
children: [
{
children: (
<ModelSelect
onChange={(props) => {
updateSystemAgent('topic', props);
}}
/>
),
desc: t('systemAgent.topic.modelDesc'),
label: t('systemAgent.topic.label'),
name: ['topic', 'model'],
},
],
title: t('systemAgent.topic.title'),
};

useSyncSystemAgent(form);

return (
<Form
form={form}
initialValues={settings}
items={[systemAgentSettings]}
variant={'pure'}
{...FORM_STYLE}
/>
);
});

export default Topic;
14 changes: 6 additions & 8 deletions src/app/(main)/settings/system-agent/features/Translation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,36 @@ import ModelSelect from '@/features/ModelSelect';
import { useUserStore } from '@/store/user';
import { settingsSelectors } from '@/store/user/selectors';

import { useSyncSettings } from '../../hooks/useSyncSettings';

const SYSTEM_AGENT_SETTING_KEY = 'systemAgent';
import { useSyncSystemAgent } from './useSync';

type SettingItemGroup = ItemGroup;

const Translation = memo(() => {
const { t } = useTranslation('setting');
const [form] = AntForm.useForm();

const settings = useUserStore(settingsSelectors.currentSettings, isEqual);
const [setTranslationSystemAgent] = useUserStore((s) => [s.setTranslationSystemAgent]);
const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual);
const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]);

const systemAgentSettings: SettingItemGroup = {
children: [
{
children: (
<ModelSelect
onChange={(props) => {
setTranslationSystemAgent(props.provider, props.model);
updateSystemAgent('translation', props);
}}
/>
),
desc: t('systemAgent.translation.modelDesc'),
label: t('systemAgent.translation.label'),
name: [SYSTEM_AGENT_SETTING_KEY, 'translation', 'model'],
name: ['translation', 'model'],
},
],
title: t('systemAgent.translation.title'),
};

useSyncSettings(form);
useSyncSystemAgent(form);

return (
<Form
Expand Down
23 changes: 23 additions & 0 deletions src/app/(main)/settings/system-agent/features/useSync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FormInstance } from 'antd';
import { useLayoutEffect } from 'react';

import { useUserStore } from '@/store/user';

export const useSyncSystemAgent = (form: FormInstance) => {
useLayoutEffect(() => {
// set the first time
form.setFieldsValue(useUserStore.getState().settings.systemAgent);

// sync with later updated settings
const unsubscribe = useUserStore.subscribe(
(s) => s.settings.systemAgent,
(settings) => {
form.setFieldsValue(settings);
},
);

return () => {
unsubscribe();
};
}, []);
};
8 changes: 7 additions & 1 deletion src/app/(main)/settings/system-agent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Topic from './features/Topic';
import Translation from './features/Translation';

const Page = () => {
return <Translation />;
return (
<>
<Topic />
<Translation />
</>
);
};

Page.displayName = 'SystemAgent';
Expand Down
Loading

0 comments on commit 56865fe

Please sign in to comment.