Christopher S. Dunham commited on
Commit
773cbfc
·
1 Parent(s): 97c16a4

Updated requirements.txt. Updated server.py to pull a new environment variable, PAPER_FINAL_PATH_PREFIX, which provides the directory prefix for the path keys in paper_final.json, and is then read in at the point of format_papers_context() calls. Hoping that's enough to fix any dir issues with those files...

Browse files
example/backend/requirements.txt CHANGED
@@ -55,7 +55,7 @@ tenacity==9.1.2
55
  tokenizers==0.21.1
56
  torch==2.7.0
57
  tqdm==4.67.1
58
- transformers==4.51.3
59
  typer==0.15.2
60
  typing-inspection==0.4.0
61
  typing_extensions==4.13.2
 
55
  tokenizers==0.21.1
56
  torch==2.7.0
57
  tqdm==4.67.1
58
+ transformers==4.52.4
59
  typer==0.15.2
60
  typing-inspection==0.4.0
61
  typing_extensions==4.13.2
example/backend/server.py CHANGED
@@ -1,6 +1,7 @@
1
  from decouple import config
2
  from fastapi import FastAPI, HTTPException
3
  from fastapi.middleware.cors import CORSMiddleware
 
4
  from pydantic import BaseModel
5
  import uvicorn
6
  import json
@@ -16,6 +17,7 @@ from typing import List, Dict, Any, Optional
16
  VOYAGE_API_KEY = config("VOYAGE_API_KEY")
17
  EMBEDDINGS_FINAL = config("EMBEDDINGS_FINAL")
18
  PAPER_FINAL = config("PAPER_FINAL")
 
19
 
20
  # Initialize FastAPI
21
  app = FastAPI(title="BioPACIFIC MIP Research Paper RAG API")
@@ -100,7 +102,7 @@ def format_papers_context(papers, similarities):
100
  relevant_papers = []
101
  context = "Based on the following relevant papers:\n\n"
102
  for paper, similarity in zip(papers, similarities):
103
- original_paper = json.load(open(paper['path']))
104
  relevant_papers.append(original_paper)
105
  context += f"Title: {original_paper['title']}\n\n"
106
  context += f"Published Time: {original_paper['published_time']}\n\n"
 
1
  from decouple import config
2
  from fastapi import FastAPI, HTTPException
3
  from fastapi.middleware.cors import CORSMiddleware
4
+ from pathlib import Path
5
  from pydantic import BaseModel
6
  import uvicorn
7
  import json
 
17
  VOYAGE_API_KEY = config("VOYAGE_API_KEY")
18
  EMBEDDINGS_FINAL = config("EMBEDDINGS_FINAL")
19
  PAPER_FINAL = config("PAPER_FINAL")
20
+ PAPER_FINAL_PATH_PREFIX = config("PAPER_FINAL_PATH_PREFIX")
21
 
22
  # Initialize FastAPI
23
  app = FastAPI(title="BioPACIFIC MIP Research Paper RAG API")
 
102
  relevant_papers = []
103
  context = "Based on the following relevant papers:\n\n"
104
  for paper, similarity in zip(papers, similarities):
105
+ original_paper = json.load(open(Path(PAPER_FINAL_PATH_PREFIX, paper['path'])))
106
  relevant_papers.append(original_paper)
107
  context += f"Title: {original_paper['title']}\n\n"
108
  context += f"Published Time: {original_paper['published_time']}\n\n"
example/src/routes/+layout.svelte CHANGED
@@ -1,81 +1,81 @@
1
  <script>
2
- import '../app.css';
3
  </script>
4
 
5
  <div class="app">
6
- <header>
7
- <div class="header-content">
8
- <h1>Research Paper Assistant</h1>
9
- <nav>
10
- <a href="/">Home</a>
11
- <a href="/about">About</a>
12
- </nav>
13
- </div>
14
- </header>
15
-
16
- <main>
17
- <slot />
18
- </main>
19
-
20
- <footer>
21
- <p>&copy; {new Date().getFullYear()} Research Paper RAG System - Built with Svelte</p>
22
- </footer>
23
  </div>
24
 
25
  <style>
26
- .app {
27
- display: flex;
28
- flex-direction: column;
29
- min-height: 100vh;
30
- }
31
-
32
- header {
33
- background-color: #2c3e50;
34
- color: white;
35
- padding: 1rem 0;
36
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
37
- }
38
-
39
- .header-content {
40
- max-width: 1200px;
41
- margin: 0 auto;
42
- padding: 0 20px;
43
- display: flex;
44
- justify-content: space-between;
45
- align-items: center;
46
- }
47
-
48
- header h1 {
49
- margin: 0;
50
- font-size: 1.5rem;
51
- }
52
-
53
- nav {
54
- display: flex;
55
- gap: 20px;
56
- }
57
-
58
- nav a {
59
- color: white;
60
- text-decoration: none;
61
- font-weight: 500;
62
- padding: 5px;
63
- }
64
-
65
- nav a:hover {
66
- text-decoration: underline;
67
- }
68
-
69
- main {
70
- flex: 1;
71
- }
72
-
73
- footer {
74
- background-color: #f8f9fa;
75
- padding: 1rem 0;
76
- text-align: center;
77
- font-size: 0.875rem;
78
- color: #7f8c8d;
79
- border-top: 1px solid #ecf0f1;
80
- }
81
- </style>
 
1
  <script>
2
+ import '../app.css';
3
  </script>
4
 
5
  <div class="app">
6
+ <header>
7
+ <div class="header-content">
8
+ <h1>Research Paper Assistant</h1>
9
+ <nav>
10
+ <a href="/">Home</a>
11
+ <a href="/about">About</a>
12
+ </nav>
13
+ </div>
14
+ </header>
15
+
16
+ <main>
17
+ <slot />
18
+ </main>
19
+
20
+ <footer>
21
+ <p>&copy; {new Date().getFullYear()} Research Paper RAG System - Built with Svelte</p>
22
+ </footer>
23
  </div>
24
 
25
  <style>
26
+ .app {
27
+ display: flex;
28
+ flex-direction: column;
29
+ min-height: 100vh;
30
+ }
31
+
32
+ header {
33
+ background-color: #2c3e50;
34
+ color: white;
35
+ padding: 1rem 0;
36
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
37
+ }
38
+
39
+ .header-content {
40
+ max-width: 1200px;
41
+ margin: 0 auto;
42
+ padding: 0 20px;
43
+ display: flex;
44
+ justify-content: space-between;
45
+ align-items: center;
46
+ }
47
+
48
+ header h1 {
49
+ margin: 0;
50
+ font-size: 1.5rem;
51
+ }
52
+
53
+ nav {
54
+ display: flex;
55
+ gap: 20px;
56
+ }
57
+
58
+ nav a {
59
+ color: white;
60
+ text-decoration: none;
61
+ font-weight: 500;
62
+ padding: 5px;
63
+ }
64
+
65
+ nav a:hover {
66
+ text-decoration: underline;
67
+ }
68
+
69
+ main {
70
+ flex: 1;
71
+ }
72
+
73
+ footer {
74
+ background-color: #f8f9fa;
75
+ padding: 1rem 0;
76
+ text-align: center;
77
+ font-size: 0.875rem;
78
+ color: #7f8c8d;
79
+ border-top: 1px solid #ecf0f1;
80
+ }
81
+ </style>
example/src/routes/+page.svelte CHANGED
@@ -1,246 +1,261 @@
1
- <script>
2
- import { onMount } from 'svelte';
3
-
4
- // State variables
5
- let question = '';
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
15
- const examples = [
16
- "Can you recommend some papers about perovskite which are published in last 5 years?",
17
- "Explain the concept of attention mechanisms in deep learning.",
18
- "What are the main challenges in few-shot learning?"
19
- ];
20
-
21
- // Function to handle form submission
22
- async function handleSubmit() {
23
- if (!question.trim()) return;
24
-
25
- isLoading = true;
26
- response = '';
27
-
28
- try {
29
- const res = await fetch('/api/query', {
30
- method: 'POST',
31
- headers: {
32
- 'Content-Type': 'application/json'
33
- },
34
- body: JSON.stringify({ message: question })
35
- });
36
-
37
- if (!res.ok) throw new Error('Failed to get response');
38
-
39
- const data = await res.json();
40
-
41
- // Update state with response data
42
- response = data.response;
43
- papers = [
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) {
61
- console.error('Error:', error);
62
- response = `An error occurred: ${error.message}`;
63
- } finally {
64
- isLoading = false;
65
- }
66
- }
67
-
68
- // Function to use an example question
69
- function useExample(example) {
70
- question = example;
71
- }
72
  </script>
73
 
74
  <svelte:head>
75
- <title>RAG-Enhanced Llama-3.1 Chat Interface</title>
76
  </svelte:head>
77
 
78
  <main class="container">
79
- <h1>RAG-Enhanced Llama-3.1 Chat Interface</h1>
80
- <p>Ask questions about papers in the database. The system will find relevant papers and use them to generate informed responses.</p>
81
-
82
- <div class="query-section">
83
- <textarea
84
- bind:value={question}
85
- rows="3"
86
- placeholder="Enter your question..."
87
- aria-label="Question"
88
- ></textarea>
89
-
90
- <button on:click={handleSubmit} disabled={isLoading}>
91
- {isLoading ? 'Processing...' : 'Submit'}
92
- </button>
93
- </div>
94
-
95
- <div class="examples-section">
96
- <h3>Examples:</h3>
97
- <div class="examples-list">
98
- {#each examples as example}
99
- <button class="example-button" on:click={() => useExample(example)}>
100
- {example}
101
- </button>
102
- {/each}
103
- </div>
104
- </div>
105
-
106
- {#if response}
107
- <div class="response-section">
108
- <h2>Generated Response</h2>
109
- <div class="response-box">
110
- {response}
111
- </div>
112
- </div>
113
- {/if}
114
-
115
- {#if papers[0].title}
116
- <div class="papers-section">
117
- <h2>Relevant Papers</h2>
118
- <div class="papers-grid">
119
- {#each papers as paper, i}
120
- <div class="paper-card">
121
- <h3>Paper {i+1}</h3>
122
- <h4>{paper.title}</h4>
123
- <p class="similarity">{paper.similarity}</p>
124
- <div class="abstract">
125
- <h5>Abstract</h5>
126
- <p>{paper.abstract}</p>
127
- </div>
128
- </div>
129
- {/each}
130
- </div>
131
- </div>
132
- {/if}
 
 
 
133
  </main>
134
 
135
  <style>
136
- .container {
137
- max-width: 1200px;
138
- margin: 0 auto;
139
- padding: 20px;
140
- font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
141
- }
142
-
143
- h1 {
144
- color: #2c3e50;
145
- margin-bottom: 10px;
146
- }
147
-
148
- .query-section {
149
- margin: 20px 0;
150
- }
151
-
152
- textarea {
153
- width: 100%;
154
- padding: 12px;
155
- border: 1px solid #ddd;
156
- border-radius: 4px;
157
- font-size: 16px;
158
- margin-bottom: 10px;
159
- font-family: inherit;
160
- }
161
-
162
- button {
163
- background-color: #3498db;
164
- color: white;
165
- border: none;
166
- padding: 10px 20px;
167
- border-radius: 4px;
168
- cursor: pointer;
169
- font-size: 16px;
170
- transition: background-color 0.3s;
171
- }
172
-
173
- button:hover:not(:disabled) {
174
- background-color: #2980b9;
175
- }
176
-
177
- button:disabled {
178
- background-color: #95a5a6;
179
- cursor: not-allowed;
180
- }
181
-
182
- .examples-section {
183
- margin: 20px 0;
184
- }
185
-
186
- .examples-list {
187
- display: flex;
188
- flex-direction: column;
189
- gap: 10px;
190
- }
191
-
192
- .example-button {
193
- background-color: #ecf0f1;
194
- color: #2c3e50;
195
- text-align: left;
196
- padding: 10px;
197
- }
198
-
199
- .response-section, .papers-section {
200
- margin-top: 30px;
201
- }
202
-
203
- .response-box {
204
- background-color: #f8f9fa;
205
- padding: 15px;
206
- border-radius: 4px;
207
- border-left: 4px solid #3498db;
208
- white-space: pre-wrap;
209
- }
210
-
211
- .papers-grid {
212
- display: grid;
213
- grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
214
- gap: 20px;
215
- margin-top: 20px;
216
- }
217
-
218
- .paper-card {
219
- border: 1px solid #ddd;
220
- border-radius: 4px;
221
- padding: 15px;
222
- background-color: #fff;
223
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
224
- }
225
-
226
- .similarity {
227
- font-size: 14px;
228
- color: #7f8c8d;
229
- margin: 5px 0;
230
- }
231
-
232
- .abstract {
233
- margin-top: 10px;
234
- }
235
-
236
- .abstract h5 {
237
- margin-bottom: 5px;
238
- }
239
-
240
- .abstract p {
241
- font-size: 14px;
242
- line-height: 1.5;
243
- max-height: 200px;
244
- overflow-y: auto;
245
- }
246
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+
4
+ // State variables
5
+ let question = '';
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
15
+ const examples = [
16
+ 'Can you recommend some papers about perovskite which are published in last 5 years?',
17
+ 'Explain the concept of attention mechanisms in deep learning.',
18
+ 'What are the main challenges in few-shot learning?'
19
+ ];
20
+
21
+ // Function to handle form submission
22
+ async function handleSubmit() {
23
+ if (!question.trim()) return;
24
+
25
+ isLoading = true;
26
+ response = '';
27
+
28
+ try {
29
+ const res = await fetch('/api/query', {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/json'
33
+ },
34
+ body: JSON.stringify({ message: question })
35
+ });
36
+
37
+ if (!res.ok) throw new Error('Failed to get response');
38
+
39
+ const data = await res.json();
40
+
41
+ // Update state with response data
42
+ response = data.response;
43
+ papers = [
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) {
61
+ console.error('Error:', error);
62
+ response = `An error occurred: ${error.message}`;
63
+ } finally {
64
+ isLoading = false;
65
+ }
66
+ }
67
+
68
+ // Function to use an example question
69
+ function useExample(example: string) {
70
+ question = example;
71
+ }
72
  </script>
73
 
74
  <svelte:head>
75
+ <title>RAG-Enhanced Llama-3.1 Chat Interface</title>
76
  </svelte:head>
77
 
78
  <main class="container">
79
+ <h1>RAG-Enhanced Llama-3.1 Chat Interface</h1>
80
+ <p>
81
+ Ask questions about papers in the database. The system will find relevant papers and use them to
82
+ generate informed responses.
83
+ </p>
84
+
85
+ <div class="query-section">
86
+ <textarea
87
+ bind:value={question}
88
+ rows="3"
89
+ placeholder="Enter your question..."
90
+ aria-label="Question"
91
+ ></textarea>
92
+
93
+ <button on:click={handleSubmit} disabled={isLoading}>
94
+ {isLoading ? 'Processing...' : 'Submit'}
95
+ </button>
96
+ </div>
97
+
98
+ <div class="examples-section">
99
+ <h3>Examples:</h3>
100
+ <div class="examples-list">
101
+ {#each examples as example}
102
+ <button class="example-button" on:click={() => useExample(example)}>
103
+ {example}
104
+ </button>
105
+ {/each}
106
+ </div>
107
+ </div>
108
+
109
+ {#if response}
110
+ <div class="response-section">
111
+ <h2>Generated Response</h2>
112
+ <div class="response-box">
113
+ {response}
114
+ </div>
115
+ </div>
116
+ {/if}
117
+
118
+ {#if papers[0].title}
119
+ <div class="papers-section">
120
+ <h2>Relevant Papers</h2>
121
+ <div class="papers-grid">
122
+ {#each papers as paper, i}
123
+ <div class="paper-card">
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>
130
+ </div>
131
+ </div>
132
+ {/each}
133
+ </div>
134
+ </div>
135
+ {/if}
136
  </main>
137
 
138
  <style>
139
+ .container {
140
+ max-width: 1200px;
141
+ margin: 0 auto;
142
+ padding: 20px;
143
+ font-family:
144
+ system-ui,
145
+ -apple-system,
146
+ BlinkMacSystemFont,
147
+ 'Segoe UI',
148
+ Roboto,
149
+ Oxygen,
150
+ Ubuntu,
151
+ Cantarell,
152
+ 'Open Sans',
153
+ 'Helvetica Neue',
154
+ sans-serif;
155
+ }
156
+
157
+ h1 {
158
+ color: #2c3e50;
159
+ margin-bottom: 10px;
160
+ }
161
+
162
+ .query-section {
163
+ margin: 20px 0;
164
+ }
165
+
166
+ textarea {
167
+ width: 100%;
168
+ padding: 12px;
169
+ border: 1px solid #ddd;
170
+ border-radius: 4px;
171
+ font-size: 16px;
172
+ margin-bottom: 10px;
173
+ font-family: inherit;
174
+ }
175
+
176
+ button {
177
+ background-color: #3498db;
178
+ color: white;
179
+ border: none;
180
+ padding: 10px 20px;
181
+ border-radius: 4px;
182
+ cursor: pointer;
183
+ font-size: 16px;
184
+ transition: background-color 0.3s;
185
+ }
186
+
187
+ button:hover:not(:disabled) {
188
+ background-color: #2980b9;
189
+ }
190
+
191
+ button:disabled {
192
+ background-color: #95a5a6;
193
+ cursor: not-allowed;
194
+ }
195
+
196
+ .examples-section {
197
+ margin: 20px 0;
198
+ }
199
+
200
+ .examples-list {
201
+ display: flex;
202
+ flex-direction: column;
203
+ gap: 10px;
204
+ }
205
+
206
+ .example-button {
207
+ background-color: #ecf0f1;
208
+ color: #2c3e50;
209
+ text-align: left;
210
+ padding: 10px;
211
+ }
212
+
213
+ .response-section,
214
+ .papers-section {
215
+ margin-top: 30px;
216
+ }
217
+
218
+ .response-box {
219
+ background-color: #f8f9fa;
220
+ padding: 15px;
221
+ border-radius: 4px;
222
+ border-left: 4px solid #3498db;
223
+ white-space: pre-wrap;
224
+ }
225
+
226
+ .papers-grid {
227
+ display: grid;
228
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
229
+ gap: 20px;
230
+ margin-top: 20px;
231
+ }
232
+
233
+ .paper-card {
234
+ border: 1px solid #ddd;
235
+ border-radius: 4px;
236
+ padding: 15px;
237
+ background-color: #fff;
238
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
239
+ }
240
+
241
+ .similarity {
242
+ font-size: 14px;
243
+ color: #7f8c8d;
244
+ margin: 5px 0;
245
+ }
246
+
247
+ .abstract {
248
+ margin-top: 10px;
249
+ }
250
+
251
+ .abstract h5 {
252
+ margin-bottom: 5px;
253
+ }
254
+
255
+ .abstract p {
256
+ font-size: 14px;
257
+ line-height: 1.5;
258
+ max-height: 200px;
259
+ overflow-y: auto;
260
+ }
261
+ </style>
example/src/routes/about/+page.svelte CHANGED
@@ -1,118 +1,121 @@
1
- <script>
2
- // Any specific about page logic can go here
3
  </script>
4
 
5
  <svelte:head>
6
- <title>About - Research Paper Assistant</title>
7
  </svelte:head>
8
 
9
  <div class="container">
10
- <h1>About This Project</h1>
11
-
12
- <div class="card mb-4">
13
- <div class="card-body">
14
- <h2>RAG-Enhanced Research Paper Assistant</h2>
15
- <p>
16
- This application uses a Retrieval-Augmented Generation (RAG) system to provide intelligent responses
17
- to research queries. The system searches through a database of scientific papers to find relevant
18
- information and uses the Llama-3.1 language model to generate responses.
19
- </p>
20
- </div>
21
- </div>
22
-
23
- <div class="mb-4">
24
- <h2>How It Works</h2>
25
- <p>Our system follows these steps to answer your research questions:</p>
26
-
27
- <ol>
28
- <li>Your question is converted into a vector embedding using VoyageAI's embedding model.</li>
29
- <li>This embedding is compared against our database of paper embeddings to find the most relevant papers.</li>
30
- <li>The top papers are retrieved and provided as context to the Llama-3.1 language model.</li>
31
- <li>The model generates a response based on the relevant papers and your question.</li>
32
- <li>Both the response and the relevant papers are displayed to you.</li>
33
- </ol>
34
- </div>
35
-
36
- <div class="mb-4">
37
- <h2>Technology Stack</h2>
38
- <div class="tech-grid">
39
- <div class="tech-item">
40
- <h3>Frontend</h3>
41
- <ul>
42
- <li>Svelte & SvelteKit</li>
43
- <li>Modern CSS</li>
44
- </ul>
45
- </div>
46
-
47
- <div class="tech-item">
48
- <h3>Backend</h3>
49
- <ul>
50
- <li>Python</li>
51
- <li>OpenScholar/Llama-3.1_OpenScholar-8B</li>
52
- <li>VoyageAI Embeddings</li>
53
- <li>FAISS Vector Database</li>
54
- </ul>
55
- </div>
56
-
57
- <div class="tech-item">
58
- <h3>Data</h3>
59
- <ul>
60
- <li>Scientific paper database</li>
61
- <li>Pre-computed vector embeddings</li>
62
- </ul>
63
- </div>
64
- </div>
65
- </div>
66
-
67
- <div>
68
- <h2>Using The System</h2>
69
- <p>
70
- To use the system, simply enter your research question in the input field on the homepage and click "Submit".
71
- Try to be specific with your questions to get the most relevant results. You can also use one of the example
72
- questions to get started.
73
- </p>
74
- <p>
75
- The system will display both the AI-generated response and the top relevant papers that were used to inform
76
- that response. You can explore these papers further by reading their abstracts.
77
- </p>
78
- </div>
 
 
 
79
  </div>
80
 
81
  <style>
82
- .tech-grid {
83
- display: grid;
84
- grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
85
- gap: 20px;
86
- margin-top: 20px;
87
- }
88
-
89
- .tech-item {
90
- background-color: #f8f9fa;
91
- border-radius: 8px;
92
- padding: 20px;
93
- border-left: 4px solid #3498db;
94
- }
95
-
96
- .tech-item h3 {
97
- margin-bottom: 10px;
98
- color: #2c3e50;
99
- }
100
-
101
- .tech-item ul {
102
- list-style-type: disc;
103
- padding-left: 20px;
104
- }
105
-
106
- .tech-item li {
107
- margin-bottom: 5px;
108
- }
109
-
110
- ol {
111
- padding-left: 20px;
112
- margin: 15px 0;
113
- }
114
-
115
- ol li {
116
- margin-bottom: 10px;
117
- }
118
- </style>
 
1
+ <script lang="ts">
2
+ // Any specific about page logic can go here
3
  </script>
4
 
5
  <svelte:head>
6
+ <title>About - Research Paper Assistant</title>
7
  </svelte:head>
8
 
9
  <div class="container">
10
+ <h1>About This Project</h1>
11
+
12
+ <div class="card mb-4">
13
+ <div class="card-body">
14
+ <h2>RAG-Enhanced Research Paper Assistant</h2>
15
+ <p>
16
+ This application uses a Retrieval-Augmented Generation (RAG) system to provide intelligent
17
+ responses to research queries. The system searches through a database of scientific papers
18
+ to find relevant information and uses the Llama-3.1 language model to generate responses.
19
+ </p>
20
+ </div>
21
+ </div>
22
+
23
+ <div class="mb-4">
24
+ <h2>How It Works</h2>
25
+ <p>Our system follows these steps to answer your research questions:</p>
26
+
27
+ <ol>
28
+ <li>Your question is converted into a vector embedding using VoyageAI's embedding model.</li>
29
+ <li>
30
+ This embedding is compared against our database of paper embeddings to find the most
31
+ relevant papers.
32
+ </li>
33
+ <li>The top papers are retrieved and provided as context to the Llama-3.1 language model.</li>
34
+ <li>The model generates a response based on the relevant papers and your question.</li>
35
+ <li>Both the response and the relevant papers are displayed to you.</li>
36
+ </ol>
37
+ </div>
38
+
39
+ <div class="mb-4">
40
+ <h2>Technology Stack</h2>
41
+ <div class="tech-grid">
42
+ <div class="tech-item">
43
+ <h3>Frontend</h3>
44
+ <ul>
45
+ <li>Svelte & SvelteKit</li>
46
+ <li>Modern CSS</li>
47
+ </ul>
48
+ </div>
49
+
50
+ <div class="tech-item">
51
+ <h3>Backend</h3>
52
+ <ul>
53
+ <li>Python</li>
54
+ <li>OpenScholar/Llama-3.1_OpenScholar-8B</li>
55
+ <li>VoyageAI Embeddings</li>
56
+ <li>FAISS Vector Database</li>
57
+ </ul>
58
+ </div>
59
+
60
+ <div class="tech-item">
61
+ <h3>Data</h3>
62
+ <ul>
63
+ <li>Scientific paper database</li>
64
+ <li>Pre-computed vector embeddings</li>
65
+ </ul>
66
+ </div>
67
+ </div>
68
+ </div>
69
+
70
+ <div>
71
+ <h2>Using The System</h2>
72
+ <p>
73
+ To use the system, simply enter your research question in the input field on the homepage and
74
+ click "Submit". Try to be specific with your questions to get the most relevant results. You
75
+ can also use one of the example questions to get started.
76
+ </p>
77
+ <p>
78
+ The system will display both the AI-generated response and the top relevant papers that were
79
+ used to inform that response. You can explore these papers further by reading their abstracts.
80
+ </p>
81
+ </div>
82
  </div>
83
 
84
  <style>
85
+ .tech-grid {
86
+ display: grid;
87
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
88
+ gap: 20px;
89
+ margin-top: 20px;
90
+ }
91
+
92
+ .tech-item {
93
+ background-color: #f8f9fa;
94
+ border-radius: 8px;
95
+ padding: 20px;
96
+ border-left: 4px solid #3498db;
97
+ }
98
+
99
+ .tech-item h3 {
100
+ margin-bottom: 10px;
101
+ color: #2c3e50;
102
+ }
103
+
104
+ .tech-item ul {
105
+ list-style-type: disc;
106
+ padding-left: 20px;
107
+ }
108
+
109
+ .tech-item li {
110
+ margin-bottom: 5px;
111
+ }
112
+
113
+ ol {
114
+ padding-left: 20px;
115
+ margin: 15px 0;
116
+ }
117
+
118
+ ol li {
119
+ margin-bottom: 10px;
120
+ }
121
+ </style>
example/src/routes/api/query/+server.js DELETED
@@ -1,68 +0,0 @@
1
- import { json } from '@sveltejs/kit';
2
-
3
- // Replace this with your actual backend URL when deployed
4
- const PYTHON_BACKEND_URL = 'http://localhost:8000/api/generate';
5
-
6
- /**
7
- * @type {import('@sveltejs/kit').RequestHandler}
8
- */
9
- export async function POST({ request }) {
10
- try {
11
- const { message } = await request.json();
12
-
13
- if (!message?.trim()) {
14
- return json({
15
- error: 'No message provided'
16
- }, { status: 400 });
17
- }
18
-
19
- // Option 1: Forward to Python backend (if running separately)
20
- try {
21
- const response = await fetch(PYTHON_BACKEND_URL, {
22
- method: 'POST',
23
- headers: {
24
- 'Content-Type': 'application/json',
25
- },
26
- body: JSON.stringify({ message }),
27
- });
28
-
29
- if (!response.ok) {
30
- throw new Error(`Backend responded with status: ${response.status}`);
31
- }
32
-
33
- const data = await response.json();
34
- return json(data);
35
-
36
- } catch (error) {
37
- console.error('Error communicating with Python backend:', error);
38
-
39
- // Fallback to dummy data if backend is not available (for development purposes)
40
- // Remove this in production and handle errors appropriately
41
- return json({
42
- response: "This is a fallback response. The Python backend appears to be offline. Please ensure your backend server is running.",
43
- papers: [
44
- {
45
- title: "Sample Paper 1",
46
- abstract: "This is a placeholder abstract for development purposes only.",
47
- similarity: "Similarity Score: 0.000"
48
- },
49
- {
50
- title: "Sample Paper 2",
51
- abstract: "This is a placeholder abstract for development purposes only.",
52
- similarity: "Similarity Score: 0.000"
53
- },
54
- {
55
- title: "Sample Paper 3",
56
- abstract: "This is a placeholder abstract for development purposes only.",
57
- similarity: "Similarity Score: 0.000"
58
- }
59
- ]
60
- });
61
- }
62
- } catch (error) {
63
- console.error('Error processing request:', error);
64
- return json({
65
- error: 'Internal server error'
66
- }, { status: 500 });
67
- }
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
example/src/routes/settings/+layout.svelte DELETED
@@ -1,81 +0,0 @@
1
- <script>
2
- import '../app.css';
3
- </script>
4
-
5
- <div class="app">
6
- <header>
7
- <div class="header-content">
8
- <h1>Research Paper Assistant</h1>
9
- <nav>
10
- <a href="/">Home</a>
11
- <a href="/about">About</a>
12
- </nav>
13
- </div>
14
- </header>
15
-
16
- <main>
17
- <slot />
18
- </main>
19
-
20
- <footer>
21
- <p>&copy; {new Date().getFullYear()} Research Paper RAG System - Built with Svelte</p>
22
- </footer>
23
- </div>
24
-
25
- <style>
26
- .app {
27
- display: flex;
28
- flex-direction: column;
29
- min-height: 100vh;
30
- }
31
-
32
- header {
33
- background-color: #2c3e50;
34
- color: white;
35
- padding: 1rem 0;
36
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
37
- }
38
-
39
- .header-content {
40
- max-width: 1200px;
41
- margin: 0 auto;
42
- padding: 0 20px;
43
- display: flex;
44
- justify-content: space-between;
45
- align-items: center;
46
- }
47
-
48
- header h1 {
49
- margin: 0;
50
- font-size: 1.5rem;
51
- }
52
-
53
- nav {
54
- display: flex;
55
- gap: 20px;
56
- }
57
-
58
- nav a {
59
- color: white;
60
- text-decoration: none;
61
- font-weight: 500;
62
- padding: 5px;
63
- }
64
-
65
- nav a:hover {
66
- text-decoration: underline;
67
- }
68
-
69
- main {
70
- flex: 1;
71
- }
72
-
73
- footer {
74
- background-color: #f8f9fa;
75
- padding: 1rem 0;
76
- text-align: center;
77
- font-size: 0.875rem;
78
- color: #7f8c8d;
79
- border-top: 1px solid #ecf0f1;
80
- }
81
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
example/src/routes/settings/+page.svelte DELETED
@@ -1,54 +0,0 @@
1
- <script lang="ts">
2
- /**
3
- * Developed by: Christopher S. Dunham
4
- * Contact: csdunham@ucsb.edu, csdunham@protonmail.com
5
- *
6
- * Copyright © Reagents of the University of California,
7
- * BioPACIFIC MIP, and their affiliates.
8
- *
9
- * This source code is licensed according to the LICENSE file
10
- * found in the root directory of this source tree and on the
11
- * project page on Github.
12
- *
13
- */
14
- </script>
15
-
16
- <section class="section">
17
- <h2 class="header">Settings Home</h2>
18
- <p class="text">Here, you can find various settings associated with your ELN account.</p>
19
- <h4 class="header">Current Features</h4>
20
- <ol class="list">
21
- <li>
22
- The ability to transfer ownership of your entire ELN notebook to a user of your choosing (via
23
- the Ownership tab)
24
- </li>
25
- <li>
26
- The ability to "publish" (make publicly accessible to the BioPACIFIC MIP Laboratory
27
- Information Management System (LIMS)) the data of selected notebooks and/or pages
28
- </li>
29
- </ol>
30
- <p>This page will fill with more features as users request them.</p>
31
- </section>
32
-
33
- <style lang="scss">
34
- .section {
35
- display: flex;
36
- flex-direction: column;
37
- align-items: center;
38
- margin-left: 10px;
39
- }
40
-
41
- .header {
42
- text-align: center;
43
- }
44
-
45
- .text {
46
- text-align: center;
47
- max-width: 60%;
48
- }
49
-
50
- .list {
51
- color: #003660;
52
- max-width: 60%;
53
- }
54
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
example/src/routes/settings/publishing/+page.server.ts DELETED
@@ -1,331 +0,0 @@
1
- /**
2
- * Developed by: Christopher S. Dunham
3
- * Contact: csdunham@ucsb.edu, csdunham@protonmail.com
4
- *
5
- * Copyright © Reagents of the University of California,
6
- * BioPACIFIC MIP, and their affiliates.
7
- *
8
- * This source code is licensed according to the LICENSE file
9
- * found in the root directory of this source tree and on the
10
- * project page on Github.
11
- *
12
- */
13
-
14
- import { fail } from '@sveltejs/kit';
15
- import { API_ENDPOINT_ROOT, LIMS_API_URL } from '$env/static/private';
16
- import {
17
- createFileTree,
18
- getAllPages,
19
- getNotebookStructure
20
- } from '$lib/utilities/notebooks/utilities';
21
-
22
- export async function load({ locals }) {
23
- const userID = locals.user.userId;
24
-
25
- // Request body for API call to get all notebooks.
26
- const getAllNotebooksBody: GetAllNotebooksRequestBody = {
27
- user_id: userID
28
- };
29
-
30
- // Request body for API call to get all pages.
31
- const getAllNotebookPagesBody: GetAllPagesRequestBody = {
32
- user_id: userID
33
- };
34
-
35
- // Get user's Notebooks
36
- const allNotebooksForUser = await getNotebookStructure(getAllNotebooksBody);
37
-
38
- // Get user's Pages
39
- const allPagesForUser = await getAllPages(getAllNotebookPagesBody);
40
-
41
- // Create the file tree (pagesAndNotebooks object)
42
- const pagesAndNotebooks = await createFileTree(
43
- allNotebooksForUser as FormattedNotebookResponse[],
44
- allPagesForUser as PageResponse[]
45
- );
46
-
47
- return {
48
- userNotebooks: pagesAndNotebooks
49
- };
50
- }
51
-
52
- export const actions = {
53
- publishAllUserPages: async ({ locals, request }) => {
54
- const data = await request.formData();
55
- const user_id = locals.user.userId;
56
- console.log('publishAllUserPages, Data:');
57
- console.log(data);
58
-
59
- try {
60
- const published_at = new Date(); // time for published_at
61
- const body: PublishRetractAllRequestBody = {
62
- is_private: false,
63
- published_at,
64
- user_id
65
- };
66
-
67
- console.log(`publishAllUserPages Body:`);
68
- console.log(body);
69
-
70
- // Complete ELN ops first, then perform LIMS ops
71
- const response = await fetch(
72
- `${API_ENDPOINT_ROOT}/publish-all-pages`,
73
- // "http://127.0.0.1:8000/api/save-notebook",
74
- {
75
- body: JSON.stringify(body),
76
- headers: {
77
- 'Content-Type': 'application/json'
78
- },
79
- method: 'POST',
80
- mode: 'cors'
81
- }
82
- );
83
-
84
- const resData: GenericApiResponse = await response.json();
85
- console.log(`Response (publishAllUserPages, ELN): ${JSON.stringify(resData, null, 4)}`);
86
-
87
- console.log(`Status: ${resData.status} type ${typeof resData.status}`);
88
-
89
- if (resData.status !== '200 OK')
90
- return fail(422, {
91
- error: true,
92
- message: `ELN publish all pages operation failed. Aborting LIMS effort.`
93
- });
94
-
95
- const limsResponse = await fetch(
96
- `${LIMS_API_URL}/eln-publish-all-pages/`,
97
- // "http://127.0.0.1:7878/api-lims/transfer-ownership",
98
- {
99
- body: JSON.stringify(body),
100
- headers: {
101
- 'Content-Type': 'application/json'
102
- },
103
- method: 'POST',
104
- mode: 'cors'
105
- }
106
- );
107
-
108
- const resDataLims = await limsResponse.json();
109
-
110
- console.log(`Response (publishAllUserPages, LIMS): ${JSON.stringify(resDataLims, null, 4)}`);
111
- } catch (error: any) {
112
- return fail(422, {
113
- error: true,
114
- message: `Error when publishing all ELN pages: ${error.message}`
115
- });
116
- }
117
- },
118
-
119
- publishSelectedNotebookPages: async ({ locals, request }) => {
120
- const data = await request.formData();
121
- const page_ids = data.getAll('page_ids') as unknown as UUID[];
122
- const user_id = locals.user.userId;
123
- console.log('publishSelectedNotebookPages, Data:');
124
- console.log(data);
125
-
126
- console.log(`page_ids`);
127
- console.log(page_ids);
128
-
129
- try {
130
- const published_at = new Date(); // time for published_at
131
- const body: PublishRetractSelectRequestBody = {
132
- is_private: false,
133
- page_ids,
134
- published_at,
135
- user_id
136
- };
137
-
138
- console.log(`publishSelectedNotebookPages Body:`);
139
- console.log(body);
140
-
141
- // Complete ELN ops first, then perform LIMS ops
142
- const response = await fetch(
143
- `${API_ENDPOINT_ROOT}/publish-select-pages`,
144
- // "http://127.0.0.1:8000/api/save-notebook",
145
- {
146
- body: JSON.stringify(body),
147
- headers: {
148
- 'Content-Type': 'application/json'
149
- },
150
- method: 'POST',
151
- mode: 'cors'
152
- }
153
- );
154
-
155
- const resData: GenericApiResponse = await response.json();
156
- console.log(
157
- `Response (publishSelectedNotebookPages, ELN): ${JSON.stringify(resData, null, 4)}`
158
- );
159
-
160
- console.log(`Status: ${resData.status} type ${typeof resData.status}`);
161
-
162
- if (resData.status !== '200 OK')
163
- return fail(422, {
164
- error: true,
165
- message: `ELN publish select pages operations failed. Aborting LIMS effort.`
166
- });
167
-
168
- const limsResponse = await fetch(
169
- `${LIMS_API_URL}/eln-publish-select-pages/`,
170
- // "http://127.0.0.1:7878/api-lims/transfer-ownership",
171
- {
172
- body: JSON.stringify(body),
173
- headers: {
174
- 'Content-Type': 'application/json'
175
- },
176
- method: 'POST',
177
- mode: 'cors'
178
- }
179
- );
180
-
181
- const resDataLims = await limsResponse.json();
182
-
183
- console.log(
184
- `Response (publishSelectedNotebookPages, LIMS): ${JSON.stringify(resDataLims, null, 4)}`
185
- );
186
- } catch (error: any) {
187
- return fail(422, {
188
- error: true,
189
- message: `Error when publishing selected ELN pages: ${error.message}`
190
- });
191
- }
192
- },
193
-
194
- retractAllUserPages: async ({ locals, request }) => {
195
- const data = await request.formData();
196
- const user_id = locals.user.userId;
197
- console.log('retractAllUserPages, Data:');
198
- console.log(data);
199
-
200
- try {
201
- const published_at = new Date(); // time for published_at
202
- const body: PublishRetractAllRequestBody = {
203
- is_private: true,
204
- published_at,
205
- user_id
206
- };
207
-
208
- console.log(`retractAllUserPages Body:`);
209
- console.log(body);
210
-
211
- // Complete ELN ops first, then perform LIMS ops
212
- const response = await fetch(
213
- `${API_ENDPOINT_ROOT}/retract-all-pages`,
214
- // "http://127.0.0.1:8000/api/save-notebook",
215
- {
216
- body: JSON.stringify(body),
217
- headers: {
218
- 'Content-Type': 'application/json'
219
- },
220
- method: 'POST',
221
- mode: 'cors'
222
- }
223
- );
224
-
225
- const resData: GenericApiResponse = await response.json();
226
- console.log(`Response (retractAllUserPages, ELN): ${JSON.stringify(resData, null, 4)}`);
227
-
228
- console.log(`Status: ${resData.status} type ${typeof resData.status}`);
229
-
230
- if (resData.status !== '200 OK')
231
- return fail(422, {
232
- error: true,
233
- message: `ELN retract all pages operation failed. Aborting LIMS effort.`
234
- });
235
-
236
- const limsResponse = await fetch(
237
- `${LIMS_API_URL}/eln-retract-all-pages/`,
238
- // "http://127.0.0.1:7878/api-lims/transfer-ownership",
239
- {
240
- body: JSON.stringify(body),
241
- headers: {
242
- 'Content-Type': 'application/json'
243
- },
244
- method: 'POST',
245
- mode: 'cors'
246
- }
247
- );
248
-
249
- const resDataLims = await limsResponse.json();
250
-
251
- console.log(`Response (retractAllUserPages, LIMS): ${JSON.stringify(resDataLims, null, 4)}`);
252
- } catch (error: any) {
253
- return fail(422, {
254
- error: true,
255
- message: `Error when retracting all ELN pages: ${error.message}`
256
- });
257
- }
258
- },
259
-
260
- retractSelectedNotebookPages: async ({ locals, request }) => {
261
- const data = await request.formData();
262
- const page_ids = data.getAll('page_ids') as unknown as UUID[];
263
- const user_id = locals.user.userId;
264
- console.log('retractSelectedNotebookPages, Data:');
265
- console.log(data);
266
-
267
- try {
268
- const published_at = null; // time for published_at
269
- const body: PublishRetractSelectRequestBody = {
270
- is_private: true,
271
- page_ids,
272
- published_at,
273
- user_id
274
- };
275
-
276
- console.log(`retractSelectedNotebookPages Body:`);
277
- console.log(body);
278
-
279
- // Complete ELN ops first, then perform LIMS ops
280
- const response = await fetch(
281
- `${API_ENDPOINT_ROOT}/retract-select-pages`,
282
- // "http://127.0.0.1:8000/api/save-notebook",
283
- {
284
- body: JSON.stringify(body),
285
- headers: {
286
- 'Content-Type': 'application/json'
287
- },
288
- method: 'POST',
289
- mode: 'cors'
290
- }
291
- );
292
-
293
- const resData: GenericApiResponse = await response.json();
294
- console.log(
295
- `Response (retractSelectedNotebookPages, ELN): ${JSON.stringify(resData, null, 4)}`
296
- );
297
-
298
- console.log(`Status: ${resData.status} type ${typeof resData.status}`);
299
-
300
- if (resData.status !== '200 OK')
301
- return fail(422, {
302
- error: true,
303
- message: `ELN retract select pages operations failed. Aborting LIMS effort.`
304
- });
305
-
306
- const limsResponse = await fetch(
307
- `${LIMS_API_URL}/eln-retract-select-pages/`,
308
- // "http://127.0.0.1:7878/api-lims/transfer-ownership",
309
- {
310
- body: JSON.stringify(body),
311
- headers: {
312
- 'Content-Type': 'application/json'
313
- },
314
- method: 'POST',
315
- mode: 'cors'
316
- }
317
- );
318
-
319
- const resDataLims = await limsResponse.json();
320
-
321
- console.log(
322
- `Response (retractSelectedNotebookPages, LIMS): ${JSON.stringify(resDataLims, null, 4)}`
323
- );
324
- } catch (error: any) {
325
- return fail(422, {
326
- error: true,
327
- message: `Error when retracting selected ELN pages: ${error.message}`
328
- });
329
- }
330
- }
331
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
example/src/routes/settings/publishing/+page.svelte DELETED
@@ -1,464 +0,0 @@
1
- <script lang="ts">
2
- /**
3
- * Developed by: Christopher S. Dunham
4
- * Contact: csdunham@ucsb.edu, csdunham@protonmail.com
5
- *
6
- * Copyright © Reagents of the University of California,
7
- * BioPACIFIC MIP, and their affiliates.
8
- *
9
- * This source code is licensed according to the LICENSE file
10
- * found in the root directory of this source tree and on the
11
- * project page on Github.
12
- *
13
- */
14
- import { enhance } from '$app/forms';
15
- import type { ActionData, PageData } from './$types';
16
- import { fade } from 'svelte/transition';
17
-
18
- interface Props {
19
- data: PageData;
20
- form: ActionData;
21
- }
22
-
23
- let { data, form }: Props = $props();
24
-
25
- type NotebookResponse = {
26
- notebook_id: UUID;
27
- name: string;
28
- parent_id?: UUID;
29
- };
30
-
31
- type PageResponse = {
32
- id: UUID;
33
- name: string;
34
- contents: object;
35
- parent_notebook_id: UUID;
36
- is_private: boolean;
37
- published_at: string | null; // really a timezone-aware datetime
38
- };
39
-
40
- type FormattedNotebookResponse = NotebookResponse & {
41
- pages: PageResponse[];
42
- };
43
-
44
- /**
45
- * Type Guard. Checks whether the obj is a NotebookResponse
46
- * @param obj
47
- * @returns
48
- */
49
- function isNotebooksArray(obj: any): obj is FormattedNotebookResponse[] {
50
- return (obj as FormattedNotebookResponse[]).length > 0;
51
- }
52
-
53
- let notebooks = $state(isNotebooksArray(data.userNotebooks) ? data.userNotebooks : null);
54
- let publishRetractMode: 'publish' | 'retract' | null = $state(null);
55
- let allOrSelect: 'all' | 'select' | null = $state(null);
56
- let showSuccessMsg: boolean = $state(false);
57
- let enablePublishOrRetractAll: boolean = $state(false);
58
- let enablePublishOrRetractSelected: boolean = $state(false);
59
- let selectedNotebook: FormattedNotebookResponse | null = $state(notebooks ? notebooks[0] : null);
60
- let selectedNotebookId: UUID | null = $state(notebooks ? notebooks[0].notebook_id : null);
61
-
62
- const publishAllFormAct = '/settings/publishing?/publishAllUserPages';
63
- const publishSelectFormAct = '/settings/publishing?/publishSelectedNotebookPages';
64
- const retractAllFormAct = '/settings/publishing?/retractAllUserPages';
65
- const retractSelectFormAct = '/settings/publishing?/retractSelectedNotebookPages';
66
-
67
- $inspect(selectedNotebook);
68
-
69
- /**
70
- * Check whether the input matches the operational mode.
71
- */
72
- function checkInput() {
73
- const confirm = (document.getElementById('publish-confirm-input') as HTMLInputElement)?.value;
74
-
75
- if (confirm === publishRetractMode?.toUpperCase()) {
76
- return true;
77
- }
78
- return false;
79
- }
80
-
81
- /**
82
- * Check whether the value of the selection matches an existing notebook name
83
- * @param selectedNotebookId
84
- */
85
- function checkSelect(selectedNotebookId: UUID | null) {
86
- const confirm = (document.getElementById('publish-confirm-selection') as HTMLInputElement)
87
- ?.value as string;
88
-
89
- const notebook = notebooks?.find((notebook) => {
90
- if (notebook.notebook_id === selectedNotebookId) return notebook;
91
- });
92
-
93
- if (notebook?.name === confirm) return true;
94
- return false;
95
- }
96
-
97
- /**
98
- * Get the selected notebook from 'notebooks', based on the selectedNotebookId,
99
- * and return it.
100
- * @param selectedNotebookId
101
- */
102
- function getSelectedNotebook(selectedNotebookId: UUID | null) {
103
- const notebook = notebooks?.find((notebook) => {
104
- if (notebook.notebook_id === selectedNotebookId) return notebook;
105
- });
106
- if (notebook) return notebook;
107
- return null;
108
- }
109
- </script>
110
-
111
- <section class="section">
112
- <h2 class="header">Publishing & Retraction</h2>
113
- <h3 class="header">What is 'publishing'?</h3>
114
- <p class="text">
115
- Publishing in the ELN means taking the data in your ELN notebooks and making them publicly
116
- available, such as through the BioPACIFIC MIP Laboratory Information Management System (LIMS)
117
- Data Viewer. This means that other registered users of the BioPACIFIC MIP will be able to view
118
- published experiment data in the Data Viewer. Likewise, Retracting in the ELN does the exact
119
- opposite of publishing, reverting the specified content to a private state that is only visible
120
- to you.
121
- </p>
122
- <p class="text">
123
- Individual notebook pages can be published (or retracted) by clicking the ‘Publish’ (or
124
- ‘Retract’) button at the top right of the page. However, you can also publish (or retract) the
125
- entire contents of your account (i.e. all notebooks and associated pages), as well as all pages
126
- of a selected notebook.
127
- </p>
128
- <p class="text">
129
- All BioPACIFIC MIP users agree to submit data and/or a small volume of materials developed as
130
- part of their BioPACIFIC MIP research to the BioPACIFIC MIP digital ecosystem and/or libraries.
131
- Submission of data and/or materials may be made after publication or filing of IP through the
132
- appropriate channels, but within one year of a project’s end date. The materials and data in the
133
- BioPACIFIC MIP libraries are to be used only for non-commercial research and educational
134
- purposes.
135
- </p>
136
- <p class="text">
137
- Before you publish (or retract) content from your ELN, please make sure you understand the
138
- ramifications behind making information public or private. Consult with your BioPACIFIC MIP
139
- Project Scientist and/or User Coordinator for more information.
140
- </p>
141
- <h3 class="header">Publish/Retract Pages</h3>
142
- {#if publishRetractMode === 'publish' || publishRetractMode === 'retract'}
143
- <div class="btn-group">
144
- <button
145
- class="btn"
146
- onclick={() => {
147
- allOrSelect = 'all';
148
- enablePublishOrRetractAll = false;
149
- enablePublishOrRetractSelected = false;
150
- }}
151
- >
152
- {publishRetractMode === 'publish'
153
- ? 'Publish All?'
154
- : publishRetractMode === 'retract'
155
- ? 'Retract All?'
156
- : ''}
157
- </button>
158
- <button
159
- class="btn"
160
- onclick={() => {
161
- allOrSelect = 'select';
162
- enablePublishOrRetractAll = false;
163
- enablePublishOrRetractSelected = false;
164
- }}
165
- >
166
- {publishRetractMode === 'publish'
167
- ? 'Publish Notebook?'
168
- : publishRetractMode === 'retract'
169
- ? 'Retract Notebook?'
170
- : ''}
171
- </button>
172
- </div>
173
-
174
- {#if allOrSelect === 'all'}
175
- <div class="container">
176
- <h3 class="header">
177
- {publishRetractMode === 'publish'
178
- ? 'Publish'
179
- : publishRetractMode === 'retract'
180
- ? 'Retract'
181
- : null}
182
- All Pages
183
- </h3>
184
- <p class="text">
185
- {publishRetractMode === 'publish'
186
- ? 'Publish'
187
- : publishRetractMode === 'retract'
188
- ? 'Retract'
189
- : null}
190
- <strong>all</strong> of the pages from <strong>all</strong> of your notebooks.
191
- </p>
192
- <form
193
- id="publish-retract-all"
194
- class="form"
195
- method="POST"
196
- action={publishRetractMode === 'publish'
197
- ? publishAllFormAct
198
- : publishRetractMode === 'retract'
199
- ? retractAllFormAct
200
- : null}
201
- use:enhance={({ formData }) => {
202
- return async ({ update, result }) => {
203
- await update();
204
- if (result.type === 'success') {
205
- enablePublishOrRetractAll = false;
206
- allOrSelect = null;
207
- showSuccessMsg = true;
208
- }
209
- };
210
- }}
211
- >
212
- <input
213
- id="publish-confirm-input"
214
- class="input"
215
- type="text"
216
- placeholder="Type {publishRetractMode === 'publish'
217
- ? 'PUBLISH'
218
- : publishRetractMode === 'retract'
219
- ? 'RETRACT'
220
- : ''} to {publishRetractMode === 'publish'
221
- ? 'publish'
222
- : publishRetractMode === 'retract'
223
- ? 'retract'
224
- : ''} all pages."
225
- autocomplete="off"
226
- onkeyup={() => {
227
- enablePublishOrRetractAll = checkInput();
228
- }}
229
- />
230
- {#if enablePublishOrRetractAll}
231
- <i transition:fade class="ri-thumb-up-fill"></i>
232
- {/if}
233
- <button
234
- class="btn"
235
- class:disabled={!enablePublishOrRetractAll}
236
- disabled={!enablePublishOrRetractAll}
237
- >
238
- {publishRetractMode === 'publish'
239
- ? 'Publish All'
240
- : publishRetractMode === 'retract'
241
- ? 'Retract All'
242
- : ''}
243
- </button>
244
- </form>
245
- </div>
246
- {:else if allOrSelect === 'select'}
247
- <div class="container">
248
- <h3 class="header">
249
- {publishRetractMode === 'publish'
250
- ? 'Publish'
251
- : publishRetractMode === 'retract'
252
- ? 'Retract'
253
- : null}
254
- Pages from the Selected Notebook
255
- </h3>
256
- {#if notebooks}
257
- <form
258
- id="publish-retract-all"
259
- class="form"
260
- method="POST"
261
- action={publishRetractMode === 'publish'
262
- ? publishSelectFormAct
263
- : publishRetractMode === 'retract'
264
- ? retractSelectFormAct
265
- : null}
266
- use:enhance={({ formData }) => {
267
- return async ({ update, result }) => {
268
- await update();
269
- if (result.type === 'success') {
270
- enablePublishOrRetractSelected = false;
271
- allOrSelect = null;
272
- showSuccessMsg = true;
273
- }
274
- };
275
- }}
276
- >
277
- <select
278
- name="notebook"
279
- class="select"
280
- bind:value={selectedNotebookId}
281
- onchange={() => {
282
- selectedNotebook = getSelectedNotebook(selectedNotebookId);
283
- enablePublishOrRetractSelected = false;
284
- }}
285
- >
286
- {#each notebooks as notebook}
287
- {#if notebook.pages.length > 0}
288
- <option value={notebook.notebook_id}>{notebook.name}</option>
289
- {/if}
290
- {/each}
291
- </select>
292
- <input
293
- id="publish-confirm-selection"
294
- class="input"
295
- type="text"
296
- placeholder="Type the notebook name to {publishRetractMode === 'publish'
297
- ? 'publish'
298
- : publishRetractMode === 'retract'
299
- ? 'retract'
300
- : ''} your selection."
301
- autocomplete="off"
302
- onkeyup={() => (enablePublishOrRetractSelected = checkSelect(selectedNotebookId))}
303
- />
304
- {#if selectedNotebook && selectedNotebook.pages.length > 0}
305
- {#each selectedNotebook.pages as page}
306
- <input name="page_ids" type="hidden" value={page.id} />
307
- {/each}
308
- {/if}
309
- {#if enablePublishOrRetractSelected}
310
- <i transition:fade class="ri-thumb-up-fill"></i>
311
- {/if}
312
- <button
313
- class="btn"
314
- class:disabled={!enablePublishOrRetractSelected}
315
- disabled={!enablePublishOrRetractSelected}
316
- type="submit"
317
- >
318
- {publishRetractMode === 'publish'
319
- ? 'Publish Pages from Selected Notebook'
320
- : publishRetractMode === 'retract'
321
- ? 'Retract Pages from Selected Notebook'
322
- : ''}
323
- </button>
324
- </form>
325
- {/if}
326
- </div>
327
- {/if}
328
- {#if showSuccessMsg}
329
- <p class="text-success">You've successfully {publishRetractMode}ed your notebook pages!</p>
330
- {/if}
331
- <button
332
- class="btn"
333
- onclick={() => {
334
- publishRetractMode = null;
335
- allOrSelect = null;
336
- showSuccessMsg = false;
337
- }}
338
- >
339
- Cancel
340
- </button>
341
- {:else}
342
- <div class="btn-group">
343
- <button class="btn" onclick={() => (publishRetractMode = 'publish')}>Publish Pages</button>
344
- <button class="btn" onclick={() => (publishRetractMode = 'retract')}>Retract Pages</button>
345
- </div>
346
- {/if}
347
- </section>
348
-
349
- <style lang="scss">
350
- /* Mixins */
351
- @mixin icons {
352
- margin: 0px 2px 0px 2px;
353
- padding: 0px 0px 0px 0px;
354
- border: none;
355
- border-radius: 5px;
356
- width: 2.5rem;
357
- height: 2.5rem;
358
- display: flex;
359
- justify-content: center;
360
- align-items: center;
361
- }
362
-
363
- @mixin formElementDims {
364
- width: 400px;
365
- height: 30px;
366
- margin: 0px 0px 5px 0px;
367
- }
368
-
369
- .section {
370
- display: flex;
371
- flex-direction: column;
372
- align-items: center;
373
- margin-left: 10px;
374
- }
375
-
376
- .container {
377
- margin: 10px 0px 0px 0px;
378
- display: flex;
379
- flex-direction: column;
380
- align-items: center;
381
- // gap: 10px;
382
- width: 100%;
383
- }
384
-
385
- .header {
386
- text-align: center;
387
- margin-bottom: 10px;
388
- }
389
-
390
- .text {
391
- margin: 0px 0px 10px 0px;
392
- text-align: center;
393
- max-width: 60%;
394
- }
395
-
396
- .form {
397
- margin-top: 10px;
398
- display: flex;
399
- flex-direction: column;
400
- align-items: center;
401
- gap: 10px;
402
- }
403
-
404
- .input {
405
- @include formElementDims;
406
- border: 1px solid #003660;
407
- border-radius: 5px;
408
- text-align: center;
409
- }
410
-
411
- .select {
412
- @include formElementDims;
413
- background-color: white;
414
- border: 1px solid #003660;
415
- border-radius: 5px;
416
- text-align: center;
417
- }
418
-
419
- .btn-group {
420
- margin-top: 20px;
421
- display: flex;
422
- flex-direction: column;
423
- // gap: 10px;
424
- }
425
-
426
- .btn {
427
- @include formElementDims;
428
- color: white;
429
- background-color: #003660;
430
- border: 1px solid #003660;
431
- border-radius: 5px;
432
- width: 300px;
433
- }
434
-
435
- .btn:hover {
436
- cursor: pointer;
437
- color: #fec11b;
438
- }
439
-
440
- .btn:disabled {
441
- background-color: #00366071;
442
- }
443
-
444
- .btn:disabled:hover {
445
- cursor: not-allowed;
446
- color: white;
447
- }
448
-
449
- .text-success {
450
- font-size: large;
451
- font-weight: 600;
452
- color: #3bbaff;
453
- margin-bottom: 10px;
454
- }
455
-
456
- /* Icons */
457
- .ri-thumb-up-fill {
458
- @include icons;
459
- background-image: url('$lib/assets/icons/RemixIcon_Svg_v3.3.0/icons/System/thumb-up-fill.svg');
460
- // Hex: #3bbaff
461
- filter: brightness(0) saturate(100%) invert(80%) sepia(44%) saturate(5917%) hue-rotate(173deg)
462
- brightness(101%) contrast(101%);
463
- }
464
- </style>