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 Yahoo Finance Operator #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -103,6 +103,7 @@ function AccordionOperators() {
|
|||||||
Operator.TavilyExtract,
|
Operator.TavilyExtract,
|
||||||
Operator.ExeSQL,
|
Operator.ExeSQL,
|
||||||
Operator.Google,
|
Operator.Google,
|
||||||
|
Operator.YahooFinance,
|
||||||
]}
|
]}
|
||||||
></OperatorItemList>
|
></OperatorItemList>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
|
|||||||
@ -464,13 +464,19 @@ export const initialWenCaiValues = {
|
|||||||
export const initialAkShareValues = { top_n: 10, ...initialQueryBaseValues };
|
export const initialAkShareValues = { top_n: 10, ...initialQueryBaseValues };
|
||||||
|
|
||||||
export const initialYahooFinanceValues = {
|
export const initialYahooFinanceValues = {
|
||||||
|
stock_code: '',
|
||||||
info: true,
|
info: true,
|
||||||
history: false,
|
history: false,
|
||||||
financials: false,
|
financials: false,
|
||||||
balance_sheet: false,
|
balance_sheet: false,
|
||||||
cash_flow_statement: false,
|
cash_flow_statement: false,
|
||||||
news: true,
|
news: true,
|
||||||
...initialQueryBaseValues,
|
outputs: {
|
||||||
|
report: {
|
||||||
|
value: '',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialJin10Values = {
|
export const initialJin10Values = {
|
||||||
|
|||||||
@ -8,12 +8,12 @@ import GithubForm from '../github-form';
|
|||||||
import GoogleScholarForm from '../google-scholar-form';
|
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 BingForm from './bing-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';
|
||||||
import TavilyForm from './tavily-form';
|
import TavilyForm from './tavily-form';
|
||||||
|
import YahooFinanceForm from './yahoo-finance-form';
|
||||||
|
|
||||||
export const ToolFormConfigMap = {
|
export const ToolFormConfigMap = {
|
||||||
[Operator.Retrieval]: RetrievalForm,
|
[Operator.Retrieval]: RetrievalForm,
|
||||||
|
|||||||
@ -0,0 +1,40 @@
|
|||||||
|
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 {
|
||||||
|
YahooFinanceFormPartialSchema,
|
||||||
|
YahooFinanceFormWidgets,
|
||||||
|
} from '../../yahoo-finance-form';
|
||||||
|
import { useValues } from '../use-values';
|
||||||
|
import { useWatchFormChange } from '../use-watch-change';
|
||||||
|
|
||||||
|
const FormSchema = z.object({
|
||||||
|
...YahooFinanceFormPartialSchema,
|
||||||
|
});
|
||||||
|
|
||||||
|
function YahooFinanceForm() {
|
||||||
|
const values = useValues();
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues: values,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<YahooFinanceFormWidgets></YahooFinanceFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(YahooFinanceForm);
|
||||||
@ -1,38 +1,127 @@
|
|||||||
|
import { FormContainer } from '@/components/form-container';
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@/components/ui/form';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Switch } from '@/components/ui/switch';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { Form, Switch } from 'antd';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { IOperatorForm } from '../../interface';
|
import { ReactNode } from 'react';
|
||||||
import DynamicInputVariable from '../components/dynamic-input-variable';
|
import { useForm, useFormContext } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import { initialYahooFinanceValues } from '../../constant';
|
||||||
|
import { useFormValues } from '../../hooks/use-form-values';
|
||||||
|
import { INextOperatorForm } from '../../interface';
|
||||||
|
import { buildOutputList } from '../../utils/build-output-list';
|
||||||
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
|
import { Output } from '../components/output';
|
||||||
|
|
||||||
const YahooFinanceForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
export const YahooFinanceFormPartialSchema = {
|
||||||
const { t } = useTranslate('flow');
|
info: z.boolean(),
|
||||||
|
history: z.boolean(),
|
||||||
|
financials: z.boolean(),
|
||||||
|
balance_sheet: z.boolean(),
|
||||||
|
cash_flow_statement: z.boolean(),
|
||||||
|
news: z.boolean(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormSchema = z.object({
|
||||||
|
stock_code: z.string(),
|
||||||
|
...YahooFinanceFormPartialSchema,
|
||||||
|
});
|
||||||
|
|
||||||
|
interface SwitchFormFieldProps {
|
||||||
|
name: string;
|
||||||
|
label: ReactNode;
|
||||||
|
}
|
||||||
|
function SwitchFormField({ name, label }: SwitchFormFieldProps) {
|
||||||
|
const form = useFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<FormField
|
||||||
name="basic"
|
control={form.control}
|
||||||
autoComplete="off"
|
name={name}
|
||||||
form={form}
|
render={({ field }) => (
|
||||||
onValuesChange={onValuesChange}
|
<FormItem>
|
||||||
layout={'vertical'}
|
<FormLabel>{label}</FormLabel>
|
||||||
>
|
<FormControl>
|
||||||
<DynamicInputVariable node={node}></DynamicInputVariable>
|
<Switch
|
||||||
<Form.Item label={t('info')} name={'info'}>
|
checked={field.value}
|
||||||
<Switch></Switch>
|
onCheckedChange={field.onChange}
|
||||||
</Form.Item>
|
></Switch>
|
||||||
<Form.Item label={t('history')} name={'history'}>
|
</FormControl>
|
||||||
<Switch></Switch>
|
<FormMessage />
|
||||||
</Form.Item>
|
</FormItem>
|
||||||
<Form.Item label={t('financials')} name={'financials'}>
|
)}
|
||||||
<Switch></Switch>
|
/>
|
||||||
</Form.Item>
|
);
|
||||||
<Form.Item label={t('balanceSheet')} name={'balance_sheet'}>
|
}
|
||||||
<Switch></Switch>
|
|
||||||
</Form.Item>
|
export function YahooFinanceFormWidgets() {
|
||||||
<Form.Item label={t('cashFlowStatement')} name={'cash_flow_statement'}>
|
const { t } = useTranslate('flow');
|
||||||
<Switch></Switch>
|
return (
|
||||||
</Form.Item>
|
<>
|
||||||
<Form.Item label={t('news')} name={'news'}>
|
<SwitchFormField name="info" label={t('info')}></SwitchFormField>
|
||||||
<Switch></Switch>
|
<SwitchFormField name="history" label={t('history')}></SwitchFormField>
|
||||||
</Form.Item>
|
<SwitchFormField
|
||||||
|
name="financials"
|
||||||
|
label={t('financials')}
|
||||||
|
></SwitchFormField>
|
||||||
|
<SwitchFormField
|
||||||
|
name="balance_sheet"
|
||||||
|
label={t('balanceSheet')}
|
||||||
|
></SwitchFormField>
|
||||||
|
|
||||||
|
<SwitchFormField
|
||||||
|
name="cash_flow_statement"
|
||||||
|
label={t('cashFlowStatement')}
|
||||||
|
></SwitchFormField>
|
||||||
|
|
||||||
|
<SwitchFormField name="news" label={t('news')}></SwitchFormField>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputList = buildOutputList(initialYahooFinanceValues.outputs);
|
||||||
|
|
||||||
|
const YahooFinanceForm = ({ node }: INextOperatorForm) => {
|
||||||
|
const { t } = useTranslate('flow');
|
||||||
|
|
||||||
|
const defaultValues = useFormValues(initialYahooFinanceValues, node);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
|
defaultValues,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`stock_code`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('stockCode')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field}></Input>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<YahooFinanceFormWidgets></YahooFinanceFormWidgets>
|
||||||
|
</FormContainer>
|
||||||
|
</FormWrapper>
|
||||||
|
<div className="p-5">
|
||||||
|
<Output list={outputList}></Output>
|
||||||
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -24,6 +24,8 @@ export function useAgentToolInitialValues() {
|
|||||||
return omit(initialValues, 'sql');
|
return omit(initialValues, 'sql');
|
||||||
case Operator.Bing:
|
case Operator.Bing:
|
||||||
return omit(initialValues, 'query');
|
return omit(initialValues, 'query');
|
||||||
|
case Operator.YahooFinance:
|
||||||
|
return omit(initialValues, 'stock_code');
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return initialValues;
|
return initialValues;
|
||||||
|
|||||||
Reference in New Issue
Block a user