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 20, 2024
2 parents aaf7af1 + f7fb18f commit e8427aa
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 116 deletions.
5 changes: 3 additions & 2 deletions api/ragflow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# limitations under the License.
#

from beartype.claw import beartype_packages
beartype_packages(["agent", "api", "deepdoc", "plugins", "rag", "ragflow_sdk"]) # <-- raise exceptions in your code
# from beartype import BeartypeConf
# from beartype.claw import beartype_all # <-- you didn't sign up for this
# beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code

import logging
from api.utils.log_utils import initRootLogger
Expand Down
7 changes: 4 additions & 3 deletions rag/svr/task_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from beartype.claw import beartype_packages
beartype_packages(["agent", "api", "deepdoc", "plugins", "rag", "ragflow_sdk"]) # <-- raise exceptions in your code

# from beartype import BeartypeConf
# from beartype.claw import beartype_all # <-- you didn't sign up for this
# beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code

import logging
import sys
Expand Down
3 changes: 0 additions & 3 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
import upperFirst from 'lodash/upperFirst';
import {
CloudUpload,
Link2,
ListOrdered,
OptionIcon,
TextCursorInput,
Expand Down Expand Up @@ -2876,7 +2875,6 @@ export enum BeginQueryType {
File = 'file',
Integer = 'integer',
Boolean = 'boolean',
Url = 'url',
}

export const BeginQueryTypeIconMap = {
Expand All @@ -2886,5 +2884,4 @@ export const BeginQueryTypeIconMap = {
[BeginQueryType.File]: CloudUpload,
[BeginQueryType.Integer]: ListOrdered,
[BeginQueryType.Boolean]: ToggleLeft,
[BeginQueryType.Url]: Link2,
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const DynamicParameters = ({ nodeId }: IProps) => {
title: t('key'),
dataIndex: 'key',
key: 'key',
width: 50,
onCell: (record: IGenerateParameter) => ({
record,
editable: true,
Expand Down
157 changes: 50 additions & 107 deletions web/src/pages/flow/run-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { useHandleSubmittable } from '@/hooks/login-hooks';
import { IModalProps } from '@/interfaces/common';
import api from '@/utils/api';
import { getAuthorization } from '@/utils/authorization-util';
import { InboxOutlined } from '@ant-design/icons';
import { UploadOutlined } from '@ant-design/icons';
import {
Button,
Drawer,
Flex,
Form,
FormItemProps,
Input,
Expand All @@ -19,7 +18,6 @@ import {
Upload,
} from 'antd';
import { pick } from 'lodash';
import { Link2, Trash2 } from 'lucide-react';
import React, { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { BeginQueryType } from '../constant';
Expand All @@ -33,6 +31,7 @@ import { getDrawerWidth } from '../utils';
import { PopoverForm } from './popover-form';

import { UploadChangeParam, UploadFile } from 'antd/es/upload';
import { Link } from 'lucide-react';
import styles from './index.less';

const RunDrawer = ({
Expand Down Expand Up @@ -60,18 +59,6 @@ const RunDrawer = ({
[setRecord, showPopover],
);

const handleRemoveUrl = useCallback(
(key: number, index: number) => () => {
const list: any[] = form.getFieldValue(key);

form.setFieldValue(
key,
list.filter((_, idx) => idx !== index),
);
},
[form],
);

const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
const query: BeginQuery[] = getBeginNodeDataQuery();

Expand Down Expand Up @@ -126,27 +113,47 @@ const RunDrawer = ({
</Form.Item>
),
[BeginQueryType.File]: (
<Form.Item
{...props}
valuePropName="fileList"
getValueFromEvent={normFile}
>
<Upload.Dragger
name="file"
action={api.parse}
multiple
headers={{ [Authorization]: getAuthorization() }}
onChange={onChange(q.optional)}
>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">{t('fileManager.uploadTitle')}</p>
<p className="ant-upload-hint">
{t('fileManager.uploadDescription')}
</p>
</Upload.Dragger>
</Form.Item>
<React.Fragment key={idx}>
<Form.Item label={q.name} required={!q.optional}>
<div className="relative">
<Form.Item
{...props}
valuePropName="fileList"
getValueFromEvent={normFile}
noStyle
>
<Upload
name="file"
action={api.parse}
multiple
headers={{ [Authorization]: getAuthorization() }}
onChange={onChange(q.optional)}
>
<Button icon={<UploadOutlined />}>
{t('common.upload')}
</Button>
</Upload>
</Form.Item>
<Form.Item
{...pick(props, ['key', 'label', 'rules'])}
required={!q.optional}
className={urlList.length > 0 ? 'mb-1' : ''}
noStyle
>
<PopoverForm visible={visible} switchVisible={switchVisible}>
<Button
onClick={handleShowPopover(idx)}
className="absolute left-1/2 top-0"
icon={<Link className="size-3" />}
>
{t('flow.pasteFileLink')}
</Button>
</PopoverForm>
</Form.Item>
</div>
</Form.Item>
<Form.Item name={idx} noStyle {...pick(props, ['rules'])} />
</React.Fragment>
),
[BeginQueryType.Integer]: (
<Form.Item {...props}>
Expand All @@ -158,66 +165,11 @@ const RunDrawer = ({
<Switch></Switch>
</Form.Item>
),
[BeginQueryType.Url]: (
<React.Fragment key={idx}>
<Form.Item
{...pick(props, ['key', 'label', 'rules'])}
required={!q.optional}
className={urlList.length > 0 ? 'mb-1' : ''}
>
<PopoverForm visible={visible} switchVisible={switchVisible}>
<Button
onClick={handleShowPopover(idx)}
className="text-buttonBlueText"
>
{t('flow.pasteFileLink')}
</Button>
</PopoverForm>
</Form.Item>
<Form.Item name={idx} noStyle {...pick(props, ['rules'])} />
<Form.Item
noStyle
shouldUpdate={(prevValues, curValues) =>
prevValues[idx] !== curValues[idx]
}
>
{({ getFieldValue }) => {
const urlInfo: { url: string; result: string }[] =
getFieldValue(idx) || [];
return urlInfo.length ? (
<Flex vertical gap={8} className="mb-3">
{urlInfo.map((u, index) => (
<div
key={index}
className="flex items-center justify-between gap-2 hover:bg-slate-100 group"
>
<Link2 className="size-5"></Link2>
<span className="flex-1 truncate"> {u.url}</span>
<Trash2
className="size-4 invisible group-hover:visible cursor-pointer"
onClick={handleRemoveUrl(idx, index)}
/>
</div>
))}
</Flex>
) : null;
}}
</Form.Item>
</React.Fragment>
),
};

return BeginQueryTypeMap[q.type as BeginQueryType];
},
[
form,
handleRemoveUrl,
handleShowPopover,
onChange,
switchVisible,
t,
visible,
],
[form, handleShowPopover, onChange, switchVisible, t, visible],
);

const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatModal!);
Expand All @@ -239,20 +191,11 @@ const RunDrawer = ({
if (Array.isArray(value)) {
nextValue = ``;

value.forEach((x, idx) => {
if (x?.originFileObj instanceof File) {
if (idx === 0) {
nextValue += `${x.name}\n\n${x.response?.data}\n\n`;
} else {
nextValue += `${x.response?.data}\n\n`;
}
} else {
if (idx === 0) {
nextValue += `${x.url}\n\n${x.result}\n\n`;
} else {
nextValue += `${x.result}\n\n`;
}
}
value.forEach((x) => {
nextValue +=
x?.originFileObj instanceof File
? `${x.name}\n${x.response?.data}\n----\n`
: `${x.url}\n${x.result}\n----\n`;
});
}
return { ...item, value: nextValue };
Expand All @@ -277,7 +220,7 @@ const RunDrawer = ({
const { basicForm } = forms;
const urlInfo = basicForm.getFieldValue(currentRecord) || [];
basicForm.setFieldsValue({
[currentRecord]: [...urlInfo, values],
[currentRecord]: [...urlInfo, { ...values, name: values.url }],
});
hidePopover();
}
Expand Down

0 comments on commit e8427aa

Please sign in to comment.