Commit 516036cc authored by StyleZhang's avatar StyleZhang

Merge branch 'main' into feat/refact-common-layout

parents c70168bb c6ab7eeb
CONVERSATION_TITLE_PROMPT = ( CONVERSATION_TITLE_PROMPT = (
"Human:{query}\n-----\n" "Human:{query}\n-----\n"
"Help me summarize the intent of what the human said and provide a title, the title should not exceed 20 words.\n" "Help me summarize the intent of what the human said and provide a title, the title should not exceed 20 words.\n"
"If the human said is conducted in Chinese, you should return a Chinese title.\n" "If what the human said is conducted in English, you should only return an English title.\n"
"If the human said is conducted in English, you should return an English title.\n" "If what the human said is conducted in Chinese, you should only return a Chinese title.\n"
"title:" "title:"
) )
CONVERSATION_SUMMARY_PROMPT = ( CONVERSATION_SUMMARY_PROMPT = (
"Please generate a short summary of the following conversation.\n" "Please generate a short summary of the following conversation.\n"
"If the conversation communicating in Chinese, you should return a Chinese summary.\n" "If the following conversation communicating in English, you should only return an English summary.\n"
"If the conversation communicating in English, you should return an English summary.\n" "If the following conversation communicating in Chinese, you should only return a Chinese summary.\n"
"[Conversation Start]\n" "[Conversation Start]\n"
"{context}\n" "{context}\n"
"[Conversation End]\n\n" "[Conversation End]\n\n"
......
...@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next' ...@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'
import { useContext } from 'use-context-selector' import { useContext } from 'use-context-selector'
import { useBoolean } from 'ahooks' import { useBoolean } from 'ahooks'
import { isEqual } from 'lodash-es' import { isEqual } from 'lodash-es'
import produce from 'immer'
import FeaturePanel from '../base/feature-panel' import FeaturePanel from '../base/feature-panel'
import OperationBtn from '../base/operation-btn' import OperationBtn from '../base/operation-btn'
import CardItem from './card-item' import CardItem from './card-item'
...@@ -31,11 +32,27 @@ const DatasetConfig: FC = () => { ...@@ -31,11 +32,27 @@ const DatasetConfig: FC = () => {
const hasData = dataSet.length > 0 const hasData = dataSet.length > 0
const [isShowSelectDataSet, { setTrue: showSelectDataSet, setFalse: hideSelectDataSet }] = useBoolean(false) const [isShowSelectDataSet, { setTrue: showSelectDataSet, setFalse: hideSelectDataSet }] = useBoolean(false)
const handleSelect = (data: DataSet[]) => { const handleSelect = (data: DataSet[]) => {
if (isEqual(data, dataSet)) if (isEqual(data.map(item => item.id), dataSet.map(item => item.id))) {
hideSelectDataSet() hideSelectDataSet()
return
}
setFormattingChanged(true) setFormattingChanged(true)
if (data.find(item => !item.name)) { // has not loaded selected dataset
const newSelected = produce(data, (draft) => {
data.forEach((item, index) => {
if (!item.name) { // not fetched database
const newItem = dataSet.find(i => i.id === item.id)
if (newItem)
draft[index] = newItem
}
})
})
setDataSet(newSelected)
}
else {
setDataSet(data) setDataSet(data)
}
hideSelectDataSet() hideSelectDataSet()
} }
const onRemove = (id: string) => { const onRemove = (id: string) => {
......
...@@ -5,6 +5,7 @@ import { useGetState, useInfiniteScroll } from 'ahooks' ...@@ -5,6 +5,7 @@ import { useGetState, useInfiniteScroll } from 'ahooks'
import cn from 'classnames' import cn from 'classnames'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import Link from 'next/link' import Link from 'next/link'
import produce from 'immer'
import TypeIcon from '../type-icon' import TypeIcon from '../type-icon'
import s from './style.module.css' import s from './style.module.css'
import Modal from '@/app/components/base/modal' import Modal from '@/app/components/base/modal'
...@@ -28,7 +29,7 @@ const SelectDataSet: FC<ISelectDataSetProps> = ({ ...@@ -28,7 +29,7 @@ const SelectDataSet: FC<ISelectDataSetProps> = ({
onSelect, onSelect,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [selected, setSelected] = React.useState<DataSet[]>([]) const [selected, setSelected] = React.useState<DataSet[]>(selectedIds.map(id => ({ id }) as any))
const [loaded, setLoaded] = React.useState(false) const [loaded, setLoaded] = React.useState(false)
const [datasets, setDataSets] = React.useState<DataSet[] | null>(null) const [datasets, setDataSets] = React.useState<DataSet[] | null>(null)
const hasNoData = !datasets || datasets?.length === 0 const hasNoData = !datasets || datasets?.length === 0
...@@ -47,7 +48,19 @@ const SelectDataSet: FC<ISelectDataSetProps> = ({ ...@@ -47,7 +48,19 @@ const SelectDataSet: FC<ISelectDataSetProps> = ({
const newList = [...(datasets || []), ...data] const newList = [...(datasets || []), ...data]
setDataSets(newList) setDataSets(newList)
setLoaded(true) setLoaded(true)
setSelected(newList.filter(item => selectedIds.includes(item.id))) if (!selected.find(item => !item.name))
return { list: [] }
const newSelected = produce(selected, (draft) => {
selected.forEach((item, index) => {
if (!item.name) { // not fetched database
const newItem = newList.find(i => i.id === item.id)
if (newItem)
draft[index] = newItem
}
})
})
setSelected(newSelected)
} }
return { list: [] } return { list: [] }
}, },
......
...@@ -43,8 +43,8 @@ const ItemOperation: FC<IItemOperationProps> = ({ ...@@ -43,8 +43,8 @@ const ItemOperation: FC<IItemOperationProps> = ({
</div> </div>
{isShowDelete && ( {isShowDelete && (
<div className={cn(s.actionItem, s.deleteActionItem, 'hover:bg-gray-50 group')} onClick={onDelete} > <div className={cn(s.actionItem, s.deleteActionItem, 'hover:bg-gray-50 group')} onClick={onDelete} >
<TrashIcon className={'shrink-0 w-4 h-4 stroke-current text-gray-500 stroke-2 group-hover:text-red-500'} /> <TrashIcon className={cn(s.deleteActionItemChild, 'shrink-0 w-4 h-4 stroke-current text-gray-500 stroke-2')} />
<span className={cn(s.actionName, 'group-hover:text-red-500')}>{t('explore.sidebar.action.delete')}</span> <span className={cn(s.actionName, s.deleteActionItemChild)}>{t('explore.sidebar.action.delete')}</span>
</div> </div>
)} )}
......
...@@ -29,3 +29,7 @@ body .btn:hover { ...@@ -29,3 +29,7 @@ body .btn:hover {
/* background-image: ; */ /* background-image: ; */
background-color: #F2F4F7; background-color: #F2F4F7;
} }
.deleteActionItem:hover .deleteActionItemChild {
@apply text-red-500;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment