mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Add agent tool CrawlerForm #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -10,8 +10,8 @@ import {
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useMemo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm, useFormContext } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { initialCrawlerValues } from '../../constant';
|
import { initialCrawlerValues } from '../../constant';
|
||||||
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
@ -19,13 +19,65 @@ import { INextOperatorForm } from '../../interface';
|
|||||||
import { CrawlerResultOptions } from '../../options';
|
import { CrawlerResultOptions } from '../../options';
|
||||||
import { QueryVariable } from '../components/query-variable';
|
import { QueryVariable } from '../components/query-variable';
|
||||||
|
|
||||||
const FormSchema = z.object({
|
export function CrawlerProxyFormField() {
|
||||||
query: z.string().optional(),
|
const { t } = useTranslate('flow');
|
||||||
|
const form = useFormContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="proxy"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('proxy')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="like: http://127.0.0.1:8888" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CrawlerExtractTypeFormField() {
|
||||||
|
const { t } = useTranslate('flow');
|
||||||
|
const form = useFormContext();
|
||||||
|
const crawlerResultOptions = useMemo(() => {
|
||||||
|
return CrawlerResultOptions.map((x) => ({
|
||||||
|
value: x,
|
||||||
|
label: t(`crawlerResultOptions.${x}`),
|
||||||
|
}));
|
||||||
|
}, [t]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="extract_type"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('extractType')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch {...field} options={crawlerResultOptions} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CrawlerFormSchema = {
|
||||||
proxy: z.string().url(),
|
proxy: z.string().url(),
|
||||||
extract_type: z.string(),
|
extract_type: z.string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormSchema = z.object({
|
||||||
|
query: z.string().optional(),
|
||||||
|
...CrawlerFormSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
function CrawlerForm({ node }: INextOperatorForm) {
|
function CrawlerForm({ node }: INextOperatorForm) {
|
||||||
const { t } = useTranslate('flow');
|
|
||||||
const form = useForm<z.infer<typeof FormSchema>>({
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
defaultValues: initialCrawlerValues,
|
defaultValues: initialCrawlerValues,
|
||||||
@ -34,13 +86,6 @@ function CrawlerForm({ node }: INextOperatorForm) {
|
|||||||
|
|
||||||
useWatchFormChange(node?.id, form);
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
const crawlerResultOptions = useMemo(() => {
|
|
||||||
return CrawlerResultOptions.map((x) => ({
|
|
||||||
value: x,
|
|
||||||
label: t(`crawlerResultOptions.${x}`),
|
|
||||||
}));
|
|
||||||
}, [t]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
@ -50,35 +95,11 @@ function CrawlerForm({ node }: INextOperatorForm) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<QueryVariable></QueryVariable>
|
<QueryVariable></QueryVariable>
|
||||||
<FormField
|
<CrawlerProxyFormField></CrawlerProxyFormField>
|
||||||
control={form.control}
|
<CrawlerExtractTypeFormField></CrawlerExtractTypeFormField>
|
||||||
name="proxy"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>{t('proxy')}</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input placeholder="like: http://127.0.0.1:8888" {...field} />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="extract_type"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>{t('extractType')}</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<SelectWithSearch {...field} options={crawlerResultOptions} />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CrawlerForm;
|
export default memo(CrawlerForm);
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { Operator } from '../../constant';
|
|||||||
import AkShareForm from '../akshare-form';
|
import AkShareForm from '../akshare-form';
|
||||||
import ArXivForm from '../arxiv-form';
|
import ArXivForm from '../arxiv-form';
|
||||||
import BingForm from '../bing-form';
|
import BingForm from '../bing-form';
|
||||||
import CrawlerForm from '../crawler-form';
|
|
||||||
import DeepLForm from '../deepl-form';
|
import DeepLForm from '../deepl-form';
|
||||||
import DuckDuckGoForm from '../duckduckgo-form';
|
import DuckDuckGoForm from '../duckduckgo-form';
|
||||||
import EmailForm from '../email-form';
|
import EmailForm from '../email-form';
|
||||||
@ -13,6 +12,7 @@ import GoogleScholarForm from '../google-scholar-form';
|
|||||||
import PubMedForm from '../pubmed-form';
|
import PubMedForm from '../pubmed-form';
|
||||||
import WikipediaForm from '../wikipedia-form';
|
import WikipediaForm from '../wikipedia-form';
|
||||||
import YahooFinanceForm from '../yahoo-finance-form';
|
import YahooFinanceForm from '../yahoo-finance-form';
|
||||||
|
import CrawlerForm from './crawler-form';
|
||||||
import RetrievalForm from './retrieval-form';
|
import RetrievalForm from './retrieval-form';
|
||||||
import TavilyForm from './tavily-form';
|
import TavilyForm from './tavily-form';
|
||||||
|
|
||||||
|
|||||||
43
web/src/pages/agent/form/tool-form/crawler-form/index.tsx
Normal file
43
web/src/pages/agent/form/tool-form/crawler-form/index.tsx
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { Form } from '@/components/ui/form';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import {
|
||||||
|
CrawlerExtractTypeFormField,
|
||||||
|
CrawlerFormSchema,
|
||||||
|
CrawlerProxyFormField,
|
||||||
|
} from '../../crawler-form';
|
||||||
|
import { useValues } from '../use-values';
|
||||||
|
import { useWatchFormChange } from '../use-watch-change';
|
||||||
|
|
||||||
|
export const FormSchema = z.object({
|
||||||
|
...CrawlerFormSchema,
|
||||||
|
});
|
||||||
|
|
||||||
|
const CrawlerForm = () => {
|
||||||
|
const defaultValues = useValues();
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
defaultValues: defaultValues,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
mode: 'onChange',
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
className="space-y-6 p-4"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CrawlerProxyFormField></CrawlerProxyFormField>
|
||||||
|
<CrawlerExtractTypeFormField></CrawlerExtractTypeFormField>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CrawlerForm;
|
||||||
Reference in New Issue
Block a user