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 bing form #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -102,6 +102,7 @@ function AccordionOperators() {
|
|||||||
Operator.TavilySearch,
|
Operator.TavilySearch,
|
||||||
Operator.Crawler,
|
Operator.Crawler,
|
||||||
Operator.ExeSQL,
|
Operator.ExeSQL,
|
||||||
|
Operator.Bing,
|
||||||
]}
|
]}
|
||||||
></OperatorItemList>
|
></OperatorItemList>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
|
|||||||
@ -516,7 +516,7 @@ export const initialBingValues = {
|
|||||||
'YOUR_API_KEY (obtained from https://www.microsoft.com/en-us/bing/apis/bing-web-search-api)',
|
'YOUR_API_KEY (obtained from https://www.microsoft.com/en-us/bing/apis/bing-web-search-api)',
|
||||||
country: 'CH',
|
country: 'CH',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
...initialQueryBaseValues,
|
query: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialGoogleScholarValues = {
|
export const initialGoogleScholarValues = {
|
||||||
|
|||||||
@ -1,12 +1,42 @@
|
|||||||
import TopNItem from '@/components/top-n-item';
|
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||||
|
import { TopNFormField } from '@/components/top-n-item';
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@/components/ui/form';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { Form, Input, Select } from 'antd';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useMemo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
import { IOperatorForm } from '../../interface';
|
import { useForm, useFormContext } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import { initialBingValues } from '../../constant';
|
||||||
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { BingCountryOptions, BingLanguageOptions } from '../../options';
|
import { BingCountryOptions, BingLanguageOptions } from '../../options';
|
||||||
import DynamicInputVariable from '../components/dynamic-input-variable';
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
|
import { QueryVariable } from '../components/query-variable';
|
||||||
|
|
||||||
const BingForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
export const BingFormSchema = {
|
||||||
|
channel: z.string(),
|
||||||
|
api_key: z.string(),
|
||||||
|
country: z.string(),
|
||||||
|
language: z.string(),
|
||||||
|
top_n: z.number(),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FormSchema = z.object({
|
||||||
|
query: z.string().optional(),
|
||||||
|
...BingFormSchema,
|
||||||
|
});
|
||||||
|
|
||||||
|
export function BingFormWidgets() {
|
||||||
|
const form = useFormContext();
|
||||||
const { t } = useTranslate('flow');
|
const { t } = useTranslate('flow');
|
||||||
|
|
||||||
const options = useMemo(() => {
|
const options = useMemo(() => {
|
||||||
@ -14,29 +44,88 @@ const BingForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<>
|
||||||
name="basic"
|
<TopNFormField></TopNFormField>
|
||||||
autoComplete="off"
|
<FormField
|
||||||
form={form}
|
control={form.control}
|
||||||
onValuesChange={onValuesChange}
|
name="channel"
|
||||||
layout={'vertical'}
|
render={({ field }) => (
|
||||||
>
|
<FormItem>
|
||||||
<DynamicInputVariable node={node}></DynamicInputVariable>
|
<FormLabel>{t('channel')}</FormLabel>
|
||||||
<TopNItem initialValue={10}></TopNItem>
|
<FormControl>
|
||||||
<Form.Item label={t('channel')} name={'channel'}>
|
<SelectWithSearch {...field} options={options}></SelectWithSearch>
|
||||||
<Select options={options}></Select>
|
</FormControl>
|
||||||
</Form.Item>
|
<FormMessage />
|
||||||
<Form.Item label={t('apiKey')} name={'api_key'}>
|
</FormItem>
|
||||||
<Input></Input>
|
)}
|
||||||
</Form.Item>
|
/>
|
||||||
<Form.Item label={t('country')} name={'country'}>
|
<FormField
|
||||||
<Select options={BingCountryOptions}></Select>
|
control={form.control}
|
||||||
</Form.Item>
|
name="api_key"
|
||||||
<Form.Item label={t('language')} name={'language'}>
|
render={({ field }) => (
|
||||||
<Select options={BingLanguageOptions}></Select>
|
<FormItem>
|
||||||
</Form.Item>
|
<FormLabel>{t('apiKey')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field}></Input>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="country"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('country')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch
|
||||||
|
{...field}
|
||||||
|
options={BingCountryOptions}
|
||||||
|
></SelectWithSearch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="language"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('language')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch
|
||||||
|
{...field}
|
||||||
|
options={BingLanguageOptions}
|
||||||
|
></SelectWithSearch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function BingForm({ node }: INextOperatorForm) {
|
||||||
|
const defaultValues = useFormValues(initialBingValues, node);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
defaultValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<QueryVariable></QueryVariable>
|
||||||
|
<BingFormWidgets></BingFormWidgets>
|
||||||
|
</FormWrapper>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default BingForm;
|
export default memo(BingForm);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import {
|
|||||||
import { Input, NumberInput } from '@/components/ui/input';
|
import { Input, NumberInput } 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 { memo } from 'react';
|
||||||
import { useForm, useFormContext } from 'react-hook-form';
|
import { useForm, useFormContext } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { initialExeSqlValues } from '../../constant';
|
import { initialExeSqlValues } from '../../constant';
|
||||||
@ -135,7 +136,7 @@ export function ExeSQLFormWidgets({ loading }: { loading: boolean }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExeSQLForm = ({ node }: INextOperatorForm) => {
|
function ExeSQLForm({ node }: INextOperatorForm) {
|
||||||
const defaultValues = useFormValues(initialExeSqlValues, node);
|
const defaultValues = useFormValues(initialExeSqlValues, node);
|
||||||
|
|
||||||
const { onSubmit, loading } = useSubmitForm();
|
const { onSubmit, loading } = useSubmitForm();
|
||||||
@ -155,6 +156,6 @@ const ExeSQLForm = ({ node }: INextOperatorForm) => {
|
|||||||
</FormWrapper>
|
</FormWrapper>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ExeSQLForm;
|
export default memo(ExeSQLForm);
|
||||||
|
|||||||
32
web/src/pages/agent/form/tool-form/bing-form/index.tsx
Normal file
32
web/src/pages/agent/form/tool-form/bing-form/index.tsx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { Form } from '@/components/ui/form';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { memo } from 'react';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import { BingFormSchema, BingFormWidgets } from '../../bing-form';
|
||||||
|
import { FormWrapper } from '../../components/form-wrapper';
|
||||||
|
import { useValues } from '../use-values';
|
||||||
|
import { useWatchFormChange } from '../use-watch-change';
|
||||||
|
|
||||||
|
export const FormSchema = z.object(BingFormSchema);
|
||||||
|
|
||||||
|
function BingForm() {
|
||||||
|
const defaultValues = useValues();
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
defaultValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<BingFormWidgets></BingFormWidgets>
|
||||||
|
</FormWrapper>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(BingForm);
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import { Operator } from '../../constant';
|
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 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';
|
||||||
@ -11,6 +10,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 BingForm from './bing-form';
|
||||||
import CrawlerForm from './crawler-form';
|
import CrawlerForm from './crawler-form';
|
||||||
import ExeSQLForm from './exesql-form';
|
import ExeSQLForm from './exesql-form';
|
||||||
import RetrievalForm from './retrieval-form';
|
import RetrievalForm from './retrieval-form';
|
||||||
|
|||||||
@ -22,6 +22,8 @@ export function useAgentToolInitialValues() {
|
|||||||
};
|
};
|
||||||
case Operator.ExeSQL:
|
case Operator.ExeSQL:
|
||||||
return omit(initialValues, 'query');
|
return omit(initialValues, 'query');
|
||||||
|
case Operator.Bing:
|
||||||
|
return omit(initialValues, 'query');
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return initialValues;
|
return initialValues;
|
||||||
|
|||||||
Reference in New Issue
Block a user