}
- onClick={clearSessions}
+ onClick={() => {
+ const confirmed = window.confirm(
+ `${Locale.Settings.Actions.ConfirmClearAll.Confirm}`,
+ );
+ if (confirmed) {
+ clearSessions();
+ }
+ }}
bordered
title={Locale.Settings.Actions.ClearAll}
/>
@@ -164,7 +171,14 @@ export function Settings(props: { closeSettings: () => void }) {
}
- onClick={resetConfig}
+ onClick={() => {
+ const confirmed = window.confirm(
+ `${Locale.Settings.Actions.ConfirmResetAll.Confirm}`,
+ );
+ if (confirmed) {
+ resetConfig();
+ }
+ }}
bordered
title={Locale.Settings.Actions.ResetAll}
/>
diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss
index 83eb614f7..67d13d3e8 100644
--- a/app/components/ui-lib.module.scss
+++ b/app/components/ui-lib.module.scss
@@ -9,6 +9,7 @@
.popover {
position: relative;
+ z-index: 2;
}
.popover-content {
diff --git a/app/locales/cn.ts b/app/locales/cn.ts
index e21272a12..01b236d7f 100644
--- a/app/locales/cn.ts
+++ b/app/locales/cn.ts
@@ -21,11 +21,11 @@ const cn = {
Rename: "重命名对话",
Typing: "正在输入…",
Input: (submitKey: string) => {
- var inputHints = `输入消息,${submitKey} 发送`;
+ var inputHints = `${submitKey} 发送`;
if (submitKey === String(SubmitKey.Enter)) {
inputHints += ",Shift + Enter 换行";
}
- return inputHints;
+ return inputHints + ",/ 触发补全";
},
Send: "发送",
},
@@ -57,6 +57,12 @@ const cn = {
ClearAll: "清除所有数据",
ResetAll: "重置所有选项",
Close: "关闭",
+ ConfirmResetAll: {
+ Confirm: "Are you sure you want to reset all configurations?",
+ },
+ ConfirmClearAll: {
+ Confirm: "Are you sure you want to reset all chat?",
+ },
},
Lang: {
Name: "Language",
@@ -126,7 +132,7 @@ const cn = {
Model: "模型 (model)",
Temperature: {
Title: "随机性 (temperature)",
- SubTitle: "值越大,回复越随机",
+ SubTitle: "值越大,回复越随机,大于 1 的值可能会导致乱码",
},
MaxTokens: {
Title: "单次回复限制 (max_tokens)",
diff --git a/app/locales/en.ts b/app/locales/en.ts
index 61d20b60f..731309034 100644
--- a/app/locales/en.ts
+++ b/app/locales/en.ts
@@ -23,11 +23,11 @@ const en: LocaleType = {
Rename: "Rename Chat",
Typing: "Typing…",
Input: (submitKey: string) => {
- var inputHints = `Type something and press ${submitKey} to send`;
+ var inputHints = `${submitKey} to send`;
if (submitKey === String(SubmitKey.Enter)) {
- inputHints += ", press Shift + Enter to newline";
+ inputHints += ", Shift + Enter to wrap";
}
- return inputHints;
+ return inputHints + ", / to search prompts";
},
Send: "Send",
},
@@ -60,6 +60,12 @@ const en: LocaleType = {
ClearAll: "Clear All Data",
ResetAll: "Reset All Settings",
Close: "Close",
+ ConfirmResetAll: {
+ Confirm: "Are you sure you want to reset all configurations?",
+ },
+ ConfirmClearAll: {
+ Confirm: "Are you sure you want to reset all chat?",
+ },
},
Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
diff --git a/app/locales/es.ts b/app/locales/es.ts
index 5a83cb55c..06277f6b5 100644
--- a/app/locales/es.ts
+++ b/app/locales/es.ts
@@ -60,6 +60,12 @@ const es: LocaleType = {
ClearAll: "Borrar todos los datos",
ResetAll: "Restablecer todas las configuraciones",
Close: "Cerrar",
+ ConfirmResetAll: {
+ Confirm: "Are you sure you want to reset all configurations?",
+ },
+ ConfirmClearAll: {
+ Confirm: "Are you sure you want to reset all chat?",
+ },
},
Lang: {
Name: "Language",
diff --git a/app/locales/it.ts b/app/locales/it.ts
index 7108090eb..70967d966 100644
--- a/app/locales/it.ts
+++ b/app/locales/it.ts
@@ -60,6 +60,12 @@ const it: LocaleType = {
ClearAll: "Cancella tutti i dati",
ResetAll: "Resetta tutte le impostazioni",
Close: "Chiudi",
+ ConfirmResetAll: {
+ Confirm: "Sei sicuro vuoi cancellare tutte le impostazioni?",
+ },
+ ConfirmClearAll: {
+ Confirm: "Sei sicuro vuoi cancellare tutte le chat?",
+ },
},
Lang: {
Name: "Lingue",
diff --git a/app/locales/tw.ts b/app/locales/tw.ts
index ff1794b55..3861a671c 100644
--- a/app/locales/tw.ts
+++ b/app/locales/tw.ts
@@ -58,6 +58,12 @@ const tw: LocaleType = {
ClearAll: "清除所有數據",
ResetAll: "重置所有設定",
Close: "關閉",
+ ConfirmResetAll: {
+ Confirm: "Are you sure you want to reset all configurations?",
+ },
+ ConfirmClearAll: {
+ Confirm: "Are you sure you want to reset all chat?",
+ },
},
Lang: {
Name: "Language",
diff --git a/app/requests.ts b/app/requests.ts
index 5ca5e217a..d7d8e4184 100644
--- a/app/requests.ts
+++ b/app/requests.ts
@@ -24,7 +24,11 @@ const makeRequestParam = (
sendMessages = sendMessages.filter((m) => m.role !== "assistant");
}
- const modelConfig = useChatStore.getState().config.modelConfig;
+ const modelConfig = { ...useChatStore.getState().config.modelConfig };
+
+ // @yidadaa: wont send max_tokens, because it is nonsense for Muggles
+ // @ts-expect-error
+ delete modelConfig.max_tokens;
return {
messages: sendMessages,
diff --git a/app/store/app.ts b/app/store/app.ts
index e6e391162..bf302eca9 100644
--- a/app/store/app.ts
+++ b/app/store/app.ts
@@ -337,18 +337,19 @@ export const useChatStore = create
()(
const isLastSession = get().sessions.length === 1;
if (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) {
get().removeSession(index);
+
+ showToast(Locale.Home.DeleteToast, {
+ text: Locale.Home.Revert,
+ onClick() {
+ set((state) => ({
+ sessions: state.sessions
+ .slice(0, index)
+ .concat([deletedSession])
+ .concat(state.sessions.slice(index + Number(isLastSession))),
+ }));
+ },
+ });
}
- showToast(Locale.Home.DeleteToast, {
- text: Locale.Home.Revert,
- onClick() {
- set((state) => ({
- sessions: state.sessions
- .slice(0, index)
- .concat([deletedSession])
- .concat(state.sessions.slice(index + Number(isLastSession))),
- }));
- },
- });
},
currentSession() {
diff --git a/app/store/prompt.ts b/app/store/prompt.ts
index b91a38d0b..d0dd454ac 100644
--- a/app/store/prompt.ts
+++ b/app/store/prompt.ts
@@ -1,6 +1,7 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import Fuse from "fuse.js";
+import { getLang } from "../locales";
export interface Prompt {
id?: number;
@@ -25,11 +26,13 @@ export const SearchService = {
count: {
builtin: 0,
},
+ allBuiltInPrompts: [] as Prompt[],
init(prompts: Prompt[]) {
if (this.ready) {
return;
}
+ this.allBuiltInPrompts = prompts;
this.engine.setCollection(prompts);
this.ready = true;
},
@@ -78,6 +81,11 @@ export const usePromptStore = create()(
},
search(text) {
+ if (text.length === 0) {
+ // return all prompts
+ const userPrompts = get().prompts?.values?.() ?? [];
+ return SearchService.allBuiltInPrompts.concat([...userPrompts]);
+ }
return SearchService.search(text) as Prompt[];
},
}),
@@ -92,7 +100,11 @@ export const usePromptStore = create()(
fetch(PROMPT_URL)
.then((res) => res.json())
.then((res) => {
- const builtinPrompts = [res.en, res.cn]
+ let fetchPrompts = [res.en, res.cn];
+ if (getLang() === "cn") {
+ fetchPrompts = fetchPrompts.reverse();
+ }
+ const builtinPrompts = fetchPrompts
.map((promptList: PromptList) => {
return promptList.map(
([title, content]) =>
diff --git a/app/utils.ts b/app/utils.ts
index 333866c7b..9a792fd52 100644
--- a/app/utils.ts
+++ b/app/utils.ts
@@ -51,6 +51,12 @@ export function isMobileScreen() {
return window.innerWidth <= 600;
}
+export function isFirefox() {
+ return (
+ typeof navigator !== "undefined" && /firefox/i.test(navigator.userAgent)
+ );
+}
+
export function selectOrCopy(el: HTMLElement, content: string) {
const currentSelection = window.getSelection();
@@ -91,3 +97,51 @@ export function getCurrentVersion() {
export function getEmojiUrl(unified: string, style: EmojiStyle) {
return `https://cdn.staticfile.org/emoji-datasource-apple/14.0.0/img/${style}/64/${unified}.png`;
}
+
+function getDomContentWidth(dom: HTMLElement) {
+ const style = window.getComputedStyle(dom);
+ const paddingWidth =
+ parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
+ const width = dom.clientWidth - paddingWidth;
+ return width;
+}
+
+function getOrCreateMeasureDom(id: string, init?: (dom: HTMLElement) => void) {
+ let dom = document.getElementById(id);
+
+ if (!dom) {
+ dom = document.createElement("span");
+ dom.style.position = "absolute";
+ dom.style.wordBreak = "break-word";
+ dom.style.fontSize = "14px";
+ dom.style.transform = "translateY(-200vh)";
+ dom.style.pointerEvents = "none";
+ dom.style.opacity = "0";
+ dom.id = id;
+ document.body.appendChild(dom);
+ init?.(dom);
+ }
+
+ return dom!;
+}
+
+export function autoGrowTextArea(dom: HTMLTextAreaElement) {
+ const measureDom = getOrCreateMeasureDom("__measure");
+ const singleLineDom = getOrCreateMeasureDom("__single_measure", (dom) => {
+ dom.innerText = "TEXT_FOR_MEASURE";
+ });
+
+ const width = getDomContentWidth(dom);
+ measureDom.style.width = width + "px";
+ measureDom.innerHTML = dom.value.trim().length > 0 ? dom.value : "1";
+
+ const lineWrapCount = Math.max(0, dom.value.split("\n").length - 1);
+ const height = parseFloat(window.getComputedStyle(measureDom).height);
+ const singleLineHeight = parseFloat(
+ window.getComputedStyle(singleLineDom).height,
+ );
+
+ const rows = Math.round(height / singleLineHeight) + lineWrapCount;
+
+ return rows;
+}
diff --git a/tsconfig.json b/tsconfig.json
index 14d189328..c73eef3e8 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -23,6 +23,6 @@
"@/*": ["./*"]
}
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "app/calcTextareaHeight.ts"],
"exclude": ["node_modules"]
}
diff --git a/vercel.json b/vercel.json
new file mode 100644
index 000000000..0cae358a1
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,5 @@
+{
+ "github": {
+ "silent": true
+ }
+}