Skip to content

Commit

Permalink
feat: 可以进行多轮文献查询
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Feb 18, 2024
1 parent edfb1c5 commit 9d799f1
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 173 deletions.
3 changes: 2 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ NEXT_PUBLIC_OPENAI_API_KEY=sk-ffe19ebe9fa44d00884330ff1c18cf82
NEXT_PUBLIC_PAPER_URL=/api/paper
NEXT_PUBLIC_SEMANTIC_API_KEY=hEQvK6ARe84dzDPcMnpzX4n9jfoqztkMfaftPWnb
NEXT_PUBLIC_PUBMED_API_KEY=057616e7ce6c722f2ae8679e38a8be9b1a09
VERCEL_URL=https://www.paperai.life
VERCEL_URL=https://www.paperai.life
NODE_ENV=production
2 changes: 1 addition & 1 deletion app/store/slices/authSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const initialState: APIState = {
2.文献引用:只引用与主题紧密相关的论文。在引用文献时,文末应使用方括号内的数字来标注引用来源,如 [1]。。请确保每个引用在文章中都有其对应的编号,*无需在文章末尾提供参考文献列表*。*每个文献对应的序号只应该出现一次,比如说引用了第一篇文献文中就只能出现一次[1]*。
3.忽略无关文献:对于与主题无关的论文,请不要包含在您的写作中。只关注对理解和阐述主题有实质性帮助的资料。
4.来源明确:在文章中,清楚地指出每个引用的具体来源。引用的信息应准确无误,确保读者能够追溯到原始文献。
5.使用中文完成回答,不超过三百字
5.使用用户所说的语言完成回答,不超过五百字
6.只能对给出的文献进行引用,坚决不能虚构文献。
返回格式举例:
在某个方面,某论文实现了以下突破...[1],在另一篇论文中,研究了...[2]`,
Expand Down
7 changes: 4 additions & 3 deletions components/GetArxiv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ interface Author {
async function getArxivPapers(
query: string,
maxResults = 5,
offset = -1,
sortBy = "submittedDate",
sortOrder = "descending"
) {
const maxOffset = 30 - maxResults; // 假设总记录数为 100
const start = getRandomOffset(maxOffset);
const url = `https://export.arxiv.org/api/query?search_query=${query}&start=${start}&max_results=${maxResults}&sortBy=${sortBy}&sortOrder=${sortOrder}`;
const maxOffset = 20 - maxResults; // 假设总记录数为 20
if (offset === -1) offset = getRandomOffset(maxOffset);
const url = `https://export.arxiv.org/api/query?search_query=${query}&start=${offset}&max_results=${maxResults}&sortBy=${sortBy}&sortOrder=${sortOrder}`;

try {
const response = await axios.get(url);
Expand Down
21 changes: 16 additions & 5 deletions components/GetPubMed .tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ type PubMedID = string;
// 定义idList为PubMedID数组
type IDList = PubMedID[];

async function getPubMedPapers(query: string, year: number, limit = 2) {
async function getPubMedPapers(
query: string,
year: number,
offset = -1,
limit = 2
) {
try {
const baseURL =
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi";
const db = "pubmed"; // 设定搜索的数据库为PubMed
const retMax = limit; // 检索的最大记录数
const retStart = getRandomOffset(20 - limit); // 假设每页最多30条,根据需要随机偏移
const url = `${baseURL}?db=${db}&term=${query}[Title/Abstract]+AND+2018:3000[Date - Publication]&retMax=${retMax}&retStart=${retStart}&api_key=${process.env.NEXT_PUBLIC_PUBMED_API_KEY}`;
const maxOffset = 20 - limit; // 假设总记录数为 20
if (offset === -1) offset = getRandomOffset(maxOffset);
const url = `${baseURL}?db=${db}&term=${query}[Title/Abstract]+AND+2018:3000[Date - Publication]&retMax=${retMax}&retStart=${offset}&api_key=${process.env.NEXT_PUBLIC_PUBMED_API_KEY}`;
const response = await axios.get(url, { responseType: "text" });
console.log(response.data);
// 解析XML数据
Expand Down Expand Up @@ -155,9 +161,14 @@ async function getPubMedPaperDetails(idList: IDList) {
}

// 示例:使用这些函数
async function fetchPubMedData(query: string, year: number, limit: number) {
async function fetchPubMedData(
query: string,
year: number,
limit: number,
offset: number
) {
try {
const idList = await getPubMedPapers(query, year, limit);
const idList = await getPubMedPapers(query, year, offset, limit);
if (idList && idList.length > 0) {
const paperDetails = await getPubMedPaperDetails(idList);
console.log("fetchPubMedData", paperDetails); // 处理或显示文章详情
Expand Down
9 changes: 7 additions & 2 deletions components/GetSemantic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ interface Paper {
url: string;
}

async function getSemanticPapers(query: string, year: string, limit = 2) {
async function getSemanticPapers(
query: string,
year: string,
offset = -1,
limit = 2
) {
try {
const maxOffset = 20 - limit; // 假设总记录数为 20
const offset = getRandomOffset(maxOffset);
if (offset === -1) offset = getRandomOffset(maxOffset);
const url = `https://api.semanticscholar.org/graph/v1/paper/search`;
const response = await axios.get(url, {
headers: {
Expand Down
Loading

0 comments on commit 9d799f1

Please sign in to comment.