|
|
|
|
|
|
|
|
web_reader: true, |
|
|
web_reader: true, |
|
|
wikipedia: true, |
|
|
wikipedia: true, |
|
|
} |
|
|
} |
|
|
|
|
|
const CONFIG_KEY = 'universal-chat-config' |
|
|
|
|
|
type CONFIG = { |
|
|
|
|
|
modelId: string |
|
|
|
|
|
plugin: { |
|
|
|
|
|
google_search: boolean |
|
|
|
|
|
web_reader: boolean |
|
|
|
|
|
wikipedia: boolean |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
let prevConfig: null | CONFIG = localStorage.getItem(CONFIG_KEY) ? JSON.parse(localStorage.getItem(CONFIG_KEY) as string) as CONFIG : null |
|
|
|
|
|
const setPrevConfig = (config: CONFIG) => { |
|
|
|
|
|
prevConfig = config |
|
|
|
|
|
localStorage.setItem(CONFIG_KEY, JSON.stringify(prevConfig)) |
|
|
|
|
|
} |
|
|
|
|
|
const getInitConfig = (type: 'model' | 'plugin') => { |
|
|
|
|
|
if (type === 'model') |
|
|
|
|
|
return prevConfig?.modelId || DEFAULT_MODEL_ID |
|
|
|
|
|
|
|
|
|
|
|
if (type === 'plugin') |
|
|
|
|
|
return prevConfig?.plugin || DEFAULT_PLUGIN |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export type IMainProps = {} |
|
|
export type IMainProps = {} |
|
|
|
|
|
|
|
|
const Main: FC<IMainProps> = () => { |
|
|
const Main: FC<IMainProps> = () => { |
|
|
|
|
|
|
|
|
const [errorHappened, setErrorHappened] = useState(false) |
|
|
const [errorHappened, setErrorHappened] = useState(false) |
|
|
const [isResponsingConIsCurrCon, setIsResponsingConCurrCon, getIsResponsingConIsCurrCon] = useGetState(true) |
|
|
const [isResponsingConIsCurrCon, setIsResponsingConCurrCon, getIsResponsingConIsCurrCon] = useGetState(true) |
|
|
const handleSend = async (message: string) => { |
|
|
const handleSend = async (message: string) => { |
|
|
|
|
|
if (isNewConversation) { |
|
|
|
|
|
setPrevConfig({ |
|
|
|
|
|
modelId, |
|
|
|
|
|
plugin: plugins as any, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (isResponsing) { |
|
|
if (isResponsing) { |
|
|
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') }) |
|
|
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') }) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const [modelId, setModeId] = useState(DEFAULT_MODEL_ID) |
|
|
|
|
|
|
|
|
const [modelId, setModeId] = useState<string>(getInitConfig('model') as string) |
|
|
// const currModel = MODEL_LIST.find(item => item.id === modelId) |
|
|
// const currModel = MODEL_LIST.find(item => item.id === modelId) |
|
|
|
|
|
|
|
|
const [plugins, setPlugins] = useState<Record<string, boolean>>(DEFAULT_PLUGIN) |
|
|
|
|
|
|
|
|
const [plugins, setPlugins] = useState<Record<string, boolean>>(getInitConfig('plugin') as Record<string, boolean>) |
|
|
const handlePluginsChange = (key: string, value: boolean) => { |
|
|
const handlePluginsChange = (key: string, value: boolean) => { |
|
|
setPlugins({ |
|
|
setPlugins({ |
|
|
...plugins, |
|
|
...plugins, |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
const [dataSets, setDateSets] = useState<DataSet[]>([]) |
|
|
const [dataSets, setDateSets] = useState<DataSet[]>([]) |
|
|
const configSetDefaultValue = () => { |
|
|
const configSetDefaultValue = () => { |
|
|
setModeId(DEFAULT_MODEL_ID) |
|
|
|
|
|
setPlugins(DEFAULT_PLUGIN) |
|
|
|
|
|
|
|
|
setModeId(getInitConfig('model') as string) |
|
|
|
|
|
setPlugins(getInitConfig('plugin') as any) |
|
|
setDateSets([]) |
|
|
setDateSets([]) |
|
|
} |
|
|
} |
|
|
const isCurrConversationPinned = !!pinnedConversationList.find(item => item.id === currConversationId) |
|
|
const isCurrConversationPinned = !!pinnedConversationList.find(item => item.id === currConversationId) |