forked from XiaoMo/ChatGPT-Next-Web
fixup
This commit is contained in:
parent
7345639af3
commit
b23adf9d5d
app
api
components
store
@ -59,4 +59,4 @@ export async function POST(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const runtime = "experimental-edge";
|
export const runtime = "edge";
|
||||||
|
@ -19,3 +19,5 @@ export async function POST(req: NextRequest) {
|
|||||||
needCode: serverConfig.needCode,
|
needCode: serverConfig.needCode,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const runtime = "edge";
|
||||||
|
@ -17,7 +17,7 @@ async function makeRequest(req: NextRequest) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: 500,
|
status: 500,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,4 +30,4 @@ export async function GET(req: NextRequest) {
|
|||||||
return makeRequest(req);
|
return makeRequest(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const runtime = "experimental-edge";
|
export const runtime = "edge";
|
||||||
|
@ -29,7 +29,6 @@ import {
|
|||||||
createMessage,
|
createMessage,
|
||||||
useAccessStore,
|
useAccessStore,
|
||||||
Theme,
|
Theme,
|
||||||
ModelType,
|
|
||||||
useAppConfig,
|
useAppConfig,
|
||||||
ModelConfig,
|
ModelConfig,
|
||||||
DEFAULT_TOPIC,
|
DEFAULT_TOPIC,
|
||||||
@ -57,7 +56,8 @@ import { Input, List, ListItem, Modal, Popover, showModal } from "./ui-lib";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Path } from "../constant";
|
import { Path } from "../constant";
|
||||||
import { ModelConfigList } from "./model-config";
|
import { ModelConfigList } from "./model-config";
|
||||||
import { AvatarPicker } from "./emoji";
|
import { Avatar, AvatarPicker } from "./emoji";
|
||||||
|
|
||||||
const Markdown = dynamic(
|
const Markdown = dynamic(
|
||||||
async () => memo((await import("./markdown")).Markdown),
|
async () => memo((await import("./markdown")).Markdown),
|
||||||
{
|
{
|
||||||
@ -65,10 +65,6 @@ const Markdown = dynamic(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const Avatar = dynamic(async () => (await import("./emoji")).Avatar, {
|
|
||||||
loading: () => <LoadingIcon />,
|
|
||||||
});
|
|
||||||
|
|
||||||
function exportMessages(messages: Message[], topic: string) {
|
function exportMessages(messages: Message[], topic: string) {
|
||||||
const mdText =
|
const mdText =
|
||||||
`# ${topic}\n\n` +
|
`# ${topic}\n\n` +
|
||||||
@ -112,8 +108,6 @@ function ContextPrompts() {
|
|||||||
const session = chatStore.currentSession();
|
const session = chatStore.currentSession();
|
||||||
const context = session.context;
|
const context = session.context;
|
||||||
|
|
||||||
const [showPicker, setShowPicker] = useState(false);
|
|
||||||
|
|
||||||
const addContextPrompt = (prompt: Message) => {
|
const addContextPrompt = (prompt: Message) => {
|
||||||
chatStore.updateCurrentSession((session) => {
|
chatStore.updateCurrentSession((session) => {
|
||||||
session.context.push(prompt);
|
session.context.push(prompt);
|
||||||
@ -190,6 +184,48 @@ function ContextPrompts() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SessionConfigModel(props: { onClose: () => void }) {
|
||||||
|
const chatStore = useChatStore();
|
||||||
|
const session = chatStore.currentSession();
|
||||||
|
|
||||||
|
const [showPicker, setShowPicker] = useState(false);
|
||||||
|
|
||||||
|
const updateConfig = (updater: (config: ModelConfig) => void) => {
|
||||||
|
const config = { ...session.modelConfig };
|
||||||
|
updater(config);
|
||||||
|
chatStore.updateCurrentSession((session) => (session.modelConfig = config));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="modal-mask">
|
||||||
|
<Modal
|
||||||
|
title={Locale.Context.Edit}
|
||||||
|
onClose={() => props.onClose()}
|
||||||
|
actions={[
|
||||||
|
<IconButton
|
||||||
|
key="reset"
|
||||||
|
icon={<CopyIcon />}
|
||||||
|
bordered
|
||||||
|
text="重置预设"
|
||||||
|
onClick={() =>
|
||||||
|
confirm(Locale.Memory.ResetConfirm) && chatStore.resetSession()
|
||||||
|
}
|
||||||
|
/>,
|
||||||
|
<IconButton
|
||||||
|
key="copy"
|
||||||
|
icon={<CopyIcon />}
|
||||||
|
bordered
|
||||||
|
text="保存预设"
|
||||||
|
onClick={() => copyToClipboard(session.memoryPrompt)}
|
||||||
|
/>,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<ContextPrompts />
|
||||||
|
|
||||||
<List>
|
<List>
|
||||||
<ListItem title={"角色头像"}>
|
<ListItem title={"角色头像"}>
|
||||||
<Popover
|
<Popover
|
||||||
@ -225,58 +261,24 @@ function ContextPrompts() {
|
|||||||
}
|
}
|
||||||
></input>
|
></input>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
</List>
|
||||||
|
|
||||||
|
<List>
|
||||||
|
<ModelConfigList
|
||||||
|
modelConfig={session.modelConfig}
|
||||||
|
updateConfig={updateConfig}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{session.modelConfig.sendMemory ? (
|
||||||
<ListItem
|
<ListItem
|
||||||
title={`${Locale.Memory.Title} (${session.lastSummarizeIndex} of
|
title={`${Locale.Memory.Title} (${session.lastSummarizeIndex} of
|
||||||
${session.messages.length})`}
|
${session.messages.length})`}
|
||||||
subTitle={session.memoryPrompt || Locale.Memory.EmptyContent}
|
subTitle={session.memoryPrompt || Locale.Memory.EmptyContent}
|
||||||
></ListItem>
|
></ListItem>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</List>
|
</List>
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SessionConfigModel(props: { onClose: () => void }) {
|
|
||||||
const chatStore = useChatStore();
|
|
||||||
const config = useAppConfig();
|
|
||||||
const session = chatStore.currentSession();
|
|
||||||
const context = session.context;
|
|
||||||
|
|
||||||
const updateConfig = (updater: (config: ModelConfig) => void) => {
|
|
||||||
const config = { ...session.modelConfig };
|
|
||||||
updater(config);
|
|
||||||
chatStore.updateCurrentSession((session) => (session.modelConfig = config));
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="modal-mask">
|
|
||||||
<Modal
|
|
||||||
title={Locale.Context.Edit}
|
|
||||||
onClose={() => props.onClose()}
|
|
||||||
actions={[
|
|
||||||
<IconButton
|
|
||||||
key="reset"
|
|
||||||
icon={<CopyIcon />}
|
|
||||||
bordered
|
|
||||||
text="重置预设"
|
|
||||||
onClick={() =>
|
|
||||||
confirm(Locale.Memory.ResetConfirm) && chatStore.resetSession()
|
|
||||||
}
|
|
||||||
/>,
|
|
||||||
<IconButton
|
|
||||||
key="copy"
|
|
||||||
icon={<CopyIcon />}
|
|
||||||
bordered
|
|
||||||
text="保存预设"
|
|
||||||
onClick={() => copyToClipboard(session.memoryPrompt)}
|
|
||||||
/>,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<ContextPrompts />
|
|
||||||
|
|
||||||
<ModelConfigList
|
|
||||||
modelConfig={session.modelConfig}
|
|
||||||
updateConfig={updateConfig}
|
|
||||||
/>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -10,7 +10,7 @@ export function ModelConfigList(props: {
|
|||||||
updateConfig: (updater: (config: ModelConfig) => void) => void;
|
updateConfig: (updater: (config: ModelConfig) => void) => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<List>
|
<>
|
||||||
<ListItem title={Locale.Settings.Model}>
|
<ListItem title={Locale.Settings.Model}>
|
||||||
<select
|
<select
|
||||||
value={props.modelConfig.model}
|
value={props.modelConfig.model}
|
||||||
@ -136,6 +136,6 @@ export function ModelConfigList(props: {
|
|||||||
}
|
}
|
||||||
></input>
|
></input>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -486,6 +486,7 @@ export function Settings() {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
|
<List>
|
||||||
<ModelConfigList
|
<ModelConfigList
|
||||||
modelConfig={config.modelConfig}
|
modelConfig={config.modelConfig}
|
||||||
updateConfig={(upater) => {
|
updateConfig={(upater) => {
|
||||||
@ -494,6 +495,7 @@ export function Settings() {
|
|||||||
config.update((config) => (config.modelConfig = modelConfig));
|
config.update((config) => (config.modelConfig = modelConfig));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</List>
|
||||||
|
|
||||||
{shouldShowPromptModal && (
|
{shouldShowPromptModal && (
|
||||||
<UserPromptModal onClose={() => setShowPromptModal(false)} />
|
<UserPromptModal onClose={() => setShowPromptModal(false)} />
|
||||||
|
@ -11,7 +11,7 @@ import { isMobileScreen, trimTopic } from "../utils";
|
|||||||
|
|
||||||
import Locale from "../locales";
|
import Locale from "../locales";
|
||||||
import { showToast } from "../components/ui-lib";
|
import { showToast } from "../components/ui-lib";
|
||||||
import { ModelConfig, ModelType, useAppConfig } from "./config";
|
import { DEFAULT_CONFIG, ModelConfig, ModelType, useAppConfig } from "./config";
|
||||||
|
|
||||||
export type Message = ChatCompletionResponseMessage & {
|
export type Message = ChatCompletionResponseMessage & {
|
||||||
date: string;
|
date: string;
|
||||||
@ -326,7 +326,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
|
|
||||||
// long term memory
|
// long term memory
|
||||||
if (
|
if (
|
||||||
session.sendMemory &&
|
session.modelConfig.sendMemory &&
|
||||||
session.memoryPrompt &&
|
session.memoryPrompt &&
|
||||||
session.memoryPrompt.length > 0
|
session.memoryPrompt.length > 0
|
||||||
) {
|
) {
|
||||||
@ -432,7 +432,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
if (
|
if (
|
||||||
historyMsgLength >
|
historyMsgLength >
|
||||||
config.modelConfig.compressMessageLengthThreshold &&
|
config.modelConfig.compressMessageLengthThreshold &&
|
||||||
session.sendMemory
|
session.modelConfig.sendMemory
|
||||||
) {
|
) {
|
||||||
requestChatStream(
|
requestChatStream(
|
||||||
toBeSummarizedMsgs.concat({
|
toBeSummarizedMsgs.concat({
|
||||||
@ -481,7 +481,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: LOCAL_KEY,
|
name: LOCAL_KEY,
|
||||||
version: 1.2,
|
version: 2,
|
||||||
migrate(persistedState, version) {
|
migrate(persistedState, version) {
|
||||||
const state = persistedState as ChatStore;
|
const state = persistedState as ChatStore;
|
||||||
|
|
||||||
@ -489,8 +489,10 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
state.sessions.forEach((s) => (s.context = []));
|
state.sessions.forEach((s) => (s.context = []));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version < 1.2) {
|
if (version < 2) {
|
||||||
state.sessions.forEach((s) => (s.sendMemory = true));
|
state.sessions.forEach(
|
||||||
|
(s) => (s.modelConfig = { ...DEFAULT_CONFIG.modelConfig }),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -15,7 +15,7 @@ export enum Theme {
|
|||||||
Light = "light",
|
Light = "light",
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_CONFIG = {
|
export const DEFAULT_CONFIG = {
|
||||||
sendBotMessages: true as boolean,
|
sendBotMessages: true as boolean,
|
||||||
submitKey: SubmitKey.CtrlEnter as SubmitKey,
|
submitKey: SubmitKey.CtrlEnter as SubmitKey,
|
||||||
avatar: "1f603",
|
avatar: "1f603",
|
||||||
|
Loading…
Reference in New Issue
Block a user