Skip to content

Commit 89b8909

Browse files
author
Samantha Mathan
committed
Removed redundant code from gptAnalysis, modified prompts so that parsing result to GPTData type is more correct
1 parent 9df8d00 commit 89b8909

File tree

3 files changed

+17
-46
lines changed

3 files changed

+17
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ each time.
4545
Simply run the below command in the `server` directory
4646

4747
```sh
48-
npm run start:dev
48+
npm run start-dev
4949
```
5050

5151
This will start a development server with the `ts-node` and `nodemon` packages. This allows for easy development via cold-reloading. `ts-node` allows for running the typescript code without the need for compliation while `nodemon` monitors for changes to any `.ts` or `.js` files.

server/src/gpt-controller.ts

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class GPTController {
4545
//console.log(`Thread Message: ${threadMessage}`)
4646
// Create the three threads for each paper
4747
let threadResults: GPTData[] = [];
48+
//const loopPromises = Array.from({ length: 1 }, async (_) => { // FOR TESTING
4849
const loopPromises = Array.from({ length: 3 }, async (_) => {
4950
const assistant = await this.createAssistant(assistantParams);
5051
const thread = await this.createThread(threadMessage);
@@ -55,43 +56,30 @@ export class GPTController {
5556
assistant_id: assistant.id,
5657
},
5758
);
58-
var result = "";
5959
if (run.status == "completed") {
6060
const messages =
6161
await GPTController.client.beta.threads.messages.list(
6262
run.thread_id,
6363
);
6464
var n = 1;
6565
for (const message of messages.data.reverse()) {
66-
// Need to check if the message content is text before parsing it
67-
if (message.content[0].type == "text") {
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}`);
66+
if (message.content[0].type == "text") { // Need to check if the message content is text before parsing it
67+
var result = message.content[0].text.value;
68+
if(n % 2 == 0) { // Every second message has the data values
69+
// console.log(`${message.role} > ${result}`); // FOR TESTING
8370
let preres = result.split("ø").map((s) => s.replace("\n", ""));
84-
// console.log(preres)
85-
resvalues = {
71+
console.log(preres)
72+
var resvalues: GPTData = {
8673
paper_name: preres[0],
8774
year: parseInt(preres[1]),
88-
author: preres[2].split(","),
75+
author: preres[2].split(",").map((s) => s.replace(/^\s+/g, "")),
8976
part_no: preres[3],
9077
type: preres[4],
9178
manufacturer: preres[5],
9279
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
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
9583
};
9684
console.log(resvalues)
9785
threadResults.push(resvalues);
@@ -112,25 +100,8 @@ export class GPTController {
112100
pass_2: threadResults[1],
113101
pass_3: threadResults[2],
114102
};
115-
116103
//console.log(threadFinal)
117104
results.push(threadFinal);
118-
119-
// TODO: Need to add the stream and and return it, not working yet.
120-
// Will be uncommented to implement
121-
122-
/*
123-
const stream = await GPTController.client.beta.threads.runs.create(
124-
thread.id,
125-
{assistant_id: assistant.id, stream: true}
126-
127-
)
128-
129-
let response = '';
130-
for await (const chunk of stream) {
131-
response += chunk.choices[0]?.delta?.content || "";
132-
}
133-
*/
134105
});
135106

136107
await Promise.all(fileThreads);

server/src/prompts.data.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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 list like this ['J. Doe', 'R. Austin']",
5-
"What is the Part No. or name if that is not available",
6-
'What is the type of part (eg, switching regulator), if there are multiple part numbers listed, list them all and seperate them with a "¶"',
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",
77
"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',
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',
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",
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"
1010
];
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

0 commit comments

Comments
 (0)