chengyanwu commited on
Commit ·
bc09fd8
1
Parent(s): ebeb985
add pdf link
Browse files- example/backend/server.py +8 -4
- example/src/routes/+page.svelte +35 -6
example/backend/server.py
CHANGED
|
@@ -62,6 +62,7 @@ class PaperInfo(BaseModel):
|
|
| 62 |
title: str
|
| 63 |
abstract: str
|
| 64 |
similarity: str
|
|
|
|
| 65 |
|
| 66 |
class QueryResponse(BaseModel):
|
| 67 |
response: str
|
|
@@ -107,7 +108,8 @@ def format_papers_context(papers, similarities):
|
|
| 107 |
context += f"Title: {original_paper['title']}\n\n"
|
| 108 |
context += f"Published Time: {original_paper['published_time']}\n\n"
|
| 109 |
context += f"Abstract: {original_paper['abstract']}\n\n"
|
| 110 |
-
context += "
|
|
|
|
| 111 |
return context, relevant_papers
|
| 112 |
|
| 113 |
# Simple API health checker route.
|
|
@@ -115,7 +117,7 @@ def format_papers_context(papers, similarities):
|
|
| 115 |
async def hello():
|
| 116 |
return {"message": "hello"}
|
| 117 |
|
| 118 |
-
@app.post("/api/
|
| 119 |
async def generate_response(request: QueryRequest):
|
| 120 |
try:
|
| 121 |
# Generate embedding for the query
|
|
@@ -178,7 +180,8 @@ async def generate_response(request: QueryRequest):
|
|
| 178 |
paper_info.append(PaperInfo(
|
| 179 |
title=paper_objects[i]['title'],
|
| 180 |
abstract=paper_objects[i]['abstract'],
|
| 181 |
-
similarity=f"Similarity Score: {similarities[i]:.3f}"
|
|
|
|
| 182 |
))
|
| 183 |
|
| 184 |
# Ensure we have exactly 3 papers in the response
|
|
@@ -186,7 +189,8 @@ async def generate_response(request: QueryRequest):
|
|
| 186 |
paper_info.append(PaperInfo(
|
| 187 |
title="",
|
| 188 |
abstract="",
|
| 189 |
-
similarity=""
|
|
|
|
| 190 |
))
|
| 191 |
|
| 192 |
return QueryResponse(
|
|
|
|
| 62 |
title: str
|
| 63 |
abstract: str
|
| 64 |
similarity: str
|
| 65 |
+
link: str
|
| 66 |
|
| 67 |
class QueryResponse(BaseModel):
|
| 68 |
response: str
|
|
|
|
| 108 |
context += f"Title: {original_paper['title']}\n\n"
|
| 109 |
context += f"Published Time: {original_paper['published_time']}\n\n"
|
| 110 |
context += f"Abstract: {original_paper['abstract']}\n\n"
|
| 111 |
+
context += "Question: "
|
| 112 |
+
# context += "Please use the information from the retrieved papers to answer the question. Do not reference or recommend papers that weren't retrieved.\n\n"
|
| 113 |
return context, relevant_papers
|
| 114 |
|
| 115 |
# Simple API health checker route.
|
|
|
|
| 117 |
async def hello():
|
| 118 |
return {"message": "hello"}
|
| 119 |
|
| 120 |
+
@app.post("/api/query", response_model=QueryResponse)
|
| 121 |
async def generate_response(request: QueryRequest):
|
| 122 |
try:
|
| 123 |
# Generate embedding for the query
|
|
|
|
| 180 |
paper_info.append(PaperInfo(
|
| 181 |
title=paper_objects[i]['title'],
|
| 182 |
abstract=paper_objects[i]['abstract'],
|
| 183 |
+
similarity=f"Similarity Score: {similarities[i]:.3f}",
|
| 184 |
+
link=paper_objects[i]['pdf_link']
|
| 185 |
))
|
| 186 |
|
| 187 |
# Ensure we have exactly 3 papers in the response
|
|
|
|
| 189 |
paper_info.append(PaperInfo(
|
| 190 |
title="",
|
| 191 |
abstract="",
|
| 192 |
+
similarity="",
|
| 193 |
+
link=""
|
| 194 |
))
|
| 195 |
|
| 196 |
return QueryResponse(
|
example/src/routes/+page.svelte
CHANGED
|
@@ -6,9 +6,9 @@
|
|
| 6 |
let isLoading = false;
|
| 7 |
let response = '';
|
| 8 |
let papers = [
|
| 9 |
-
{ title: '', abstract: '', similarity: '' },
|
| 10 |
-
{ title: '', abstract: '', similarity: '' },
|
| 11 |
-
{ title: '', abstract: '', similarity: '' }
|
| 12 |
];
|
| 13 |
|
| 14 |
// Example questions
|
|
@@ -44,17 +44,20 @@
|
|
| 44 |
{
|
| 45 |
title: data.papers[0].title,
|
| 46 |
abstract: data.papers[0].abstract,
|
| 47 |
-
similarity: data.papers[0].similarity
|
|
|
|
| 48 |
},
|
| 49 |
{
|
| 50 |
title: data.papers[1].title,
|
| 51 |
abstract: data.papers[1].abstract,
|
| 52 |
-
similarity: data.papers[1].similarity
|
|
|
|
| 53 |
},
|
| 54 |
{
|
| 55 |
title: data.papers[2].title,
|
| 56 |
abstract: data.papers[2].abstract,
|
| 57 |
-
similarity: data.papers[2].similarity
|
|
|
|
| 58 |
}
|
| 59 |
];
|
| 60 |
} catch (error: any) {
|
|
@@ -124,6 +127,16 @@
|
|
| 124 |
<h3>Paper {i + 1}</h3>
|
| 125 |
<h4>{paper.title}</h4>
|
| 126 |
<p class="similarity">{paper.similarity}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
<div class="abstract">
|
| 128 |
<h5>Abstract</h5>
|
| 129 |
<p>{paper.abstract}</p>
|
|
@@ -258,4 +271,20 @@
|
|
| 258 |
max-height: 200px;
|
| 259 |
overflow-y: auto;
|
| 260 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
</style>
|
|
|
|
| 6 |
let isLoading = false;
|
| 7 |
let response = '';
|
| 8 |
let papers = [
|
| 9 |
+
{ title: '', abstract: '', similarity: '', link: '' },
|
| 10 |
+
{ title: '', abstract: '', similarity: '', link: '' },
|
| 11 |
+
{ title: '', abstract: '', similarity: '', link: '' }
|
| 12 |
];
|
| 13 |
|
| 14 |
// Example questions
|
|
|
|
| 44 |
{
|
| 45 |
title: data.papers[0].title,
|
| 46 |
abstract: data.papers[0].abstract,
|
| 47 |
+
similarity: data.papers[0].similarity,
|
| 48 |
+
link: data.papers[0].link
|
| 49 |
},
|
| 50 |
{
|
| 51 |
title: data.papers[1].title,
|
| 52 |
abstract: data.papers[1].abstract,
|
| 53 |
+
similarity: data.papers[1].similarity,
|
| 54 |
+
link: data.papers[1].link
|
| 55 |
},
|
| 56 |
{
|
| 57 |
title: data.papers[2].title,
|
| 58 |
abstract: data.papers[2].abstract,
|
| 59 |
+
similarity: data.papers[2].similarity,
|
| 60 |
+
link: data.papers[2].link
|
| 61 |
}
|
| 62 |
];
|
| 63 |
} catch (error: any) {
|
|
|
|
| 127 |
<h3>Paper {i + 1}</h3>
|
| 128 |
<h4>{paper.title}</h4>
|
| 129 |
<p class="similarity">{paper.similarity}</p>
|
| 130 |
+
{#if paper.link}
|
| 131 |
+
<a
|
| 132 |
+
href={paper.link}
|
| 133 |
+
target="_blank"
|
| 134 |
+
rel="noopener noreferrer"
|
| 135 |
+
class="paper-link"
|
| 136 |
+
>
|
| 137 |
+
Read Paper
|
| 138 |
+
</a>
|
| 139 |
+
{/if}
|
| 140 |
<div class="abstract">
|
| 141 |
<h5>Abstract</h5>
|
| 142 |
<p>{paper.abstract}</p>
|
|
|
|
| 271 |
max-height: 200px;
|
| 272 |
overflow-y: auto;
|
| 273 |
}
|
| 274 |
+
|
| 275 |
+
.paper-link {
|
| 276 |
+
display: inline-block;
|
| 277 |
+
margin-top: 10px;
|
| 278 |
+
margin-bottom: 10px;
|
| 279 |
+
padding: 5px 10px;
|
| 280 |
+
background-color: #e74c3c;
|
| 281 |
+
color: white;
|
| 282 |
+
text-decoration: none;
|
| 283 |
+
border-radius: 3px;
|
| 284 |
+
font-size: 14px;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.paper-link:hover {
|
| 288 |
+
background-color: #c0392b;
|
| 289 |
+
}
|
| 290 |
</style>
|