mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-03 10:26:52 +00:00
### What problem does this PR solve? Feat: Add Arxiv GoogleScholar operator #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
b9d3846bb4
commit
98c78073c7
@ -107,6 +107,8 @@ function AccordionOperators() {
|
|||||||
Operator.Email,
|
Operator.Email,
|
||||||
Operator.DuckDuckGo,
|
Operator.DuckDuckGo,
|
||||||
Operator.Wikipedia,
|
Operator.Wikipedia,
|
||||||
|
Operator.GoogleScholar,
|
||||||
|
Operator.ArXiv,
|
||||||
]}
|
]}
|
||||||
></OperatorItemList>
|
></OperatorItemList>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { IAgentForm, IToolNode } from '@/interfaces/database/agent';
|
import { IAgentForm, IToolNode } from '@/interfaces/database/agent';
|
||||||
import { Handle, NodeProps, Position } from '@xyflow/react';
|
import { Handle, NodeProps, Position } from '@xyflow/react';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { memo, useCallback } from 'react';
|
import { MouseEventHandler, memo, useCallback } from 'react';
|
||||||
import { NodeHandleId } from '../../constant';
|
import { NodeHandleId, Operator } from '../../constant';
|
||||||
import { ToolCard } from '../../form/agent-form/agent-tools';
|
import { ToolCard } from '../../form/agent-form/agent-tools';
|
||||||
import { useFindMcpById } from '../../hooks/use-find-mcp-by-id';
|
import { useFindMcpById } from '../../hooks/use-find-mcp-by-id';
|
||||||
import useGraphStore from '../../store';
|
import useGraphStore from '../../store';
|
||||||
@ -18,7 +18,16 @@ function InnerToolNode({
|
|||||||
const upstreamAgentNode = getNode(upstreamAgentNodeId);
|
const upstreamAgentNode = getNode(upstreamAgentNodeId);
|
||||||
const { findMcpById } = useFindMcpById();
|
const { findMcpById } = useFindMcpById();
|
||||||
|
|
||||||
const handleClick = useCallback(() => {}, []);
|
const handleClick = useCallback(
|
||||||
|
(operator: string): MouseEventHandler<HTMLLIElement> =>
|
||||||
|
(e) => {
|
||||||
|
if (operator === Operator.Code) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
const tools: IAgentForm['tools'] = get(
|
const tools: IAgentForm['tools'] = get(
|
||||||
upstreamAgentNode,
|
upstreamAgentNode,
|
||||||
@ -44,17 +53,18 @@ function InnerToolNode({
|
|||||||
{tools.map((x) => (
|
{tools.map((x) => (
|
||||||
<ToolCard
|
<ToolCard
|
||||||
key={x.component_name}
|
key={x.component_name}
|
||||||
onClick={handleClick}
|
onClick={handleClick(x.component_name)}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
data-tool={x.component_name}
|
data-tool={x.component_name}
|
||||||
>
|
>
|
||||||
{x.component_name}
|
{x.component_name}
|
||||||
</ToolCard>
|
</ToolCard>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{mcpList.map((x) => (
|
{mcpList.map((x) => (
|
||||||
<ToolCard
|
<ToolCard
|
||||||
key={x.mcp_id}
|
key={x.mcp_id}
|
||||||
onClick={handleClick}
|
onClick={handleClick(x.mcp_id)}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
data-tool={x.mcp_id}
|
data-tool={x.mcp_id}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -378,18 +378,23 @@ export const initialPubMedValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const initialArXivValues = {
|
export const initialArXivValues = {
|
||||||
top_n: 10,
|
top_n: 12,
|
||||||
sort_by: 'relevance',
|
sort_by: 'relevance',
|
||||||
...initialQueryBaseValues,
|
query: AgentGlobals.SysQuery,
|
||||||
|
outputs: {
|
||||||
|
formalized_content: {
|
||||||
|
value: '',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialGoogleValues = {
|
export const initialGoogleValues = {
|
||||||
q: AgentGlobals.SysQuery,
|
q: AgentGlobals.SysQuery,
|
||||||
start: 0,
|
start: 0,
|
||||||
num: 12,
|
num: 12,
|
||||||
top_n: 10,
|
|
||||||
api_key: '',
|
api_key: '',
|
||||||
country: 'cn',
|
country: 'us',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
outputs: {
|
outputs: {
|
||||||
formalized_content: {
|
formalized_content: {
|
||||||
@ -414,10 +419,22 @@ export const initialBingValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const initialGoogleScholarValues = {
|
export const initialGoogleScholarValues = {
|
||||||
top_n: 5,
|
top_n: 12,
|
||||||
sort_by: 'relevance',
|
sort_by: 'relevance',
|
||||||
patents: true,
|
patents: true,
|
||||||
...initialQueryBaseValues,
|
query: AgentGlobals.SysQuery,
|
||||||
|
year_low: undefined,
|
||||||
|
year_high: undefined,
|
||||||
|
outputs: {
|
||||||
|
formalized_content: {
|
||||||
|
value: '',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
value: [],
|
||||||
|
type: 'Array<Object>',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialDeepLValues = {
|
export const initialDeepLValues = {
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
import { BlockButton } from '@/components/ui/button';
|
import { BlockButton } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from '@/components/ui/tooltip';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { Position } from '@xyflow/react';
|
import { Position } from '@xyflow/react';
|
||||||
import { PencilLine, X } from 'lucide-react';
|
import { PencilLine, X } from 'lucide-react';
|
||||||
@ -25,6 +30,7 @@ export function ToolCard({
|
|||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: PropsWithChildren & React.HTMLAttributes<HTMLLIElement>) {
|
}: PropsWithChildren & React.HTMLAttributes<HTMLLIElement>) {
|
||||||
|
const element = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
{...props}
|
{...props}
|
||||||
@ -36,6 +42,20 @@ export function ToolCard({
|
|||||||
{children}
|
{children}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
}, [children, className, props]);
|
||||||
|
|
||||||
|
if (children === Operator.Code) {
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>{element}</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>It doesn't have any config.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionButtonProps<T> = {
|
type ActionButtonProps<T> = {
|
||||||
|
|||||||
@ -26,6 +26,7 @@ const Menus = [
|
|||||||
Operator.YahooFinance,
|
Operator.YahooFinance,
|
||||||
Operator.PubMed,
|
Operator.PubMed,
|
||||||
Operator.GoogleScholar,
|
Operator.GoogleScholar,
|
||||||
|
Operator.ArXiv,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,11 +1,40 @@
|
|||||||
import TopNItem from '@/components/top-n-item';
|
import { FormContainer } from '@/components/form-container';
|
||||||
|
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 { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { Form, 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 DynamicInputVariable from '../components/dynamic-input-variable';
|
import { z } from 'zod';
|
||||||
|
import { initialArXivValues } from '../../constant';
|
||||||
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
|
import { INextOperatorForm } from '../../interface';
|
||||||
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
|
import { Output } from '../components/output';
|
||||||
|
import { QueryVariable } from '../components/query-variable';
|
||||||
|
|
||||||
const ArXivForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
export const ArXivFormPartialSchema = {
|
||||||
|
top_n: z.number(),
|
||||||
|
sort_by: z.string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FormSchema = z.object({
|
||||||
|
...ArXivFormPartialSchema,
|
||||||
|
query: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export function ArXivFormWidgets() {
|
||||||
|
const form = useFormContext();
|
||||||
const { t } = useTranslate('flow');
|
const { t } = useTranslate('flow');
|
||||||
|
|
||||||
const options = useMemo(() => {
|
const options = useMemo(() => {
|
||||||
@ -16,21 +45,52 @@ const ArXivForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
|||||||
}, [t]);
|
}, [t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<>
|
||||||
name="basic"
|
<TopNFormField></TopNFormField>
|
||||||
autoComplete="off"
|
<FormField
|
||||||
form={form}
|
control={form.control}
|
||||||
onValuesChange={onValuesChange}
|
name={`sort_by`}
|
||||||
layout={'vertical'}
|
render={({ field }) => (
|
||||||
>
|
<FormItem className="flex-1">
|
||||||
<DynamicInputVariable node={node}></DynamicInputVariable>
|
<FormLabel>{t('sortBy')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch {...field} options={options}></SelectWithSearch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
<TopNItem initialValue={10}></TopNItem>
|
const outputList = buildOutputList(initialArXivValues.outputs);
|
||||||
<Form.Item label={t('sortBy')} name={'sort_by'}>
|
|
||||||
<Select options={options}></Select>
|
function ArXivForm({ node }: INextOperatorForm) {
|
||||||
</Form.Item>
|
const defaultValues = useFormValues(initialArXivValues, node);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<QueryVariable></QueryVariable>
|
||||||
|
</FormContainer>
|
||||||
|
<FormContainer>
|
||||||
|
<ArXivFormWidgets></ArXivFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
<div className="p-5">
|
||||||
|
<Output list={outputList}></Output>
|
||||||
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ArXivForm;
|
export default memo(ArXivForm);
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import { useForm, useFormContext } from 'react-hook-form';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { Channel, initialDuckValues } from '../../constant';
|
import { Channel, initialDuckValues } from '../../constant';
|
||||||
import { useFormValues } from '../../hooks/use-form-values';
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { buildOutputList } from '../../utils/build-output-list';
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
import { FormWrapper } from '../components/form-wrapper';
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
@ -70,6 +71,8 @@ function DuckDuckGoForm({ node }: INextOperatorForm) {
|
|||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { useForm, useFormContext } from 'react-hook-form';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { initialEmailValues } from '../../constant';
|
import { initialEmailValues } from '../../constant';
|
||||||
import { useFormValues } from '../../hooks/use-form-values';
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { buildOutputList } from '../../utils/build-output-list';
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
import { FormWrapper } from '../components/form-wrapper';
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
@ -101,6 +102,8 @@ const EmailForm = ({ node }: INextOperatorForm) => {
|
|||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { FormContainer } from '@/components/form-container';
|
import { FormContainer } from '@/components/form-container';
|
||||||
import NumberInput from '@/components/originui/number-input';
|
import NumberInput from '@/components/originui/number-input';
|
||||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||||
import { TopNFormField } from '@/components/top-n-item';
|
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@ -12,10 +11,11 @@ import {
|
|||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
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 { useForm } from 'react-hook-form';
|
import { useForm, useFormContext } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { initialGoogleValues } from '../../constant';
|
import { initialGoogleValues } from '../../constant';
|
||||||
import { useFormValues } from '../../hooks/use-form-values';
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { GoogleCountryOptions, GoogleLanguageOptions } from '../../options';
|
import { GoogleCountryOptions, GoogleLanguageOptions } from '../../options';
|
||||||
import { buildOutputList } from '../../utils/build-output-list';
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
@ -26,16 +26,61 @@ import { QueryVariable } from '../components/query-variable';
|
|||||||
|
|
||||||
const outputList = buildOutputList(initialGoogleValues.outputs);
|
const outputList = buildOutputList(initialGoogleValues.outputs);
|
||||||
|
|
||||||
export const FormSchema = z.object({
|
export const GoogleFormPartialSchema = {
|
||||||
top_n: z.number(),
|
|
||||||
api_key: z.string(),
|
api_key: z.string(),
|
||||||
country: z.string(),
|
country: z.string(),
|
||||||
language: z.string(),
|
language: z.string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FormSchema = z.object({
|
||||||
|
...GoogleFormPartialSchema,
|
||||||
q: z.string(),
|
q: z.string(),
|
||||||
start: z.number(),
|
start: z.number(),
|
||||||
num: z.number(),
|
num: z.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function GoogleFormWidgets() {
|
||||||
|
const form = useFormContext();
|
||||||
|
const { t } = useTranslate('flow');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`country`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormLabel>{t('country')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch
|
||||||
|
{...field}
|
||||||
|
options={GoogleCountryOptions}
|
||||||
|
></SelectWithSearch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`language`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormLabel>{t('language')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch
|
||||||
|
{...field}
|
||||||
|
options={GoogleLanguageOptions}
|
||||||
|
></SelectWithSearch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const GoogleForm = ({ node }: INextOperatorForm) => {
|
const GoogleForm = ({ node }: INextOperatorForm) => {
|
||||||
const { t } = useTranslate('flow');
|
const { t } = useTranslate('flow');
|
||||||
const defaultValues = useFormValues(initialGoogleValues, node);
|
const defaultValues = useFormValues(initialGoogleValues, node);
|
||||||
@ -45,6 +90,8 @@ const GoogleForm = ({ node }: INextOperatorForm) => {
|
|||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
@ -79,39 +126,7 @@ const GoogleForm = ({ node }: INextOperatorForm) => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<TopNFormField></TopNFormField>
|
<GoogleFormWidgets></GoogleFormWidgets>
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name={`country`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel>{t('country')}</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<SelectWithSearch
|
|
||||||
{...field}
|
|
||||||
options={GoogleCountryOptions}
|
|
||||||
></SelectWithSearch>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name={`language`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="flex-1">
|
|
||||||
<FormLabel>{t('language')}</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<SelectWithSearch
|
|
||||||
{...field}
|
|
||||||
options={GoogleLanguageOptions}
|
|
||||||
></SelectWithSearch>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
</FormWrapper>
|
</FormWrapper>
|
||||||
<div className="p-5">
|
<div className="p-5">
|
||||||
|
|||||||
@ -1,12 +1,33 @@
|
|||||||
import TopNItem from '@/components/top-n-item';
|
import { FormContainer } from '@/components/form-container';
|
||||||
|
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 { Switch } from '@/components/ui/switch';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { DatePicker, DatePickerProps, Form, Select, Switch } from 'antd';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { DatePicker, DatePickerProps } from 'antd';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
|
import { useForm, useFormContext } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import { initialGoogleScholarValues } from '../../constant';
|
||||||
import { useBuildSortOptions } from '../../form-hooks';
|
import { useBuildSortOptions } from '../../form-hooks';
|
||||||
import { IOperatorForm } from '../../interface';
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
import DynamicInputVariable from '../components/dynamic-input-variable';
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
|
import { INextOperatorForm } from '../../interface';
|
||||||
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
|
import { Output } from '../components/output';
|
||||||
|
import { QueryVariable } from '../components/query-variable';
|
||||||
|
|
||||||
|
// TODO: To be replaced
|
||||||
const YearPicker = ({
|
const YearPicker = ({
|
||||||
onChange,
|
onChange,
|
||||||
value,
|
value,
|
||||||
@ -32,44 +53,114 @@ const YearPicker = ({
|
|||||||
return <DatePicker picker="year" onChange={handleChange} value={nextValue} />;
|
return <DatePicker picker="year" onChange={handleChange} value={nextValue} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const GoogleScholarForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
export function GoogleScholarFormWidgets() {
|
||||||
|
const form = useFormContext();
|
||||||
const { t } = useTranslate('flow');
|
const { t } = useTranslate('flow');
|
||||||
|
|
||||||
const options = useBuildSortOptions();
|
const options = useBuildSortOptions();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<>
|
||||||
name="basic"
|
<TopNFormField></TopNFormField>
|
||||||
autoComplete="off"
|
<FormField
|
||||||
form={form}
|
control={form.control}
|
||||||
onValuesChange={onValuesChange}
|
name={`sort_by`}
|
||||||
layout={'vertical'}
|
render={({ field }) => (
|
||||||
>
|
<FormItem className="flex-1">
|
||||||
<DynamicInputVariable node={node}></DynamicInputVariable>
|
<FormLabel>{t('sortBy')}</FormLabel>
|
||||||
<TopNItem initialValue={5}></TopNItem>
|
<FormControl>
|
||||||
<Form.Item
|
<SelectWithSearch {...field} options={options}></SelectWithSearch>
|
||||||
label={t('sortBy')}
|
</FormControl>
|
||||||
name={'sort_by'}
|
<FormMessage />
|
||||||
initialValue={'relevance'}
|
</FormItem>
|
||||||
>
|
)}
|
||||||
<Select options={options}></Select>
|
/>
|
||||||
</Form.Item>
|
<FormField
|
||||||
<Form.Item label={t('yearLow')} name={'year_low'}>
|
control={form.control}
|
||||||
<YearPicker />
|
name={`year_low`}
|
||||||
</Form.Item>
|
render={({ field }) => (
|
||||||
<Form.Item label={t('yearHigh')} name={'year_high'}>
|
<FormItem className="flex-1">
|
||||||
<YearPicker />
|
<FormLabel>{t('yearLow')}</FormLabel>
|
||||||
</Form.Item>
|
<FormControl>
|
||||||
<Form.Item
|
<YearPicker {...field}></YearPicker>
|
||||||
label={t('patents')}
|
</FormControl>
|
||||||
name={'patents'}
|
<FormMessage />
|
||||||
valuePropName="checked"
|
</FormItem>
|
||||||
initialValue={true}
|
)}
|
||||||
>
|
/>
|
||||||
<Switch></Switch>
|
<FormField
|
||||||
</Form.Item>
|
control={form.control}
|
||||||
</Form>
|
name={`year_high`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormLabel>{t('yearHigh')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<YearPicker {...field}></YearPicker>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`patents`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormLabel>{t('patents')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Switch
|
||||||
|
checked={field.value}
|
||||||
|
onCheckedChange={field.onChange}
|
||||||
|
></Switch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GoogleScholarFormPartialSchema = {
|
||||||
|
top_n: z.number(),
|
||||||
|
sort_by: z.string(),
|
||||||
|
year_low: z.number(),
|
||||||
|
year_high: z.number(),
|
||||||
|
patents: z.boolean(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default GoogleScholarForm;
|
export const FormSchema = z.object({
|
||||||
|
...GoogleScholarFormPartialSchema,
|
||||||
|
query: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const outputList = buildOutputList(initialGoogleScholarValues.outputs);
|
||||||
|
|
||||||
|
function GoogleScholarForm({ node }: INextOperatorForm) {
|
||||||
|
const defaultValues = useFormValues(initialGoogleScholarValues, node);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<QueryVariable></QueryVariable>
|
||||||
|
</FormContainer>
|
||||||
|
<FormContainer>
|
||||||
|
<GoogleScholarFormWidgets></GoogleScholarFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
<div className="p-5">
|
||||||
|
<Output list={outputList}></Output>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(GoogleScholarForm);
|
||||||
|
|||||||
35
web/src/pages/agent/form/tool-form/arxiv-form/index.tsx
Normal file
35
web/src/pages/agent/form/tool-form/arxiv-form/index.tsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { FormContainer } from '@/components/form-container';
|
||||||
|
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 { ArXivFormPartialSchema, ArXivFormWidgets } from '../../arxiv-form';
|
||||||
|
import { FormWrapper } from '../../components/form-wrapper';
|
||||||
|
import { useValues } from '../use-values';
|
||||||
|
import { useWatchFormChange } from '../use-watch-change';
|
||||||
|
|
||||||
|
function ArXivForm() {
|
||||||
|
const values = useValues();
|
||||||
|
|
||||||
|
const FormSchema = z.object(ArXivFormPartialSchema);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues: values,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<ArXivFormWidgets></ArXivFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(ArXivForm);
|
||||||
@ -1,15 +1,16 @@
|
|||||||
import { Operator } from '../../constant';
|
import { Operator } from '../../constant';
|
||||||
import AkShareForm from '../akshare-form';
|
import AkShareForm from '../akshare-form';
|
||||||
import ArXivForm from '../arxiv-form';
|
|
||||||
import DeepLForm from '../deepl-form';
|
import DeepLForm from '../deepl-form';
|
||||||
import GithubForm from '../github-form';
|
import GithubForm from '../github-form';
|
||||||
import GoogleScholarForm from '../google-scholar-form';
|
|
||||||
import PubMedForm from '../pubmed-form';
|
import PubMedForm from '../pubmed-form';
|
||||||
|
import ArXivForm from './arxiv-form';
|
||||||
import BingForm from './bing-form';
|
import BingForm from './bing-form';
|
||||||
import CrawlerForm from './crawler-form';
|
import CrawlerForm from './crawler-form';
|
||||||
import DuckDuckGoForm from './duckduckgo-form';
|
import DuckDuckGoForm from './duckduckgo-form';
|
||||||
import EmailForm from './email-form';
|
import EmailForm from './email-form';
|
||||||
import ExeSQLForm from './exesql-form';
|
import ExeSQLForm from './exesql-form';
|
||||||
|
import GoogleForm from './google-form';
|
||||||
|
import GoogleScholarForm from './google-scholar-form';
|
||||||
import RetrievalForm from './retrieval-form';
|
import RetrievalForm from './retrieval-form';
|
||||||
import TavilyForm from './tavily-form';
|
import TavilyForm from './tavily-form';
|
||||||
import WikipediaForm from './wikipedia-form';
|
import WikipediaForm from './wikipedia-form';
|
||||||
@ -22,7 +23,7 @@ export const ToolFormConfigMap = {
|
|||||||
[Operator.Wikipedia]: WikipediaForm,
|
[Operator.Wikipedia]: WikipediaForm,
|
||||||
[Operator.PubMed]: PubMedForm,
|
[Operator.PubMed]: PubMedForm,
|
||||||
[Operator.ArXiv]: ArXivForm,
|
[Operator.ArXiv]: ArXivForm,
|
||||||
[Operator.Google]: TavilyForm,
|
[Operator.Google]: GoogleForm,
|
||||||
[Operator.Bing]: BingForm,
|
[Operator.Bing]: BingForm,
|
||||||
[Operator.GoogleScholar]: GoogleScholarForm,
|
[Operator.GoogleScholar]: GoogleScholarForm,
|
||||||
[Operator.DeepL]: DeepLForm,
|
[Operator.DeepL]: DeepLForm,
|
||||||
|
|||||||
37
web/src/pages/agent/form/tool-form/google-form/index.tsx
Normal file
37
web/src/pages/agent/form/tool-form/google-form/index.tsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { FormContainer } from '@/components/form-container';
|
||||||
|
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 { ApiKeyField } from '../../components/api-key-field';
|
||||||
|
import { FormWrapper } from '../../components/form-wrapper';
|
||||||
|
import { GoogleFormPartialSchema, GoogleFormWidgets } from '../../google-form';
|
||||||
|
import { useValues } from '../use-values';
|
||||||
|
import { useWatchFormChange } from '../use-watch-change';
|
||||||
|
|
||||||
|
function GoogleForm() {
|
||||||
|
const values = useValues();
|
||||||
|
|
||||||
|
const FormSchema = z.object(GoogleFormPartialSchema);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues: values,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<ApiKeyField></ApiKeyField>
|
||||||
|
<GoogleFormWidgets></GoogleFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(GoogleForm);
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
import { FormContainer } from '@/components/form-container';
|
||||||
|
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 { FormWrapper } from '../../components/form-wrapper';
|
||||||
|
import {
|
||||||
|
GoogleScholarFormPartialSchema,
|
||||||
|
GoogleScholarFormWidgets,
|
||||||
|
} from '../../google-scholar-form';
|
||||||
|
import { useValues } from '../use-values';
|
||||||
|
import { useWatchFormChange } from '../use-watch-change';
|
||||||
|
|
||||||
|
function GoogleScholarForm() {
|
||||||
|
const values = useValues();
|
||||||
|
|
||||||
|
const FormSchema = z.object(GoogleScholarFormPartialSchema);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues: values,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<GoogleScholarFormWidgets></GoogleScholarFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(GoogleScholarForm);
|
||||||
@ -16,6 +16,7 @@ import { useForm, useFormContext } from 'react-hook-form';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { initialWikipediaValues } from '../../constant';
|
import { initialWikipediaValues } from '../../constant';
|
||||||
import { useFormValues } from '../../hooks/use-form-values';
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { LanguageOptions } from '../../options';
|
import { LanguageOptions } from '../../options';
|
||||||
import { buildOutputList } from '../../utils/build-output-list';
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
@ -67,6 +68,8 @@ function WikipediaForm({ node }: INextOperatorForm) {
|
|||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import { useForm, useFormContext } from 'react-hook-form';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { initialYahooFinanceValues } from '../../constant';
|
import { initialYahooFinanceValues } from '../../constant';
|
||||||
import { useFormValues } from '../../hooks/use-form-values';
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { buildOutputList } from '../../utils/build-output-list';
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
import { FormWrapper } from '../components/form-wrapper';
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
@ -99,6 +100,8 @@ const YahooFinanceForm = ({ node }: INextOperatorForm) => {
|
|||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export function useAgentToolInitialValues() {
|
|||||||
...omit(initialValues, 'query'),
|
...omit(initialValues, 'query'),
|
||||||
description: '',
|
description: '',
|
||||||
};
|
};
|
||||||
case (Operator.TavilySearch, Operator.TavilyExtract, Operator.Google):
|
case (Operator.TavilySearch, Operator.TavilyExtract):
|
||||||
return {
|
return {
|
||||||
api_key: '',
|
api_key: '',
|
||||||
};
|
};
|
||||||
@ -42,6 +42,12 @@ export function useAgentToolInitialValues() {
|
|||||||
|
|
||||||
case Operator.Wikipedia:
|
case Operator.Wikipedia:
|
||||||
return pick(initialValues, 'top_n', 'language');
|
return pick(initialValues, 'top_n', 'language');
|
||||||
|
case Operator.Google:
|
||||||
|
return pick(initialValues, 'api_key', 'country', 'language');
|
||||||
|
case Operator.GoogleScholar:
|
||||||
|
return omit(initialValues, 'query', 'outputs');
|
||||||
|
case Operator.ArXiv:
|
||||||
|
return pick(initialValues, 'top_n', 'sort_by');
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return initialValues;
|
return initialValues;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user