Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Cherry Picking #76

Merged
merged 21 commits into from
Nov 10, 2023
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
1 change: 1 addition & 0 deletions app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface ChatCommands {
load?: Command;
copymemoryai?: Command;
updatemasks?: Command;
summarize?: Command;
}

export const ChatCommandPrefix = ":";
Expand Down
11 changes: 7 additions & 4 deletions app/components/changelog.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
font-size: 24px;
font-weight: bold;
line-height: 3;
position: relative;
}

.changelog-tips {
Expand Down Expand Up @@ -51,6 +52,9 @@
height: 10%;
width: 10%;
margin-top: auto; /* Add margin for spacing */
padding-top: 10px;
padding-bottom: 10px;
position: relative;

button:not(:last-child) {
margin-bottom: auto;
Expand All @@ -73,7 +77,7 @@
justify-content: space-evenly; /* Spread the buttons evenly */
align-items: center; /* Center align the buttons vertically */
margin-top: auto; /* Adjust the margin */

position: relative;
button {
width: auto; /* Reset the width to auto */
}
Expand All @@ -93,9 +97,8 @@
flex-direction: row; /* Change to horizontal layout */
justify-content: space-evenly; /* Spread the buttons evenly */
align-items: center; /* Center align the buttons vertically */
height: 10%;
width: 10%;
margin-top: 20px; /* Adjust the margin */
margin-top: auto; /* Adjust the margin */
position: relative;
}

button {
Expand Down
8 changes: 7 additions & 1 deletion app/components/changelog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ export function ChangeLog(props: { onClose?: () => void }) {
}

const authorSection = `[${author.replace("[bot]", "").replace(/\s/g, "")}](https://github.com/${author.replace("[bot]", "").replace(/\s/g, "")}) ${coAuthorsSection}`;
const prLinkRegex = /#(\d+)/g; // Regular expression to match '#<number>' ref : autolinks github
const prLink = commitInfo?.commitMessage.summary.replace(prLinkRegex, '[$&](https://github.com/H0llyW00dzZ/ChatGPT-Next-Web/pull/$1/commits)');
const descriptionWithLinks = commitInfo?.commitMessage.description.map((change: string) =>
change.replace(prLinkRegex, '[$&](https://github.com/H0llyW00dzZ/ChatGPT-Next-Web/pull/$1/commits)')
).join('\n\n\n');

table += `\n\n\n![GitHub contributors](https://img.shields.io/github/contributors/Yidadaa/ChatGPT-Next-Web.svg) ![GitHub commits](https://badgen.net/github/commits/H0llyW00dzZ/ChatGPT-Next-Web) ![GitHub license](https://img.shields.io/github/license/H0llyW00dzZ/ChatGPT-Next-Web) [![GitHub forks](https://img.shields.io/github/forks/Yidadaa/ChatGPT-Next-Web.svg)](https://github.com/Yidadaa/ChatGPT-Next-Web/network/members) [![GitHub stars](https://img.shields.io/github/stars/Yidadaa/ChatGPT-Next-Web.svg)](https://github.com/Yidadaa/ChatGPT-Next-Web/stargazers) [![Github All Releases](https://img.shields.io/github/downloads/Yidadaa/ChatGPT-Next-Web/total.svg)](https://github.com/Yidadaa/ChatGPT-Next-Web/releases/)\n\n\n [![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/${author}) ![${author.replace("[bot]", "")}](https://github.com/${author.replace("[bot]", "")}.png?size=25) ${authorSection} :\n\n${commitInfo?.commitMessage.summary}\n\n\n${changesFormatted}\n\n\n`; } else {
table += `\n\n\n![GitHub contributors](https://img.shields.io/github/contributors/Yidadaa/ChatGPT-Next-Web.svg) ![GitHub commits](https://badgen.net/github/commits/H0llyW00dzZ/ChatGPT-Next-Web) ![GitHub license](https://img.shields.io/github/license/H0llyW00dzZ/ChatGPT-Next-Web) [![GitHub forks](https://img.shields.io/github/forks/Yidadaa/ChatGPT-Next-Web.svg)](https://github.com/Yidadaa/ChatGPT-Next-Web/network/members) [![GitHub stars](https://img.shields.io/github/stars/Yidadaa/ChatGPT-Next-Web.svg)](https://github.com/Yidadaa/ChatGPT-Next-Web/stargazers) [![Github All Releases](https://img.shields.io/github/downloads/Yidadaa/ChatGPT-Next-Web/total.svg)](https://github.com/Yidadaa/ChatGPT-Next-Web/releases/)\n\n\n [![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/${author}) ![${author.replace("[bot]", "")}](https://github.com/${author.replace("[bot]", "")}.png?size=25) ${authorSection} :\n\n${prLink}\n\n\n${descriptionWithLinks}\n\n\n\n\n\n`;
} else {
table += `###${commitInfo?.commitMessage.summary}###\nNo changes\n\n`;
}

Expand Down
106 changes: 90 additions & 16 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ import PinIcon from "../icons/pin.svg";
import EditIcon from "../icons/rename.svg";
import ConfirmIcon from "../icons/confirm.svg";
import CancelIcon from "../icons/cancel.svg";
import DownloadIcon from "../icons/download.svg";
import UploadIcon from "../icons/upload.svg";

import LightIcon from "../icons/light.svg";
import DarkIcon from "../icons/dark.svg";
import AutoIcon from "../icons/auto.svg";
import BottomIcon from "../icons/bottom.svg";
import StopIcon from "../icons/pause.svg";
import RobotIcon from "../icons/robot.svg";
import EyeOnIcon from "../icons/eye.svg";
import EyeOffIcon from "../icons/eye-off.svg";
import { escapeRegExp } from "lodash";

import {
Expand Down Expand Up @@ -103,12 +107,60 @@ export function SessionConfigModel(props: { onClose: () => void }) {
const maskStore = useMaskStore();
const navigate = useNavigate();

const [exporting, setExporting] = useState(false);
const isApp = !!getClientConfig()?.isApp;

const handleExport = async () => {
if (exporting) return;
setExporting(true);
const currentDate = new Date();
const currentSession = chatStore.currentSession();
const messageCount = currentSession.messages.length;
const datePart = isApp
? `${currentDate.toLocaleDateString().replace(/\//g, '_')} ${currentDate.toLocaleTimeString().replace(/:/g, '_')}`
: `${currentDate.toLocaleString().replace(/:/g, '_')}`;

const formattedMessageCount = Locale.ChatItem.ChatItemCount(messageCount); // Format the message count using the translation function
const fileName = `${session.topic}-(${formattedMessageCount})-${datePart}.json`;
await downloadAs(session, fileName);
setExporting(false);
};

const importchat = async () => {
await readFromFile().then((content) => {
try {
const importedData = JSON.parse(content);
chatStore.updateCurrentSession((session) => {
Object.assign(session, importedData);
});
} catch (e) {
console.error("[Import] Failed to import JSON file:", e);
showToast(Locale.Settings.Sync.ImportFailed);
}
});
};

return (
<div className="modal-mask">
<Modal
title={Locale.Context.Edit}
onClose={() => props.onClose()}
actions={[
<IconButton
key="export"
icon={<DownloadIcon />}
bordered
text={Locale.UI.Export}
onClick={handleExport}
disabled={exporting}
/>,
<IconButton
key="import"
icon={<UploadIcon />}
bordered
text={Locale.UI.Import}
onClick={importchat}
/>,
<IconButton
key="reset"
icon={<ResetIcon />}
Expand Down Expand Up @@ -413,6 +465,8 @@ export function ChatActions(props: {
scrollToBottom: () => void;
showPromptHints: () => void;
hitBottom: boolean;
showContextPrompts: boolean;
toggleContextPrompts: () => void;
}) {
const config = useAppConfig();
const navigate = useNavigate();
Expand Down Expand Up @@ -485,6 +539,22 @@ export function ChatActions(props: {
icon={<PromptIcon />}
/>

<ChatAction
onClick={props.toggleContextPrompts}
text={
props.showContextPrompts
? Locale.Mask.Config.HideContext.UnHide
: Locale.Mask.Config.HideContext.Hide
}
icon={
props.showContextPrompts ? (
<EyeOffIcon />
) : (
<EyeOnIcon />
)
}
/>

<ChatAction
onClick={() => {
navigate(Path.Masks);
Expand Down Expand Up @@ -653,11 +723,9 @@ function _Chat() {
const loadchat = () => {
readFromFile().then((content) => {
try {
const importedSession = JSON.parse(content);
const importedData = JSON.parse(content);
chatStore.updateCurrentSession((session) => {
session.messages = importedSession.messages;
session.topic = importedSession.topic;
session.memoryPrompt = importedSession.memoryPrompt;
Object.assign(session, importedData);
// Set any other properties you want to update in the session
});
} catch (e) {
Expand Down Expand Up @@ -923,21 +991,25 @@ function _Chat() {
});
};

const context: RenderMessage[] = useMemo(() => {
return session.mask.hideContext ? [] : session.mask.context.slice();
}, [session.mask.context, session.mask.hideContext]);
const accessStore = useAccessStore();
const isAuthorized = accessStore.isAuthorized();
const context: RenderMessage[] = useMemo(() => {
const contextMessages = session.mask.hideContext ? [] : session.mask.context.slice();

if (
context.length === 0 &&
session.messages.at(0)?.content !== BOT_HELLO.content
) {
const copiedHello = Object.assign({}, BOT_HELLO);
if (!accessStore.isAuthorized()) {
copiedHello.content = Locale.Error.Unauthorized;
if (
contextMessages.length === 0 &&
session.messages.at(0)?.role !== "system"
) {
const copiedHello = Object.assign({}, BOT_HELLO);
if (!isAuthorized) {
copiedHello.role = "system";
copiedHello.content = Locale.Error.Unauthorized;
}
contextMessages.push(copiedHello);
}
context.push(copiedHello);
}

return contextMessages;
}, [session.mask.context, session.mask.hideContext, session.messages, isAuthorized]);

// preview messages
const renderMessages = useMemo(() => {
Expand Down Expand Up @@ -1330,6 +1402,8 @@ function _Chat() {
setUserInput("/");
onSearch("");
}}
showContextPrompts={false}
toggleContextPrompts={() => showToast(Locale.WIP)}
/>
<div className={styles["chat-input-panel-inner"]}>
<textarea
Expand Down
4 changes: 2 additions & 2 deletions app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import LoadingIcon from "../icons/three-dots.svg";
import { getCSSVar, useMobileScreen } from "../utils";

import dynamic from "next/dynamic";
import { Path, SlotID } from "../constant";
import { Path, SlotID, DEFAULT_CORS_HOST } from "../constant";
import { ErrorBoundary } from "./error";

import { getISOLang, getLang } from "../locales";
Expand Down Expand Up @@ -118,7 +118,7 @@ const useHasHydrated = () => {
const loadAsyncGoogleFont = () => {
const linkEl = document.createElement("link");
const proxyFontUrl = "/google-fonts";
const remoteFontUrl = "https://fonts.googleapis.com";
const remoteFontUrl = `${DEFAULT_CORS_HOST}/google-fonts`; // we use proxy in client app
const googleFontUrl =
getClientConfig()?.buildMode === "export" ? remoteFontUrl : proxyFontUrl;
linkEl.rel = "stylesheet";
Expand Down
22 changes: 17 additions & 5 deletions app/components/privacy.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@
margin-bottom: 20px; /* Add margin for spacing */
}

.privacy-header {
display: flex;
align-items: center;
justify-content: center;
margin-right: 10px;
}

.privacy-title {
font-size: 24px;
font-weight: bold;
line-height: 3;
}
position: relative;
margin-right: 10px; /* Add some spacing to the right of the title */
}

.privacy-tips {
box-sizing: border-box;
Expand Down Expand Up @@ -51,6 +60,9 @@
height: 10%;
width: 10%;
margin-top: auto; /* Add margin for spacing */
padding-top: 10px;
padding-bottom: 10px;
position: relative;

button:not(:last-child) {
margin-bottom: auto;
Expand All @@ -62,6 +74,7 @@
justify-content: space-evenly; /* Spread the buttons evenly */
align-items: center; /* Center align the buttons vertically */
margin-top: auto; /* Adjust the margin */
position: relative;
button {
width: auto; /* Set a fixed width for the buttons */
}
Expand All @@ -73,7 +86,7 @@
justify-content: space-evenly; /* Spread the buttons evenly */
align-items: center; /* Center align the buttons vertically */
margin-top: auto; /* Adjust the margin */

position: relative;
button {
width: auto; /* Reset the width to auto */
}
Expand All @@ -93,9 +106,8 @@
flex-direction: row; /* Change to horizontal layout */
justify-content: space-evenly; /* Spread the buttons evenly */
align-items: center; /* Center align the buttons vertically */
height: 10%;
width: 10%;
margin-top: 20px; /* Adjust the margin */
margin-top: auto; /* Adjust the margin */
position: relative;
}

button {
Expand Down
Loading