Skip to content

Commit 0efc7f6

Browse files
author
Samantha Mathan
committed
runGptAnalysis now parses the results from assistant. Need to add prompt for data type
1 parent 91796d8 commit 0efc7f6

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/gpt-controller.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GPTModel } from "./enums";
33
import { FileObject } from "openai/resources";
44
import path, { resolve } from "path";
55
import fs from "fs";
6-
import { AssistantBody, GPTResponse, ThreadMessage, GPTData } from "./types";
6+
import { AssistantBody, GPTResponse, ThreadMessage, GPTData, Testing, TestLocation } from "./types";
77
import { prompt, questions } from "./prompts.data";
88
import { threadId } from "worker_threads";
99

@@ -61,14 +61,42 @@ export class GPTController {
6161
await GPTController.client.beta.threads.messages.list(
6262
run.thread_id,
6363
);
64+
var n = 1;
6465
for (const message of messages.data.reverse()) {
6566
// Need to check if the message content is text before parsing it
6667
if (message.content[0].type == "text") {
67-
result = message.content[0].text.value; // TODO: parse this result, then verify with user or add to database
68-
console.log(`${message.role} > ${result}`);
69-
//console.log();
70-
// TODO: push the parsed results to the threadResults as a GPTData object
71-
threadResults.push();
68+
result = message.content[0].text.value;
69+
var resvalues: GPTData = { // Initialize GPT data object
70+
paper_name: "",
71+
year: 0,
72+
author: [],
73+
part_no: "",
74+
type: [],
75+
manufacturer: "",
76+
testing_location: "Terrestrial",
77+
testing_type: "TID",
78+
data_type: 0
79+
}
80+
// Every second message has the data values
81+
if(n % 2 == 0) {
82+
// console.log(`${message.role} > ${result}`);
83+
let preres = result.split("ø").map((s) => s.replace("\n", ""));
84+
// console.log(preres)
85+
resvalues = {
86+
paper_name: preres[0],
87+
year: parseInt(preres[1]),
88+
author: preres[2].split(","),
89+
part_no: preres[3],
90+
type: preres[4].split("¶"),
91+
manufacturer: preres[5],
92+
testing_location: <TestLocation>preres[6],
93+
testing_type: <Testing>preres[7], // TODO: this gives a list ("TID, TID, DD") sometimes so the cast may fail
94+
data_type: 0 // TODO: add a prompt to get data_type
95+
};
96+
console.log(resvalues)
97+
threadResults.push(resvalues);
98+
}
99+
n++;
72100
}
73101
}
74102
} else {

src/prompts.data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export const questions = [
2+
"What is the title of the paper",
3+
"Which year was the paper published",
24
"What are all of the author's names, in the format (J. Doe) in a list like this ['J. Doe', 'R. Austin']",
35
"What is the Part No. or name if that is not available",
46
'What is the type of part (eg, switching regulator), if there are multiple part numbers listed, list them all and seperate them with a "¶"',
57
"Who is the manufacturer",
8+
'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',
69
'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',
710
];
811

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type GPTData = {
5353
year: number;
5454
author: string[];
5555
part_no: string;
56-
type: string;
56+
type: string[];
5757
manufacturer: string;
5858
testing_location: TestLocation;
5959
testing_type: Testing;

0 commit comments

Comments
 (0)