Skip to content

Commit 786b914

Browse files
committed
Added a test for the runGPTAnalysis function. Needs MAJOR prompr revision
1 parent 076e5ab commit 786b914

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

src/gpt-controller.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class GPTController {
2020
this.model = model;
2121
}
2222

23-
async runGPTAnalysis(files: Express.Multer.File[]): Promise<GPTResponse[]> {
23+
async runGPTAnalysis(filePaths: string[]): Promise<GPTResponse[]> {
2424
const assistantParams: AssistantBody = {
2525
name: "Radiation Effects Researcher",
2626
instructions:
@@ -34,14 +34,15 @@ export class GPTController {
3434
const results: GPTResponse[] = [];
3535

3636
// Upload files and create threads concurrently
37-
const fileThreads = files.map(async (file: Express.Multer.File) => {
37+
const fileThreads = filePaths.map(async (filePath: string) => {
3838
// Pretty sure we need an assistant for each thread to keep it separated.
39-
const fileID = await this.uploadFile(file.path);
39+
const fileID = await this.uploadFile(filePath);
4040
const threadMessage: ThreadMessage = {
4141
role: "assistant",
4242
content: prompt + questions,
4343
attachments: [{ file_id: fileID, tools: [{ type: "file_search" }] }],
4444
};
45+
console.log(`Thread Message: ${threadMessage}`)
4546
// Create the three threads for each paper
4647
let threadResults: GPTData[] = []
4748
for (let i = 0; i < 3; i++) {
@@ -74,13 +75,14 @@ export class GPTController {
7475
console.log(run.status);
7576
}
7677
}
78+
/*
7779
const threadFinal: GPTResponse = {
7880
pass_1: threadResults[0],
7981
pass_2: threadResults[1],
8082
pass_3: threadResults[2]
8183
}
8284
results.push(threadFinal);
83-
85+
8486
// TODO: Need to add the stream and and return it, not working yet.
8587
// Will be uncommented to implement
8688

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import sqlite3 from "sqlite3";
33
import cors from "cors";
44
import bodyParser from "body-parser";
55
import { open, Database } from "sqlite";
6+
import dotenv from "dotenv"
67

78
// Import routers
89

@@ -16,7 +17,7 @@ import { GPTModel } from "./enums";
1617

1718
const app = express();
1819
const PORT = process.env.PORT || 3000; // Use environment variable if available, otherwise default to 3000
19-
20+
dotenv.config();
2021
/* In the future this will be used to ensure that only requests from certain domains are accepted
2122
const corsOptions = {
2223
origin: (origin: string | undefined, callback: (err: Error | null, allowed: boolean) => void) => {

src/prompts.data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const questions = [
2-
"What is the first author's name, in the format (J. Doe)",
2+
"What are all of the author's names, in the format (J. Doe) in a list like this ['J. Doe', 'R. Austin']",
33
"What is the Part No. or name if that is not available",
44
'What is the type of part (eg, switching regulator), if there are multiple part numbers listed, list them all and seperate them with a "¶"',
55
"Who is the manufacturer",

src/routes/admin-router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ async function insertRows(
5050
}
5151

5252
async function parsePapers(files: any, gptController: GPTController): Promise<GPTResponse[]> {
53-
gptController.runGPTAnalysis(files)
53+
const fileList: string[] = files.forEach((file: any) => file.path)
54+
gptController.runGPTAnalysis(fileList)
5455
const temp: GPTResponse[] = [];
5556
return temp;
5657
}

test/gpt-controller.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { GetQuery, InsertData, RadData } from '../src/types';
2+
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';
8+
9+
async function initializeGPT(): Promise<GPTController> {
10+
return new GPTController(GPTModel.GPT3_5Turbo);
11+
}
12+
13+
let testGPT: GPTController;
14+
15+
// Initialize the database once before all tests
16+
beforeAll(async () => {
17+
dotenv.config();
18+
testGPT = await initializeGPT();
19+
});
20+
21+
/**********
22+
* TODO
23+
* Finish unit testing (using jest)
24+
***********/
25+
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');
29+
fs.readFileSync(paper);
30+
31+
await expect(testGPT.runGPTAnalysis([paper])).resolves.not.toThrow();
32+
}, 60000);

0 commit comments

Comments
 (0)