-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update models, enhance extension
- Loading branch information
Showing
27 changed files
with
325 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions
105
src/components/Header/WebCopilotSettingsModal/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { useEffect, useState, forwardRef, useImperativeHandle } from 'react'; | ||
import { Dialog, Button, Textarea, Space } from 'tdesign-react'; | ||
import { getAllTextModels } from '@src/utils/models'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import ModelOption from '@src/components/ModelOption'; | ||
import { Select } from 'tdesign-react'; | ||
import { | ||
useLocalStorageAtom, | ||
useLocalStorageJSONAtom, | ||
} from '@src/store/storage'; | ||
import { LOCAL_STORAGE_KEY } from '@src/utils/types'; | ||
const allTextModels = getAllTextModels(); | ||
|
||
const WebCopilotSettings = forwardRef((props, ref) => { | ||
const { t } = useTranslation(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [selectedModels, setSelectedModels] = useState([]); | ||
const [prompt, setPrompt] = useState(''); | ||
const [activeModels, setActiveModels] = useLocalStorageJSONAtom( | ||
LOCAL_STORAGE_KEY.WORD_EXPLAINER_ACTIVE_MODELS | ||
); | ||
const [activePrompt, setActivePrompt] = useLocalStorageAtom( | ||
LOCAL_STORAGE_KEY.WORD_EXPLAINER_PROMPT | ||
); | ||
|
||
useImperativeHandle(ref, () => ({ | ||
open: () => setIsOpen(true), | ||
close: () => setIsOpen(false), | ||
})); | ||
|
||
useEffect(() => { | ||
setSelectedModels(activeModels); | ||
setPrompt(activePrompt); | ||
}, [activeModels, activePrompt]); | ||
|
||
const handleSave = () => { | ||
setActiveModels(selectedModels); | ||
setActivePrompt(prompt); | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
closeOnOverlayClick={false} | ||
visible={isOpen} | ||
onClose={() => setIsOpen(false)} | ||
header={t('webCopilot.settings')} | ||
footer={ | ||
<Space> | ||
<Button variant="outline" onClick={() => setIsOpen(false)}> | ||
{t('common.cancel')} | ||
</Button> | ||
<Button theme="primary" onClick={handleSave}> | ||
{t('common.confirm')} | ||
</Button> | ||
</Space> | ||
} | ||
> | ||
<div className="space-y-4"> | ||
<div> | ||
<div className="text-sm font-medium mb-2"> | ||
{t('webCopilot.selectModel')} | ||
</div> | ||
<Select | ||
className="!w-full" | ||
filterable | ||
filter={(value, option) => | ||
option['data-keywords'].includes(value.toLowerCase()) | ||
} | ||
value={selectedModels} | ||
placeholder="" | ||
multiple | ||
onChange={setSelectedModels} | ||
> | ||
{allTextModels.map(option => ( | ||
<Select.Option | ||
style={{ height: '60px' }} | ||
key={option.id} | ||
value={option.id} | ||
label={option.name} | ||
data-keywords={(option.id + option.keywords).toLowerCase()} | ||
> | ||
<ModelOption option={option} /> | ||
</Select.Option> | ||
))} | ||
</Select> | ||
</div> | ||
|
||
<div> | ||
<div className="text-sm font-medium mb-2"> | ||
{t('webCopilot.prompt')} | ||
</div> | ||
<Textarea | ||
value={prompt} | ||
onChange={value => setPrompt(value)} | ||
autosize={{ minRows: 4, maxRows: 8 }} | ||
/> | ||
</div> | ||
</div> | ||
</Dialog> | ||
); | ||
}); | ||
|
||
export default WebCopilotSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.