Skip to content

Commit

Permalink
feat: Add GoogleScholar infiniflow#918 (infiniflow#1818)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
feat: Add GoogleScholar infiniflow#918
### Type of change


- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Aug 6, 2024
1 parent 79592b8 commit 88be3f6
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 0 deletions.
9 changes: 9 additions & 0 deletions web/src/assets/svg/google-scholar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions web/src/components/file-upload-modal/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
}
}
}

.uploadLimit {
color: red;
font-size: 12px;
}
1 change: 1 addition & 0 deletions web/src/components/file-upload-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const FileUpload = ({
</p>
<p className="ant-upload-text">{t('uploadTitle')}</p>
<p className="ant-upload-hint">{t('uploadDescription')}</p>
{false && <p className={styles.uploadLimit}>{t('uploadLimit')}</p>}
</Dragger>
);
};
Expand Down
9 changes: 9 additions & 0 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ The above is the content you need to summarize.`,
s3: 'S3 uploads',
preview: 'Preview',
fileError: 'File error',
uploadLimit:
'The file size cannot exceed 10M, and the total number of files cannot exceed 128',
},
flow: {
cite: 'Cite',
Expand Down Expand Up @@ -650,6 +652,13 @@ The above is the content you need to summarize.`,
apiKey: 'Api Key',
country: 'Country',
language: 'Language',
googleScholar: 'Google Scholar',
googleScholarDescription:
'This component is used to get search result from https://scholar.google.com/. Typically, it performs as a supplement to knowledgebases. Top N specifies the number of search results you need to adapt.',
yearLow: 'Year low',
yearHigh: 'Year high',
patents: 'Patents',
data: 'Data',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
7 changes: 7 additions & 0 deletions web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export default {
s3: 'S3 上傳',
preview: '預覽',
fileError: '文件錯誤',
uploadLimit: '文件大小不能超過10M,文件總數不超過128個',
},
flow: {
cite: '引用',
Expand Down Expand Up @@ -610,6 +611,12 @@ export default {
apiKey: 'Api Key',
country: '國家',
language: '語言',
googleScholar: '谷歌學術',
googleScholarDescription: `該元件用於從 https://scholar.google.com/ 取得搜尋結果。通常,它充當知識庫的補充。 Top N 指定您需要調整的搜尋結果的數量。`,
yearLow: '開始年份',
yearHigh: '結束年份',
patents: '專利',
data: '數據',
},
footer: {
profile: '“保留所有權利 @ react”',
Expand Down
7 changes: 7 additions & 0 deletions web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ export default {
s3: 'S3 上传',
preview: '预览',
fileError: '文件错误',
uploadLimit: '文件大小不能超过10M,文件总数不超过128个',
},
flow: {
flow: '工作流',
Expand Down Expand Up @@ -628,6 +629,12 @@ export default {
apiKey: 'Api Key',
country: '国家',
language: '语言',
googleScholar: '谷歌学术',
googleScholarDescription: `此组件用于从 https://scholar.google.com/ 获取搜索结果。通常,它作为知识库的补充。Top N 指定您需要调整的搜索结果数量。`,
yearLow: '开始年份',
yearHigh: '结束年份',
patents: '专利',
data: '数据',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
15 changes: 15 additions & 0 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactComponent as ArXivIcon } from '@/assets/svg/arxiv.svg';
import { ReactComponent as BaiduIcon } from '@/assets/svg/baidu.svg';
import { ReactComponent as BingIcon } from '@/assets/svg/bing.svg';
import { ReactComponent as DuckIcon } from '@/assets/svg/duck.svg';
import { ReactComponent as GoogleScholarIcon } from '@/assets/svg/google-scholar.svg';
import { ReactComponent as GoogleIcon } from '@/assets/svg/google.svg';
import { ReactComponent as KeywordIcon } from '@/assets/svg/keyword.svg';
import { ReactComponent as PubMedIcon } from '@/assets/svg/pubmed.svg';
Expand Down Expand Up @@ -44,6 +45,7 @@ export enum Operator {
ArXiv = 'ArXiv',
Google = 'Google',
Bing = 'Bing',
GoogleScholar = 'GoogleScholar',
}

export const operatorIconMap = {
Expand All @@ -63,6 +65,7 @@ export const operatorIconMap = {
[Operator.ArXiv]: ArXivIcon,
[Operator.Google]: GoogleIcon,
[Operator.Bing]: BingIcon,
[Operator.GoogleScholar]: GoogleScholarIcon,
};

export const operatorMap = {
Expand Down Expand Up @@ -145,6 +148,7 @@ export const operatorMap = {
backgroundColor: 'pink',
},
[Operator.Bing]: {},
[Operator.GoogleScholar]: {},
};

export const componentMenuList = [
Expand Down Expand Up @@ -193,6 +197,9 @@ export const componentMenuList = [
{
name: Operator.Bing,
},
{
name: Operator.GoogleScholar,
},
];

export const initialRetrievalValues = {
Expand Down Expand Up @@ -291,6 +298,12 @@ export const initialBingValues = {
language: 'en',
};

export const initialGoogleScholarValues = {
top_n: 5,
sort_by: 'relevance',
patents: true,
};

export const CategorizeAnchorPointPositions = [
{ top: 1, right: 34 },
{ top: 8, right: 18 },
Expand Down Expand Up @@ -354,6 +367,7 @@ export const RestrictedUpstreamMap = {
[Operator.ArXiv]: [Operator.Begin, Operator.Retrieval],
[Operator.Google]: [Operator.Begin, Operator.Retrieval],
[Operator.Bing]: [Operator.Begin, Operator.Retrieval],
[Operator.GoogleScholar]: [Operator.Begin, Operator.Retrieval],
};

export const NodeMap = {
Expand All @@ -373,6 +387,7 @@ export const NodeMap = {
[Operator.ArXiv]: 'ragNode',
[Operator.Google]: 'ragNode',
[Operator.Bing]: 'ragNode',
[Operator.GoogleScholar]: 'ragNode',
};

export const LanguageOptions = [
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/flow/flow-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Operator } from '../constant';
import DuckDuckGoForm from '../duckduckgo-form';
import GenerateForm from '../generate-form';
import GoogleForm from '../google-form';
import GoogleScholarForm from '../google-scholar-form';
import { useHandleFormValuesChange, useHandleNodeNameChange } from '../hooks';
import KeywordExtractForm from '../keyword-extract-form';
import MessageForm from '../message-form';
Expand Down Expand Up @@ -46,6 +47,7 @@ const FormMap = {
[Operator.ArXiv]: ArXivForm,
[Operator.Google]: GoogleForm,
[Operator.Bing]: BingForm,
[Operator.GoogleScholar]: GoogleScholarForm,
};

const EmptyContent = () => <div>empty</div>;
Expand Down
78 changes: 78 additions & 0 deletions web/src/pages/flow/google-scholar-form/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import TopNItem from '@/components/top-n-item';
import { useTranslate } from '@/hooks/common-hooks';
import { DatePicker, DatePickerProps, Form, Select, Switch } from 'antd';
import dayjs from 'dayjs';
import { useCallback, useMemo } from 'react';
import { IOperatorForm } from '../interface';

const YearPicker = ({
onChange,
value,
}: {
onChange?: (val: number | undefined) => void;
value?: number | undefined;
}) => {
const handleChange: DatePickerProps['onChange'] = useCallback(
(val: any) => {
const nextVal = val?.format('YYYY');
onChange?.(nextVal ? Number(nextVal) : undefined);
},
[onChange],
);
// The year needs to be converted into a number and saved to the backend
const nextValue = useMemo(() => {
if (value) {
return dayjs(value.toString());
}
return undefined;
}, [value]);

return <DatePicker picker="year" onChange={handleChange} value={nextValue} />;
};

const GoogleScholarForm = ({ onValuesChange, form }: IOperatorForm) => {
const { t } = useTranslate('flow');

const options = useMemo(() => {
return ['data', 'relevance'].map((x) => ({
value: x,
label: t(x),
}));
}, [t]);

return (
<Form
name="basic"
labelCol={{ span: 6 }}
wrapperCol={{ span: 18 }}
autoComplete="off"
form={form}
onValuesChange={onValuesChange}
>
<TopNItem initialValue={5}></TopNItem>
<Form.Item
label={t('sortBy')}
name={'sort_by'}
initialValue={'relevance'}
>
<Select options={options}></Select>
</Form.Item>
<Form.Item label={t('yearLow')} name={'year_low'}>
<YearPicker />
</Form.Item>
<Form.Item label={t('yearHigh')} name={'year_high'}>
<YearPicker />
</Form.Item>
<Form.Item
label={t('patents')}
name={'patents'}
valuePropName="checked"
initialValue={true}
>
<Switch></Switch>
</Form.Item>
</Form>
);
};

export default GoogleScholarForm;
2 changes: 2 additions & 0 deletions web/src/pages/flow/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
initialCategorizeValues,
initialDuckValues,
initialGenerateValues,
initialGoogleScholarValues,
initialGoogleValues,
initialKeywordExtractValues,
initialMessageValues,
Expand Down Expand Up @@ -97,6 +98,7 @@ export const useInitializeOperatorParams = () => {
[Operator.ArXiv]: initialArXivValues,
[Operator.Google]: initialGoogleValues,
[Operator.Bing]: initialBingValues,
[Operator.GoogleScholar]: initialGoogleScholarValues,
};
}, [llmId]);

Expand Down

0 comments on commit 88be3f6

Please sign in to comment.