Skip to content

Commit ddc4823

Browse files
committed
Added more gpt analysis unit tests. Improved prompts so that answers are given for every question for better result parsing
1 parent 45366f6 commit ddc4823

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

server/src/gpt-controller.ts

Lines changed: 8 additions & 6 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
{
@@ -67,19 +68,20 @@ export class GPTController {
6768
var result = message.content[0].text.value;
6869
if(n % 2 == 0) { // Every second message has the data values
6970
// console.log(`${message.role} > ${result}`); // FOR TESTING
70-
let preres = result.split("ø").map((s) => s.replace("\n", ""));
71+
let preres = result.split("ø").map((s) => s.replace("\n", "") && s.replace(/^\s+/g, "")); // Trimming each string
7172
console.log(preres)
7273
var resvalues: GPTData = {
7374
paper_name: preres[0],
7475
year: parseInt(preres[1]),
75-
author: preres[2].split(",").map((s) => s.replace(/^\s+/g, "")),
76+
author: preres[2].split("").map((s) => s.replace(/^\s+/g, "")),
7677
part_no: preres[3],
7778
type: preres[4],
7879
manufacturer: preres[5],
7980
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
81+
testing_type: <Testing>preres[7],
82+
// TODO: preres[7] is a list ("TID, TID, DD") if the paper has more than one testing type, so the cast may fail
83+
// Produces weird output: "SEE【4:0†source】"
84+
data_type: 0 // TODO: add a prompt to get number data_type. What is it?
8385
};
8486
console.log(resvalues)
8587
threadResults.push(resvalues);

server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ 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}) => {

server/src/prompts.data.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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",
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", // Returns same thing as part type if part name is mentioned
66
"What is the type of part or parts (eg, switching regulator) mentioned in the paper",
77
"Who is the manufacturer",
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",
@@ -11,8 +11,8 @@ export const questions = [
1111

1212
export const prompt = `Please answer the following questions, as concisely as possible, and with a heavy emphasis on numbers instead of words.\n
1313
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`;
14+
If you are unable to answer the question accurately, provide the answer N/A.
15+
Answer each question, and separate the answers with a "ø" character as a delimiter.\n`;
1616

1717
export const Other_targeted_questions = [
1818
"What type was the radiation source",

server/test/gpt-controller.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,37 @@ test("Insertion of a paper with one author", async () => {
3232

3333
await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
3434
}, 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+
44+
// Below gpt tests commented out to reduce token usage during testing
45+
46+
// test('Insertion of a paper with two authors', async () => {
47+
// const paper: string = path.resolve(__dirname,
48+
// './testfiles/Solar_flare_proton_environment_for_estimating_downtime_of_spacecraft_CCDs.pdf');
49+
// fs.readFileSync(paper);
50+
51+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
52+
// }, 60000);
53+
54+
// test('Insertion of a paper with three authors. 1 of 2', async () => {
55+
// const paper: string = path.resolve(__dirname,
56+
// './testfiles/A_radiation_tolerant_video_camera_for_high_total_dose_environments.pdf');
57+
// fs.readFileSync(paper);
58+
59+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
60+
// }, 60000);
61+
62+
// test('Insertion of a paper with three authors. 2 of 2', async () => {
63+
// const paper: string = path.resolve(__dirname,
64+
// './testfiles/Radiation_effects_predicted_observed_and_compared_for_spacecraft_systems.pdf');
65+
// fs.readFileSync(paper);
66+
67+
// await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
68+
// }, 60000);

0 commit comments

Comments
 (0)