Skip to content

适配一些功能 #61

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

Open
wants to merge 1 commit into
base: pro-v0.9.4
Choose a base branch
from
Open
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn config set registry 'https://registry.npmmirror.com/'
RUN yarn install

COPY . .
Expand Down
51 changes: 37 additions & 14 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ import Locale from "../locales";
import { IconButton } from "./button";
import styles from "./chat.module.scss";

import { ListItem, Modal, showConfirm, showPrompt, showToast } from "./ui-lib";
import {
ListItem,
Modal,
Selector,
showConfirm,
showPrompt,
showToast,
} from "./ui-lib";
import { useLocation, useNavigate } from "react-router-dom";
import { LAST_INPUT_KEY, Path, REQUEST_TIMEOUT_MS } from "../constant";
import { Avatar } from "./emoji";
Expand Down Expand Up @@ -466,19 +473,12 @@ export function ChatActions(props: {
const currentModel = chatStore.currentSession().mask.modelConfig.model;
const currentContentType =
chatStore.currentSession().mask.modelConfig.contentType;
function nextModel() {
const models = availableModels;
const modelIndex = models.findIndex(
(m) => m.name === currentModel && m.contentType === currentContentType,
const models = useMemo(
() => availableModels,
[availableModels],
);
const nextIndex = (modelIndex + 1) % models.length;
const nextModel = models[nextIndex];
chatStore.updateCurrentSession((session) => {
session.mask.modelConfig.model = nextModel.name as ModelType;
session.mask.modelConfig.contentType = nextModel.contentType;
session.mask.syncGlobalConfig = false;
});
}
const [showModelSelector, setShowModelSelector] = useState(false);


return (
<div className={styles["chat-input-actions"]}>
Expand Down Expand Up @@ -556,7 +556,7 @@ export function ChatActions(props: {
/>

<ChatAction
onClick={nextModel}
onClick={() => setShowModelSelector(true)}
text={currentModel}
icon={<RobotIcon />}
/>
Expand All @@ -579,6 +579,29 @@ export function ChatActions(props: {
);
})}
</>
{showModelSelector && (
<Selector
items={models.map((m) => ({
title: m.name,
value: m.name,
}))}
onClose={() => setShowModelSelector(false)}
onSelection={(s) => {
if (s.length === 0) return;
chatStore.updateCurrentSession((session) => {
session.mask.modelConfig.model = s[0] as ModelType;
if (s[0].match(/MidJourney|Stable|Diffusion|sd|mj|绘|画|图/i)) {
session.mask.modelConfig.contentType = "Image";
}
else {
session.mask.modelConfig.contentType = "Text";
}
session.mask.syncGlobalConfig = false;
});
showToast(s[0]);
}}
/>
)}
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/exporter.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
box-shadow: var(--card-shadow);
border: var(--border-in-light);

* {
*:not(li) {
overflow: hidden;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function Screen(props: { logoLoading: boolean; logoUrl?: string }) {
config.tightBorder && !isMobileScreen
? styles["tight-container"]
: styles.container
} ${getLang() === "ar" ? styles["rtl-screen"] : ""}`
}`
}
>
{isAuth ? (
Expand Down
9 changes: 7 additions & 2 deletions app/components/mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,19 @@ export function MaskConfig(props: {
type="checkbox"
checked={props.mask.syncGlobalConfig}
onChange={async (e) => {
const checked = e.currentTarget.checked;
if (
e.currentTarget.checked &&
checked &&
(await showConfirm(Locale.Mask.Config.Sync.Confirm))
) {
props.updateMask((mask) => {
mask.syncGlobalConfig = e.currentTarget.checked;
mask.syncGlobalConfig = checked;
mask.modelConfig = { ...globalConfig.modelConfig };
});
} else if (!checked) {
props.updateMask((mask) => {
mask.syncGlobalConfig = checked;
});
}
}}
></input>
Expand Down
90 changes: 17 additions & 73 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,77 +237,6 @@ function DangerItems() {
);
}

function SyncItems() {
const syncStore = useSyncStore();
const webdav = syncStore.webDavConfig;

// not ready: https://github.com/Yidadaa/ChatGPT-Next-Web/issues/920#issuecomment-1609866332
return null;

return (
<List>
<ListItem
title={"上次同步:" + new Date().toLocaleString()}
subTitle={"20 次对话,100 条消息,200 提示词,20 面具"}
>
<IconButton
icon={<ResetIcon />}
text="同步"
onClick={() => {
syncStore.check().then(console.log);
}}
/>
</ListItem>

<ListItem
title={"本地备份"}
subTitle={"20 次对话,100 条消息,200 提示词,20 面具"}
></ListItem>

<ListItem
title={"Web Dav Server"}
subTitle={Locale.Settings.AccessCode.SubTitle}
>
<input
value={webdav.server}
type="text"
placeholder={"https://example.com"}
onChange={(e) => {
syncStore.update(
(config) => (config.server = e.currentTarget.value),
);
}}
/>
</ListItem>

<ListItem title="Web Dav User Name" subTitle="user name here">
<input
value={webdav.username}
type="text"
placeholder={"username"}
onChange={(e) => {
syncStore.update(
(config) => (config.username = e.currentTarget.value),
);
}}
/>
</ListItem>

<ListItem title="Web Dav Password" subTitle="password here">
<input
value={webdav.password}
type="text"
placeholder={"password"}
onChange={(e) => {
syncStore.update(
(config) => (config.password = e.currentTarget.value),
);
}}
/>
</ListItem>
</List>
);
}

export function Settings() {
const navigate = useNavigate();
Expand Down Expand Up @@ -521,6 +450,23 @@ export function Settings() {
}
></InputRange>
</ListItem>

<ListItem
title={Locale.Settings.AutoGenerateTitle.Title}
subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}
>
<input
type="checkbox"
checked={config.enableAutoGenerateTitle}
onChange={(e) =>
updateConfig(
(config) =>
(config.enableAutoGenerateTitle = e.currentTarget.checked),
)
}
></input>
</ListItem>

{/*
<ListItem
title={Locale.Settings.SendPreviewBubble.Title}
Expand Down Expand Up @@ -666,8 +612,6 @@ export function Settings() {
</ListItem>
</List>

<SyncItems />

<List>
<ModelConfigList
modelConfig={config.modelConfig}
Expand Down
64 changes: 60 additions & 4 deletions app/components/ui-lib.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
box-shadow: var(--card-shadow);
margin-bottom: 20px;
animation: slide-in ease 0.3s;
background: var(--white);
}

.list .list-item:last-child {
Expand All @@ -77,6 +78,19 @@

--modal-padding: 20px;

&-max {
width: 95vw;
max-width: unset;
height: 95vh;
display: flex;
flex-direction: column;

.modal-content {
max-height: unset !important;
flex-grow: 1;
}
}

.modal-header {
padding: var(--modal-padding);
display: flex;
Expand All @@ -89,11 +103,19 @@
font-size: 16px;
}

.modal-close-btn {
cursor: pointer;
.modal-header-actions {
display: flex;

&:hover {
filter: brightness(1.2);
.modal-header-action {
cursor: pointer;

&:not(:last-child) {
margin-right: 20px;
}

&:hover {
filter: brightness(1.2);
}
}
}
}
Expand Down Expand Up @@ -254,3 +276,37 @@
border: 1px solid var(--primary);
}
}

.selector {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 999;

&-content {
.list {
max-height: 90vh;
overflow-x: hidden;
overflow-y: auto;

.list-item {
cursor: pointer;
background-color: var(--white);

&:hover {
filter: brightness(0.95);
}

&:active {
filter: brightness(0.9);
}
}
}
}
}
Loading