diff --git a/app/api/chat-stream/route.ts b/app/api/chat-stream/route.ts index 22550e39c..2775ff068 100644 --- a/app/api/chat-stream/route.ts +++ b/app/api/chat-stream/route.ts @@ -59,4 +59,4 @@ export async function POST(req: NextRequest) { } } -export const runtime = "experimental-edge"; +export const runtime = "edge"; diff --git a/app/api/config/route.ts b/app/api/config/route.ts index e04e22a0c..65290a476 100644 --- a/app/api/config/route.ts +++ b/app/api/config/route.ts @@ -19,3 +19,5 @@ export async function POST(req: NextRequest) { needCode: serverConfig.needCode, }); } + +export const runtime = "edge"; diff --git a/app/api/openai/route.ts b/app/api/openai/route.ts index bed70d928..d49027c61 100644 --- a/app/api/openai/route.ts +++ b/app/api/openai/route.ts @@ -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"; diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 867fbc494..a35295272 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -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: () => , -}); - 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() { /> - - - - chatStore.updateCurrentSession( - (session) => (session.avatar = emoji), - ) - } - > - } - open={showPicker} - onClose={() => setShowPicker(false)} - > - setShowPicker(true)}> - {session.avatar ? ( - - ) : ( - - )} - - - - - - chatStore.updateCurrentSession( - (session) => (session.topic = e.currentTarget.value), - ) - } - > - - - > ); } 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 }) { > - + + + + chatStore.updateCurrentSession( + (session) => (session.avatar = emoji), + ) + } + > + } + open={showPicker} + onClose={() => setShowPicker(false)} + > + setShowPicker(true)}> + {session.avatar ? ( + + ) : ( + + )} + + + + + + chatStore.updateCurrentSession( + (session) => (session.topic = e.currentTarget.value), + ) + } + > + + + + + + + {session.modelConfig.sendMemory ? ( + + ) : ( + <>> + )} + ); diff --git a/app/components/model-config.tsx b/app/components/model-config.tsx index 2b6d59f53..112e6b2e6 100644 --- a/app/components/model-config.tsx +++ b/app/components/model-config.tsx @@ -10,7 +10,7 @@ export function ModelConfigList(props: { updateConfig: (updater: (config: ModelConfig) => void) => void; }) { return ( - + <> - + > ); } diff --git a/app/components/settings.tsx b/app/components/settings.tsx index ffe540a9e..f396ed327 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -486,14 +486,16 @@ export function Settings() { - { - const modelConfig = { ...config.modelConfig }; - upater(modelConfig); - config.update((config) => (config.modelConfig = modelConfig)); - }} - /> + + { + const modelConfig = { ...config.modelConfig }; + upater(modelConfig); + config.update((config) => (config.modelConfig = modelConfig)); + }} + /> + {shouldShowPromptModal && ( setShowPromptModal(false)} /> diff --git a/app/store/chat.ts b/app/store/chat.ts index fcea406b8..4692a5a4c 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -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()( // long term memory if ( - session.sendMemory && + session.modelConfig.sendMemory && session.memoryPrompt && session.memoryPrompt.length > 0 ) { @@ -432,7 +432,7 @@ export const useChatStore = create()( if ( historyMsgLength > config.modelConfig.compressMessageLengthThreshold && - session.sendMemory + session.modelConfig.sendMemory ) { requestChatStream( toBeSummarizedMsgs.concat({ @@ -481,7 +481,7 @@ export const useChatStore = create()( }), { name: LOCAL_KEY, - version: 1.2, + version: 2, migrate(persistedState, version) { const state = persistedState as ChatStore; @@ -489,8 +489,10 @@ export const useChatStore = create()( 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; diff --git a/app/store/config.ts b/app/store/config.ts index 1e604607f..05d3383d9 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -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",