Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHuSh authored Nov 21, 2024
2 parents 3f1ee64 + 3a3e23d commit fae3b35
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 5 deletions.
6 changes: 6 additions & 0 deletions web/src/assets/svg/template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/components/editable-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const EditableCell: React.FC<EditableCellProps> = ({
if (editable) {
childNode = editing ? (
<Form.Item
style={{ margin: 0, width: 70 }}
style={{ margin: 0, minWidth: 70 }}
name={dataIndex}
rules={[
{
Expand Down
7 changes: 5 additions & 2 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export default {
'Conduct a retrieval test to check if RAGFlow can recover the intended content for the LLM.',
similarityThreshold: 'Similarity threshold',
similarityThresholdTip:
"RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This parameter sets the threshold for similarities between the user query and chunks. Any chunk with a similarity score below this threshold will be excluded from the results.",
'RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This parameter sets the threshold for similarities between the user query and chunks. Any chunk with a similarity score below this threshold will be excluded from the results.',
vectorSimilarityWeight: 'Keywords similarity weight',
vectorSimilarityWeightTip:
"This sets the weight of keyword similarity in the combined similarity score, either used with vector cosine similarity or with reranking score. The total of the two weights must equal 1.0.",
'This sets the weight of keyword similarity in the combined similarity score, either used with vector cosine similarity or with reranking score. The total of the two weights must equal 1.0.',
testText: 'Test text',
testTextPlaceholder: 'Input your question here!',
testingLabel: 'Testing',
Expand Down Expand Up @@ -1037,6 +1037,9 @@ The above is the content you need to summarize.`,
optional: 'Optional',
pasteFileLink: 'Paste file link',
testRun: 'Test Run',
template: 'Template',
templateDescription:
'This component is used for typesetting the outputs of various components.',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ export default {
optional: '可選項',
pasteFileLink: '貼上文件連結',
testRun: '試運行',
template: '模板轉換',
templateDescription: '此元件用於排版各種元件的輸出。 ',
},
footer: {
profile: '“保留所有權利 @ react”',
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,8 @@ export default {
optional: '可选项',
pasteFileLink: '粘贴文件链接',
testRun: '试运行',
template: '模板转换',
templateDescription: '该组件用于排版各种组件的输出。',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/chat/chat-id-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ChatIdModal = ({
{id}
</Paragraph>
<Link
href="https://ragflow.io/docs/dev/http_api_reference#create-session"
href="https://ragflow.io/docs/dev/http_api_reference#create-session-with-chat-assistant"
target="_blank"
>
{t('howUseId')}
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/flow/canvas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { RelevantNode } from './node/relevant-node';
import { RetrievalNode } from './node/retrieval-node';
import { RewriteNode } from './node/rewrite-node';
import { SwitchNode } from './node/switch-node';
import { TemplateNode } from './node/template-node';

const nodeTypes = {
ragNode: RagNode,
Expand All @@ -50,6 +51,7 @@ const nodeTypes = {
rewriteNode: RewriteNode,
keywordNode: KeywordNode,
invokeNode: InvokeNode,
templateNode: TemplateNode,
};

const edgeTypes = {
Expand Down
68 changes: 68 additions & 0 deletions web/src/pages/flow/canvas/node/template-node.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Flex } from 'antd';
import classNames from 'classnames';
import { get } from 'lodash';
import { Handle, NodeProps, Position } from 'reactflow';
import { useGetComponentLabelByValue } from '../../hooks';
import { IGenerateParameter, NodeData } from '../../interface';
import { LeftHandleStyle, RightHandleStyle } from './handle-icon';
import NodeHeader from './node-header';

import styles from './index.less';

export function TemplateNode({
id,
data,
isConnectable = true,
selected,
}: NodeProps<NodeData>) {
const parameters: IGenerateParameter[] = get(data, 'form.parameters', []);
const getLabel = useGetComponentLabelByValue(id);

return (
<section
className={classNames(styles.logicNode, {
[styles.selectedNode]: selected,
})}
>
<Handle
id="c"
type="source"
position={Position.Left}
isConnectable={isConnectable}
className={styles.handle}
style={LeftHandleStyle}
></Handle>
<Handle
type="source"
position={Position.Right}
isConnectable={isConnectable}
className={styles.handle}
style={RightHandleStyle}
id="b"
></Handle>

<NodeHeader
id={id}
name={data.name}
label={data.label}
className={styles.nodeHeader}
></NodeHeader>

<Flex gap={8} vertical className={styles.generateParameters}>
{parameters.map((x) => (
<Flex
key={x.id}
align="center"
gap={6}
className={styles.conditionBlock}
>
<label htmlFor="">{x.key}</label>
<span className={styles.parameterValue}>
{getLabel(x.component_id)}
</span>
</Flex>
))}
</Flex>
</section>
);
}
16 changes: 16 additions & 0 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ReactComponent as NoteIcon } from '@/assets/svg/note.svg';
import { ReactComponent as PubMedIcon } from '@/assets/svg/pubmed.svg';
import { ReactComponent as QWeatherIcon } from '@/assets/svg/qweather.svg';
import { ReactComponent as SwitchIcon } from '@/assets/svg/switch.svg';
import { ReactComponent as TemplateIcon } from '@/assets/svg/template.svg';
import { ReactComponent as TuShareIcon } from '@/assets/svg/tushare.svg';
import { ReactComponent as WenCaiIcon } from '@/assets/svg/wencai.svg';
import { ReactComponent as WikipediaIcon } from '@/assets/svg/wikipedia.svg';
Expand Down Expand Up @@ -85,6 +86,7 @@ export enum Operator {
Note = 'Note',
Crawler = 'Crawler',
Invoke = 'Invoke',
Template = 'Template',
}

export const CommonOperatorList = Object.values(Operator).filter(
Expand Down Expand Up @@ -124,6 +126,7 @@ export const operatorIconMap = {
[Operator.Note]: NoteIcon,
[Operator.Crawler]: CrawlerIcon,
[Operator.Invoke]: InvokeIcon,
[Operator.Template]: TemplateIcon,
};

export const operatorMap: Record<
Expand Down Expand Up @@ -253,6 +256,9 @@ export const operatorMap: Record<
[Operator.Invoke]: {
backgroundColor: '#dee0e2',
},
[Operator.Template]: {
backgroundColor: '#dee0e2',
},
};

export const componentMenuList = [
Expand Down Expand Up @@ -286,6 +292,9 @@ export const componentMenuList = [
{
name: Operator.Concentrator,
},
{
name: Operator.Template,
},
{
name: Operator.Note,
},
Expand Down Expand Up @@ -566,6 +575,11 @@ export const initialInvokeValues = {
clean_html: false,
};

export const initialTemplateValues = {
content: '',
parameters: [],
};

export const CategorizeAnchorPointPositions = [
{ top: 1, right: 34 },
{ top: 8, right: 18 },
Expand Down Expand Up @@ -645,6 +659,7 @@ export const RestrictedUpstreamMap = {
[Operator.Crawler]: [Operator.Begin],
[Operator.Note]: [],
[Operator.Invoke]: [Operator.Begin],
[Operator.Template]: [Operator.Begin, Operator.Relevant],
};

export const NodeMap = {
Expand Down Expand Up @@ -680,6 +695,7 @@ export const NodeMap = {
[Operator.Note]: 'noteNode',
[Operator.Crawler]: 'ragNode',
[Operator.Invoke]: 'invokeNode',
[Operator.Template]: 'templateNode',
};

export const LanguageOptions = [
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/flow/flow-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import OperatorIcon from '../operator-icon';

import { CloseOutlined } from '@ant-design/icons';
import { lowerFirst } from 'lodash';
import TemplateForm from '../form/template-form';
import { getDrawerWidth } from '../utils';
import styles from './index.less';

Expand Down Expand Up @@ -79,6 +80,7 @@ const FormMap = {
[Operator.Invoke]: InvokeForm,
[Operator.Concentrator]: () => <></>,
[Operator.Note]: () => <></>,
[Operator.Template]: TemplateForm,
};

const EmptyContent = () => <div></div>;
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/flow/flow-id-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const FlowIdModal = ({ hideModal }: IModalProps<any>) => {
{id}
</Paragraph>
<Link
href="https://ragflow.io/docs/dev/http_api_reference#create-agent-session"
href="https://ragflow.io/docs/dev/http_api_reference#create-session-with-an-agent"
target="_blank"
>
{t('howUseId')}
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/flow/form/generate-form/dynamic-parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const DynamicParameters = ({ nodeId }: IProps) => {
title: t('key'),
dataIndex: 'key',
key: 'key',
width: '40%',
onCell: (record: IGenerateParameter) => ({
record,
editable: true,
Expand All @@ -49,6 +50,7 @@ const DynamicParameters = ({ nodeId }: IProps) => {
dataIndex: 'component_id',
key: 'component_id',
align: 'center',
width: '40%',
render(text, record) {
return (
<Select
Expand Down
26 changes: 26 additions & 0 deletions web/src/pages/flow/form/template-form/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Form, Input } from 'antd';
import { useTranslation } from 'react-i18next';
import { IOperatorForm } from '../../interface';
import DynamicParameters from '../generate-form/dynamic-parameters';

const TemplateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslation();

return (
<Form
name="basic"
autoComplete="off"
form={form}
onValuesChange={onValuesChange}
layout={'vertical'}
>
<Form.Item name={['content']} label={t('flow.content')}>
<Input.TextArea rows={8} placeholder={t('flow.blank')} />
</Form.Item>

<DynamicParameters nodeId={node?.id}></DynamicParameters>
</Form>
);
};

export default TemplateForm;
2 changes: 2 additions & 0 deletions web/src/pages/flow/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
initialRetrievalValues,
initialRewriteQuestionValues,
initialSwitchValues,
initialTemplateValues,
initialTuShareValues,
initialWenCaiValues,
initialWikipediaValues,
Expand Down Expand Up @@ -139,6 +140,7 @@ export const useInitializeOperatorParams = () => {
[Operator.Note]: initialNoteValues,
[Operator.Crawler]: initialCrawlerValues,
[Operator.Invoke]: initialInvokeValues,
[Operator.Template]: initialTemplateValues,
};
}, [llmId]);

Expand Down

0 comments on commit fae3b35

Please sign in to comment.