Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: menual regen title #5430

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import QualityIcon from "../icons/hd.svg";
import StyleIcon from "../icons/palette.svg";
import PluginIcon from "../icons/plugin.svg";
import ShortcutkeyIcon from "../icons/shortcutkey.svg";
import ReloadIcon from "../icons/reload.svg";

import {
ChatMessage,
Expand Down Expand Up @@ -1541,6 +1542,17 @@ function _Chat() {
</div>
</div>
<div className="window-actions">
<div className="window-action-button">
<IconButton
icon={<ReloadIcon />}
bordered
title={Locale.Chat.Actions.RefreshTitle}
onClick={() => {
showToast(Locale.Chat.Actions.RefreshToast);
chatStore.summarizeSession(true);
}}
/>
</div>
{!isMobileScreen && (
<div className="window-action-button">
<IconButton
Expand Down
2 changes: 2 additions & 0 deletions app/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const ar: PartialLocaleType = {
PinToastAction: "عرض",
Delete: "حذف",
Edit: "تحرير",
RefreshTitle: "تحديث العنوان",
RefreshToast: "تم إرسال طلب تحديث العنوان",
},
Commands: {
new: "دردشة جديدة",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/bn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const bn: PartialLocaleType = {
PinToastAction: "দেখুন",
Delete: "মুছে ফেলুন",
Edit: "সম্পাদনা করুন",
RefreshTitle: "শিরোনাম রিফ্রেশ করুন",
RefreshToast: "শিরোনাম রিফ্রেশ অনুরোধ পাঠানো হয়েছে",
},
Commands: {
new: "নতুন চ্যাট",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const cn = {
Delete: "删除",
Edit: "编辑",
FullScreen: "全屏",
RefreshTitle: "刷新标题",
RefreshToast: "已发送刷新标题请求",
},
Commands: {
new: "新建聊天",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const cs: PartialLocaleType = {
PinToastAction: "Zobrazit",
Delete: "Smazat",
Edit: "Upravit",
RefreshTitle: "Obnovit název",
RefreshToast: "Požadavek na obnovení názvu byl odeslán",
},
Commands: {
new: "Nová konverzace",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const de: PartialLocaleType = {
PinToastAction: "Ansehen",
Delete: "Löschen",
Edit: "Bearbeiten",
RefreshTitle: "Titel aktualisieren",
RefreshToast: "Anfrage zur Titelaktualisierung gesendet",
},
Commands: {
new: "Neues Gespräch",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const en: LocaleType = {
Delete: "Delete",
Edit: "Edit",
FullScreen: "FullScreen",
RefreshTitle: "Refresh Title",
RefreshToast: "Title refresh request sent",
},
Commands: {
new: "Start a new chat",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const es: PartialLocaleType = {
PinToastAction: "Ver",
Delete: "Eliminar",
Edit: "Editar",
RefreshTitle: "Actualizar título",
RefreshToast: "Se ha enviado la solicitud de actualización del título",
},
Commands: {
new: "Nueva conversación",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const fr: PartialLocaleType = {
PinToastAction: "Voir",
Delete: "Supprimer",
Edit: "Modifier",
RefreshTitle: "Actualiser le titre",
RefreshToast: "Demande d'actualisation du titre envoyée",
},
Commands: {
new: "Nouvelle discussion",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const id: PartialLocaleType = {
PinToastAction: "Lihat",
Delete: "Hapus",
Edit: "Edit",
RefreshTitle: "Segarkan Judul",
RefreshToast: "Permintaan penyegaran judul telah dikirim",
},
Commands: {
new: "Obrolan Baru",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const it: PartialLocaleType = {
PinToastAction: "Visualizza",
Delete: "Elimina",
Edit: "Modifica",
RefreshTitle: "Aggiorna titolo",
RefreshToast: "Richiesta di aggiornamento del titolo inviata",
},
Commands: {
new: "Nuova chat",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const jp: PartialLocaleType = {
PinToastAction: "見る",
Delete: "削除",
Edit: "編集",
RefreshTitle: "タイトルを更新",
RefreshToast: "タイトル更新リクエストが送信されました",
},
Commands: {
new: "新しいチャット",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const ko: PartialLocaleType = {
PinToastAction: "보기",
Delete: "삭제",
Edit: "편집",
RefreshTitle: "제목 새로고침",
RefreshToast: "제목 새로고침 요청이 전송되었습니다",
},
Commands: {
new: "새 채팅",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/no.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const no: PartialLocaleType = {
PinToastAction: "Se",
Delete: "Slett",
Edit: "Rediger",
RefreshTitle: "Oppdater tittel",
RefreshToast: "Forespørsel om titteloppdatering sendt",
},
Commands: {
new: "Ny samtale",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const pt: PartialLocaleType = {
PinToastAction: "Visualizar",
Delete: "Deletar",
Edit: "Editar",
RefreshTitle: "Atualizar Título",
RefreshToast: "Solicitação de atualização de título enviada",
},
Commands: {
new: "Iniciar um novo chat",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const ru: PartialLocaleType = {
PinToastAction: "Просмотреть",
Delete: "Удалить",
Edit: "Редактировать",
RefreshTitle: "Обновить заголовок",
RefreshToast: "Запрос на обновление заголовка отправлен",
},
Commands: {
new: "Новый чат",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/sk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const sk: PartialLocaleType = {
PinToastAction: "Zobraziť",
Delete: "Vymazať",
Edit: "Upraviť",
RefreshTitle: "Obnoviť názov",
RefreshToast: "Požiadavka na obnovenie názvu bola odoslaná",
},
Commands: {
new: "Začať nový chat",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const tr: PartialLocaleType = {
PinToastAction: "Görünüm",
Delete: "Sil",
Edit: "Düzenle",
RefreshTitle: "Başlığı Yenile",
RefreshToast: "Başlık yenileme isteği gönderildi",
},
Commands: {
new: "Yeni sohbet",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const tw = {
PinToastAction: "檢視",
Delete: "刪除",
Edit: "編輯",
RefreshTitle: "刷新標題",
RefreshToast: "已發送刷新標題請求",
},
Commands: {
new: "新建聊天",
Expand Down
2 changes: 2 additions & 0 deletions app/locales/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const vi: PartialLocaleType = {
PinToastAction: "Xem",
Delete: "Xóa",
Edit: "Chỉnh sửa",
RefreshTitle: "Làm mới tiêu đề",
RefreshToast: "Đã gửi yêu cầu làm mới tiêu đề",
},
Commands: {
new: "Tạo cuộc trò chuyện mới",
Expand Down
28 changes: 19 additions & 9 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export const useChatStore = createPersistStore(
});
},

summarizeSession() {
summarizeSession(refreshTitle: boolean = false) {
const config = useAppConfig.getState();
const session = get().currentSession();
const modelConfig = session.mask.modelConfig;
Expand All @@ -590,16 +590,26 @@ export const useChatStore = createPersistStore(
// should summarize topic after chating more than 50 words
const SUMMARIZE_MIN_LEN = 50;
if (
config.enableAutoGenerateTitle &&
session.topic === DEFAULT_TOPIC &&
countMessages(messages) >= SUMMARIZE_MIN_LEN
(config.enableAutoGenerateTitle &&
session.topic === DEFAULT_TOPIC &&
countMessages(messages) >= SUMMARIZE_MIN_LEN) ||
refreshTitle
) {
const topicMessages = messages.concat(
createMessage({
role: "user",
content: Locale.Store.Prompt.Topic,
}),
const startIndex = Math.max(
0,
messages.length - modelConfig.historyMessageCount,
);
const topicMessages = messages
.slice(
startIndex < messages.length ? startIndex : messages.length - 1,
messages.length,
)
.concat(
createMessage({
role: "user",
content: Locale.Store.Prompt.Topic,
}),
);
api.llm.chat({
messages: topicMessages,
config: {
Expand Down
Loading