Skip to content

Commit 378f727

Browse files
Merge branch 'main' into base-components
2 parents 5558224 + d0cef3a commit 378f727

File tree

7 files changed

+153
-28
lines changed

7 files changed

+153
-28
lines changed

.github/workflows/node.js.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: CI/CD for Server and Web
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
server:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '18.x'
21+
- name: Install dependencies for server
22+
run: |
23+
cd server
24+
npm install
25+
- name: Run server tests
26+
env:
27+
OPEN_API_KEY: ${{ secrets.OPEN_API_KEY }}
28+
run: |
29+
cd server
30+
npm test
31+
web:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Set up Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: '18.x'
39+
- name: Install dependencies for web
40+
run: |
41+
cd web
42+
npm install
43+
- name: Build web app
44+
run: |
45+
cd web
46+
npm run build
47+
# build:
48+
49+
# runs-on: ubuntu-latest
50+
51+
# strategy:
52+
# matrix:
53+
# node-version: [18.x, 20.x, 22.x]
54+
# # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
55+
56+
# steps:
57+
# - uses: actions/checkout@v4
58+
# - name: Use Node.js ${{ matrix.node-version }}
59+
# uses: actions/setup-node@v4
60+
# with:
61+
# node-version: ${{ matrix.node-version }}
62+
# cache: 'npm'
63+
# - run: npm ci
64+
# - run: npm run build --if-present
65+
# - run: npm test

server/src/gpt-controller.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export class GPTController {
4949
const loopPromises = Array.from({ length: 3 }, async (_) => {
5050
const assistant = await this.createAssistant(assistantParams);
5151
const thread = await this.createThread(threadMessage);
52-
// Run the assistant on the thread and get the prompt results. Think non-stream results are better?
52+
53+
// Run the assistant on the thread and get the prompt results
5354
let run = await GPTController.client.beta.threads.runs.createAndPoll(
5455
thread.id,
5556
{
@@ -61,25 +62,29 @@ export class GPTController {
6162
await GPTController.client.beta.threads.messages.list(
6263
run.thread_id,
6364
);
65+
// console.log("Tokens used: ", run.usage)
6466
var n = 1;
6567
for (const message of messages.data.reverse()) {
6668
if (message.content[0].type == "text") { // Need to check if the message content is text before parsing it
6769
var result = message.content[0].text.value;
70+
//console.log("Result: ", result) // FOR DEBUGGING
6871
if(n % 2 == 0) { // Every second message has the data values
69-
// console.log(`${message.role} > ${result}`); // FOR TESTING
70-
let preres = result.split("ø").map((s) => s.replace("\n", ""));
71-
console.log(preres)
72+
// console.log(`${message.role} > ${result}`); // FOR DEBUGGING
73+
let preres = result.split("ø").map((s) => s.replace("\n", "") && s.replace(/^\s+/g, "")); // Trimming each string
74+
console.log("After split: ", preres)
7275
var resvalues: GPTData = {
7376
paper_name: preres[0],
7477
year: parseInt(preres[1]),
75-
author: preres[2].split(",").map((s) => s.replace(/^\s+/g, "")),
78+
author: preres[2].split("").map((s) => s.replace(/^\s+/g, "")),
7679
part_no: preres[3],
7780
type: preres[4],
7881
manufacturer: preres[5],
7982
testing_location: <TestLocation>preres[6],
80-
testing_type: <Testing>preres[7], // TODO: preres[7] is a list ("TID, TID, DD") sometimes so the cast may fail
81-
// Produces weird output: "SEE【4:0†source】"
82-
data_type: 0 // TODO: add a prompt to get data_type
83+
84+
testing_type: <Testing>preres[7],
85+
// TODO: preres[7] is a list ("TID, TID, DD") if the paper has more than one testing type, so the cast may fail
86+
// Produces weird output: "SEE【4:0†source】"
87+
data_type: 0 // TODO: Need to be removed hear, from the defined data types and in db controller
8388
};
8489
console.log(resvalues)
8590
threadResults.push(resvalues);
@@ -105,6 +110,7 @@ export class GPTController {
105110
});
106111

107112
await Promise.all(fileThreads);
113+
console.log("All threads completed!");
108114
return results;
109115
}
110116

server/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ async function initializeSystem(): Promise<{dbController: DatabaseController, gp
4242
filename: "./database.db",
4343
driver: sqlite3.Database,
4444
});
45-
return {dbController: new DatabaseController(db), gptController: new GPTController(GPTModel.GPT3_5Turbo)};
45+
return {dbController: new DatabaseController(db), gptController: new GPTController(GPTModel.GPT4Turbo)};
4646
}
4747

4848
initializeSystem().then(({dbController, gptController}) => {
4949
app.use("/", exampleRouter);
5050
//app.use("/getTable", tableRouter)
5151
app.use("/api/dataRequest", cascadeRouter(dbController));
5252
app.use("/api/adminRequest", adminRouter(dbController, gptController));
53+
//FOR QUICKLY TESTING A PAPER: Uncomment paper to test it. Run "localhost:3000/parse" in a browser to parse the paper and see results in console
54+
// app.use("/parse", () => {
55+
// gptController.runGPTAnalysis(["./test/testfiles/SEE_in-flight_data_for_two_static_32KB_memories_on_high_earth_orbit.pdf"]);
56+
// // gptController.runGPTAnalysis(["./test/testfiles/A_radiation_tolerant_video_camera_for_high_total_dose_environments.pdf"]);
57+
// // gptController.runGPTAnalysis(["./test/testfiles/Radiation_effects_predicted_observed_and_compared_for_spacecraft_systems.pdf"]);
58+
// // gptController.runGPTAnalysis(["./test/testfiles/Solar_flare_proton_environment_for_estimating_downtime_of_spacecraft_CCDs.pdf"]);
59+
// // gptController.runGPTAnalysis(["./test/testfiles/slvk121.pdf"]);
60+
// });
5361

5462
app.listen(PORT, () => {
5563
console.log(`Server is running on ${PORT}`);

server/src/prompts.data.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
export const questions = [
22
"What is the title of the paper",
33
"Which year was the paper published",
4-
"What are all of the author's names, in the format (J. Doe) in a comma separated list",
5-
"What is the part number (or name if that is not available) of the part or parts studied by the paper",
6-
"What is the type of part or parts (eg, switching regulator) mentioned in the paper",
7-
"Who is the manufacturer",
4+
"What are all of the author's names, in the format (J. Doe) in a \"¶\" separated list",
5+
"What is the part no. of the part studied by the paper. If there is more than one, list them", // There can be more than one part no. in a paper
6+
"What is the type of part or parts (eg. switching regulator) mentioned in the paper. If there is more than one, list them",
7+
"Who is the manufacturer. If there is more than one, list them", // There can be more than one manufacturer in a paper if multiple parts are mentioned
88
"What is the type of testing location: Respond to this question with \"Terrestrial\" for a terrestial testing location, or \"Flight\" for a flight testing location",
9-
"What type of testing was done: Respond to this question with \"TID\" for Total Ionizing Dose testing, \"SEE\" for heavy ion, proton, laser, or neutron testing, or \"OTHER\" if you are not completely 100% sure"
9+
"What type of testing was done: Respond to this question with \"TID\" for Total Ionizing Dose testing, \"SEE\" for heavy ion, proton, laser, or neutron testing, \"DD\" for displacement damage testing, or \"OTHER\" if you are not completely 100% sure",
10+
// In-progress prompts, bad results
11+
// "If Total Ionizing Dose testing was performed, then list which of the following tests were done: Co60, ELDRS, Protons, Electrons. Otherwise, reply N/A",
12+
// "If single event effects testing using heavy ion, proton, laser, or neutron was done, then list which of the following tests were done: Reply SEU for single event upset, SET for single event transient, SEFI for single event functional interrupt, SEL for single event latchup, SEB for single event burnout, SEGR for gate rupture, Dose rate for dose rate. Otherwise, reply N/A",
13+
// "If displacement damage testing was performed, then list which of the following tests were conducted: Reply \"Protons\" for proton damage, \"Neutrons\" for neutron damage. Otherwise, reply N/A",
14+
15+
"Summarize the paper's test results in 3 lines",
16+
// "Reference the page number for each answer for the above questions in a \"¶\" separated list. If you are unable to give a page number or the answer is N/A, provide the answer N/A"
1017
];
1118

1219
export const prompt = `Please answer the following questions, as concisely as possible, and with a heavy emphasis on numbers instead of words.\n
13-
Use standard text and do not provide citations for each of your answers.
14-
Answer each question, and separate the answers with a "ø" character as a delimiter.
15-
If you are unable to answer the question accurately, provide the answer N/A.\n`;
20+
Use standard text and do not provide citations for any answer.
21+
If you are unable to answer the question accurately, provide the answer N/A.
22+
Answer each question, and separate the answers with a "ø" character as a delimiter.\n`;
1623

24+
// TODO: Need to incorporate the 3 sets of questions below, into prompts
1725
export const Other_targeted_questions = [
1826
"What type was the radiation source",
1927
"Were there any failures, if so, when?",

server/test/gpt-controller.test.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { GetQuery, InsertData, RadData } from '../src/types';
1+
import { GetQuery, InsertData, RadData } from "../src/types";
22

3-
import { GPTController } from '../src/gpt-controller';
4-
import { GPTModel } from '../src/enums';
5-
import fs from 'fs';
6-
import dotenv from 'dotenv';
7-
import path, { resolve } from 'path';
3+
import { GPTController } from "../src/gpt-controller";
4+
import { GPTModel } from "../src/enums";
5+
import fs from "fs";
6+
import dotenv from "dotenv";
7+
import path, { resolve } from "path";
88

99
async function initializeGPT(): Promise<GPTController> {
1010
return new GPTController(GPTModel.GPT3_5Turbo);
@@ -23,10 +23,47 @@ beforeAll(async () => {
2323
* Finish unit testing (using jest)
2424
***********/
2525

26-
test('Insertion of a paper with one author', async () => {
27-
const paper: string = path.resolve(__dirname,
28-
'./testfiles/SEE_in-flight_data_for_two_static_32KB_memories_on_high_earth_orbit.pdf');
26+
test("Insertion of a paper with one author", async () => {
27+
const paper: string = path.resolve(
28+
__dirname,
29+
"./testfiles/Radiation_Test_Dummy_File.pdf"
30+
);
2931
fs.readFileSync(paper);
3032

3133
await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
3234
}, 60000);
35+
36+
// test('Insertion of a paper with five authors', async () => {
37+
// const paper: string = path.resolve(__dirname,
38+
// './testfiles/SEE_in-flight_data_for_two_static_32KB_memories_on_high_earth_orbit.pdf');
39+
// fs.readFileSync(paper);
40+
41+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
42+
// }, 60000);
43+
// }, 90000); // More prompts = more time. Still not enough time... TODO: fix the test
44+
45+
// Below gpt tests commented out to reduce token usage during testing
46+
47+
// test('Insertion of a paper with two authors', async () => {
48+
// const paper: string = path.resolve(__dirname,
49+
// './testfiles/Solar_flare_proton_environment_for_estimating_downtime_of_spacecraft_CCDs.pdf');
50+
// fs.readFileSync(paper);
51+
52+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
53+
// }, 60000);
54+
55+
// test('Insertion of a paper with three authors. 1 of 2', async () => {
56+
// const paper: string = path.resolve(__dirname,
57+
// './testfiles/A_radiation_tolerant_video_camera_for_high_total_dose_environments.pdf');
58+
// fs.readFileSync(paper);
59+
60+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
61+
// }, 60000);
62+
63+
// test('Insertion of a paper with three authors. 2 of 2', async () => {
64+
// const paper: string = path.resolve(__dirname,
65+
// './testfiles/Radiation_effects_predicted_observed_and_compared_for_spacecraft_systems.pdf');
66+
// fs.readFileSync(paper);
67+
68+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
69+
// }, 60000);
1.66 KB
Binary file not shown.

web/src/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState as _useState } from "react";
12
import { Route, Routes, BrowserRouter } from "react-router-dom";
23
import "./App.css";
34
import CASCallback from "./auth/CASCallback";
@@ -8,8 +9,7 @@ import Nav from "./components/nav-bar/nav-bar";
89
import EditEntry from "./pages/edit-entry";
910

1011
function App() {
11-
//const [count, setCount] = useState(0);
12-
12+
//const [count, setCount] = useState(0);
1313
return (
1414
<BrowserRouter>
1515
<Nav />
@@ -50,6 +50,7 @@ function App() {
5050
</Routes>
5151
</BrowserRouter>
5252
);
53+
5354
}
5455

5556
export default App;

0 commit comments

Comments
 (0)