forked from XiaoMo/ChatGPT-Next-Web
fixup
This commit is contained in:
parent
7345639af3
commit
b23adf9d5d
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
export const runtime = "edge";
|
||||
|
@ -17,7 +17,7 @@ async function makeRequest(req: NextRequest) {
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -30,4 +30,4 @@ export async function GET(req: NextRequest) {
|
||||
return makeRequest(req);
|
||||
}
|
||||
|
||||
export const runtime = "experimental-edge";
|
||||
export const runtime = "edge";
|
||||
|
@ -29,7 +29,6 @@ import {
|
||||
createMessage,
|
||||
useAccessStore,
|
||||
Theme,
|
||||
ModelType,
|
||||
useAppConfig,
|
||||
ModelConfig,
|
||||
DEFAULT_TOPIC,
|
||||
@ -57,7 +56,8 @@ import { Input, List, ListItem, Modal, Popover, showModal } from "./ui-lib";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Path } from "../constant";
|
||||
import { ModelConfigList } from "./model-config";
|
||||
import { AvatarPicker } from "./emoji";
|
||||
import { Avatar, AvatarPicker } from "./emoji";
|
||||
|
||||
const Markdown = dynamic(
|
||||
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) {
|
||||
const mdText =
|
||||
`# ${topic}\n\n` +
|
||||
@ -112,8 +108,6 @@ function ContextPrompts() {
|
||||
const session = chatStore.currentSession();
|
||||
const context = session.context;
|
||||
|
||||
const [showPicker, setShowPicker] = useState(false);
|
||||
|
||||
const addContextPrompt = (prompt: Message) => {
|
||||
chatStore.updateCurrentSession((session) => {
|
||||
session.context.push(prompt);
|
||||
@ -190,56 +184,15 @@ function ContextPrompts() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<List>
|
||||
<ListItem title={"角色头像"}>
|
||||
<Popover
|
||||
content={
|
||||
<AvatarPicker
|
||||
onEmojiClick={(emoji) =>
|
||||
chatStore.updateCurrentSession(
|
||||
(session) => (session.avatar = emoji),
|
||||
)
|
||||
}
|
||||
></AvatarPicker>
|
||||
}
|
||||
open={showPicker}
|
||||
onClose={() => setShowPicker(false)}
|
||||
>
|
||||
<div onClick={() => setShowPicker(true)}>
|
||||
{session.avatar ? (
|
||||
<Avatar avatar={session.avatar} />
|
||||
) : (
|
||||
<Avatar model={session.modelConfig.model} />
|
||||
)}
|
||||
</div>
|
||||
</Popover>
|
||||
</ListItem>
|
||||
<ListItem title={"对话标题"}>
|
||||
<input
|
||||
type="text"
|
||||
value={session.topic}
|
||||
onInput={(e) =>
|
||||
chatStore.updateCurrentSession(
|
||||
(session) => (session.topic = e.currentTarget.value),
|
||||
)
|
||||
}
|
||||
></input>
|
||||
</ListItem>
|
||||
<ListItem
|
||||
title={`${Locale.Memory.Title} (${session.lastSummarizeIndex} of
|
||||
${session.messages.length})`}
|
||||
subTitle={session.memoryPrompt || Locale.Memory.EmptyContent}
|
||||
></ListItem>
|
||||
</List>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function SessionConfigModel(props: { onClose: () => void }) {
|
||||
const chatStore = useChatStore();
|
||||
const config = useAppConfig();
|
||||
const session = chatStore.currentSession();
|
||||
const context = session.context;
|
||||
|
||||
const [showPicker, setShowPicker] = useState(false);
|
||||
|
||||
const updateConfig = (updater: (config: ModelConfig) => void) => {
|
||||
const config = { ...session.modelConfig };
|
||||
@ -273,10 +226,59 @@ export function SessionConfigModel(props: { onClose: () => void }) {
|
||||
>
|
||||
<ContextPrompts />
|
||||
|
||||
<ModelConfigList
|
||||
modelConfig={session.modelConfig}
|
||||
updateConfig={updateConfig}
|
||||
/>
|
||||
<List>
|
||||
<ListItem title={"角色头像"}>
|
||||
<Popover
|
||||
content={
|
||||
<AvatarPicker
|
||||
onEmojiClick={(emoji) =>
|
||||
chatStore.updateCurrentSession(
|
||||
(session) => (session.avatar = emoji),
|
||||
)
|
||||
}
|
||||
></AvatarPicker>
|
||||
}
|
||||
open={showPicker}
|
||||
onClose={() => setShowPicker(false)}
|
||||
>
|
||||
<div onClick={() => setShowPicker(true)}>
|
||||
{session.avatar ? (
|
||||
<Avatar avatar={session.avatar} />
|
||||
) : (
|
||||
<Avatar model={session.modelConfig.model} />
|
||||
)}
|
||||
</div>
|
||||
</Popover>
|
||||
</ListItem>
|
||||
<ListItem title={"对话标题"}>
|
||||
<input
|
||||
type="text"
|
||||
value={session.topic}
|
||||
onInput={(e) =>
|
||||
chatStore.updateCurrentSession(
|
||||
(session) => (session.topic = e.currentTarget.value),
|
||||
)
|
||||
}
|
||||
></input>
|
||||
</ListItem>
|
||||
</List>
|
||||
|
||||
<List>
|
||||
<ModelConfigList
|
||||
modelConfig={session.modelConfig}
|
||||
updateConfig={updateConfig}
|
||||
/>
|
||||
|
||||
{session.modelConfig.sendMemory ? (
|
||||
<ListItem
|
||||
title={`${Locale.Memory.Title} (${session.lastSummarizeIndex} of
|
||||
${session.messages.length})`}
|
||||
subTitle={session.memoryPrompt || Locale.Memory.EmptyContent}
|
||||
></ListItem>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</List>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
|
@ -10,7 +10,7 @@ export function ModelConfigList(props: {
|
||||
updateConfig: (updater: (config: ModelConfig) => void) => void;
|
||||
}) {
|
||||
return (
|
||||
<List>
|
||||
<>
|
||||
<ListItem title={Locale.Settings.Model}>
|
||||
<select
|
||||
value={props.modelConfig.model}
|
||||
@ -136,6 +136,6 @@ export function ModelConfigList(props: {
|
||||
}
|
||||
></input>
|
||||
</ListItem>
|
||||
</List>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -486,14 +486,16 @@ export function Settings() {
|
||||
</ListItem>
|
||||
</List>
|
||||
|
||||
<ModelConfigList
|
||||
modelConfig={config.modelConfig}
|
||||
updateConfig={(upater) => {
|
||||
const modelConfig = { ...config.modelConfig };
|
||||
upater(modelConfig);
|
||||
config.update((config) => (config.modelConfig = modelConfig));
|
||||
}}
|
||||
/>
|
||||
<List>
|
||||
<ModelConfigList
|
||||
modelConfig={config.modelConfig}
|
||||
updateConfig={(upater) => {
|
||||
const modelConfig = { ...config.modelConfig };
|
||||
upater(modelConfig);
|
||||
config.update((config) => (config.modelConfig = modelConfig));
|
||||
}}
|
||||
/>
|
||||
</List>
|
||||
|
||||
{shouldShowPromptModal && (
|
||||
<UserPromptModal onClose={() => setShowPromptModal(false)} />
|
||||
|
@ -11,7 +11,7 @@ import { isMobileScreen, trimTopic } from "../utils";
|
||||
|
||||
import Locale from "../locales";
|
||||
import { showToast } from "../components/ui-lib";
|
||||
import { ModelConfig, ModelType, useAppConfig } from "./config";
|
||||
import { DEFAULT_CONFIG, ModelConfig, ModelType, useAppConfig } from "./config";
|
||||
|
||||
export type Message = ChatCompletionResponseMessage & {
|
||||
date: string;
|
||||
@ -326,7 +326,7 @@ export const useChatStore = create<ChatStore>()(
|
||||
|
||||
// long term memory
|
||||
if (
|
||||
session.sendMemory &&
|
||||
session.modelConfig.sendMemory &&
|
||||
session.memoryPrompt &&
|
||||
session.memoryPrompt.length > 0
|
||||
) {
|
||||
@ -432,7 +432,7 @@ export const useChatStore = create<ChatStore>()(
|
||||
if (
|
||||
historyMsgLength >
|
||||
config.modelConfig.compressMessageLengthThreshold &&
|
||||
session.sendMemory
|
||||
session.modelConfig.sendMemory
|
||||
) {
|
||||
requestChatStream(
|
||||
toBeSummarizedMsgs.concat({
|
||||
@ -481,7 +481,7 @@ export const useChatStore = create<ChatStore>()(
|
||||
}),
|
||||
{
|
||||
name: LOCAL_KEY,
|
||||
version: 1.2,
|
||||
version: 2,
|
||||
migrate(persistedState, version) {
|
||||
const state = persistedState as ChatStore;
|
||||
|
||||
@ -489,8 +489,10 @@ export const useChatStore = create<ChatStore>()(
|
||||
state.sessions.forEach((s) => (s.context = []));
|
||||
}
|
||||
|
||||
if (version < 1.2) {
|
||||
state.sessions.forEach((s) => (s.sendMemory = true));
|
||||
if (version < 2) {
|
||||
state.sessions.forEach(
|
||||
(s) => (s.modelConfig = { ...DEFAULT_CONFIG.modelConfig }),
|
||||
);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
@ -15,7 +15,7 @@ export enum Theme {
|
||||
Light = "light",
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG = {
|
||||
export const DEFAULT_CONFIG = {
|
||||
sendBotMessages: true as boolean,
|
||||
submitKey: SubmitKey.CtrlEnter as SubmitKey,
|
||||
avatar: "1f603",
|
||||
|
Loading…
Reference in New Issue
Block a user