-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…4587) ### What problem does this PR solve? Feat: Display the knowledge graph on the knowledge base page #4543 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
- Loading branch information
Showing
31 changed files
with
346 additions
and
133 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
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
120 changes: 120 additions & 0 deletions
120
web/src/components/parse-configuration/graph-rag-items.tsx
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,120 @@ | ||
import { useTranslate } from '@/hooks/common-hooks'; | ||
import { Divider, Form, Select, Switch } from 'antd'; | ||
import { upperFirst } from 'lodash'; | ||
import { useCallback, useMemo } from 'react'; | ||
import EntityTypesItem from '../entity-types-item'; | ||
|
||
const excludedTagParseMethods = ['table', 'knowledge_graph', 'tag']; | ||
|
||
export const showTagItems = (parserId: string) => { | ||
return !excludedTagParseMethods.includes(parserId); | ||
}; | ||
|
||
const enum MethodValue { | ||
General = 'general', | ||
Light = 'light', | ||
} | ||
|
||
export const excludedParseMethods = [ | ||
'table', | ||
'resume', | ||
'picture', | ||
'knowledge_graph', | ||
'qa', | ||
'tag', | ||
]; | ||
|
||
export const showGraphRagItems = (parserId: string) => { | ||
return !excludedParseMethods.includes(parserId); | ||
}; | ||
|
||
// The three types "table", "resume" and "one" do not display this configuration. | ||
const GraphRagItems = () => { | ||
const { t } = useTranslate('knowledgeConfiguration'); | ||
|
||
const methodOptions = useMemo(() => { | ||
return [MethodValue.Light, MethodValue.General].map((x) => ({ | ||
value: x, | ||
label: upperFirst(x), | ||
})); | ||
}, []); | ||
|
||
const renderWideTooltip = useCallback( | ||
(title: React.ReactNode | string) => { | ||
return { | ||
title: typeof title === 'string' ? t(title) : title, | ||
overlayInnerStyle: { width: '50vw' }, | ||
}; | ||
}, | ||
[t], | ||
); | ||
|
||
return ( | ||
<> | ||
<Divider></Divider> | ||
<Form.Item | ||
name={['parser_config', 'graphrag', 'use_graphrag']} | ||
label={t('useGraphRag')} | ||
initialValue={false} | ||
valuePropName="checked" | ||
tooltip={renderWideTooltip('useGraphRagTip')} | ||
> | ||
<Switch /> | ||
</Form.Item> | ||
<Form.Item | ||
shouldUpdate={(prevValues, curValues) => | ||
prevValues.parser_config.graphrag.use_graphrag !== | ||
curValues.parser_config.graphrag.use_graphrag | ||
} | ||
> | ||
{({ getFieldValue }) => { | ||
const useRaptor = getFieldValue([ | ||
'parser_config', | ||
'graphrag', | ||
'use_graphrag', | ||
]); | ||
|
||
return ( | ||
useRaptor && ( | ||
<> | ||
<EntityTypesItem | ||
field={['parser_config', 'graphrag', 'entity_types']} | ||
></EntityTypesItem> | ||
<Form.Item | ||
name={['parser_config', 'graphrag', 'method']} | ||
label={t('graphRagMethod')} | ||
tooltip={renderWideTooltip( | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: t('graphRagMethodTip'), | ||
}} | ||
></div>, | ||
)} | ||
initialValue={MethodValue.Light} | ||
> | ||
<Select options={methodOptions} /> | ||
</Form.Item> | ||
<Form.Item | ||
name={['parser_config', 'graphrag', 'resolution']} | ||
label={t('resolution')} | ||
tooltip={renderWideTooltip('resolutionTip')} | ||
> | ||
<Switch /> | ||
</Form.Item> | ||
<Form.Item | ||
name={['parser_config', 'graphrag', 'community']} | ||
label={t('community')} | ||
tooltip={renderWideTooltip('communityTip')} | ||
> | ||
<Switch /> | ||
</Form.Item> | ||
</> | ||
) | ||
); | ||
}} | ||
</Form.Item> | ||
</> | ||
); | ||
}; | ||
|
||
export default GraphRagItems; |
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,21 @@ | ||
import { Form, Switch } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
type IProps = { | ||
filedName: string[]; | ||
}; | ||
|
||
export function UseKnowledgeGraphItem({ filedName }: IProps) { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Form.Item | ||
label={t('chat.useKnowledgeGraph')} | ||
tooltip={t('chat.useKnowledgeGraphTip')} | ||
name={filedName} | ||
initialValue={false} | ||
> | ||
<Switch></Switch> | ||
</Form.Item> | ||
); | ||
} |
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.