Skip to content

Commit 4d535ce

Browse files
committed
Fixed the ingestion process from end to end
1 parent d1c3bfe commit 4d535ce

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

ai-assistant/src/endpoints/establishRelations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class EstablishRelationsEndpoint extends ApiEndpoint {
5454
makeBodies(
5555
content: any
5656
): [EstablishRelationsEndpointRequestBody, EstablishRelationsEndpointResponseBody] {
57-
const requestBody = JSON.parse(content) as EstablishRelationsEndpointRequestBody;
57+
const requestBody = content as EstablishRelationsEndpointRequestBody;
5858
const responseBody: EstablishRelationsEndpointResponseBody = {
5959
status: 200,
6060
};

ingestion/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { exec } from "child_process"
22
import { v4 as uuid } from "uuid"
33

4+
import { REPO_URI } from "./constants"
45
import { insertDataIntoDB } from "./process/ingest/ingest"
56
import { Codebase } from "./process/prepare/codebase"
67
import { FileProcessor } from "./process/prepare/processor/file"

ingestion/src/process/ingest/ingest.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,42 @@ namespace Algorithms {
1212
const res = await fetch(`${RC_APP_URI}/purgeDB`, {
1313
method: "POST",
1414
headers: {
15+
accept: "application/json",
1516
"Content-Type": "application/json",
1617
},
1718
})
1819

1920
return res.status === 200
2021
} catch (e) {
21-
console.log(e);
22+
console.log(e)
2223
return false
2324
}
2425
}
2526

26-
export async function insertBatch(batchID: string, nodes: DBNode[]): Promise<boolean> {
27+
export async function insertBatch(
28+
batchID: string,
29+
nodes: DBNode[]
30+
): Promise<boolean> {
2731
try {
2832
const res = await fetch(`${RC_APP_URI}/ingest`, {
2933
method: "POST",
3034
headers: {
35+
accept: "application/json",
3136
"Content-Type": "application/json",
3237
},
3338
body: JSON.stringify({ nodes, batchID }),
3439
})
3540

3641
return res.status === 200
3742
} catch (e) {
38-
console.log(e);
43+
console.log(e)
3944
return false
4045
}
4146
}
4247

43-
export async function establishRelations(relations: DBNodeRelation[]): Promise<boolean> {
48+
export async function establishRelations(
49+
relations: DBNodeRelation[]
50+
): Promise<boolean> {
4451
try {
4552
const res = await fetch(`${RC_APP_URI}/establishRelations`, {
4653
method: "POST",
@@ -52,7 +59,7 @@ namespace Algorithms {
5259

5360
return res.status === 200
5461
} catch (e) {
55-
console.log(e);
62+
console.log(e)
5663
return false
5764
}
5865
}
@@ -87,11 +94,13 @@ export async function insertDataIntoDB(batchesDirPath: string) {
8794
const nodes = Object.values(JSON.parse(data)) as DBNode[]
8895

8996
for (const node of nodes)
90-
relations.push(...node.relations.map((relation) => ({
91-
source: node.id,
92-
target: relation.target,
93-
relation: relation.relation,
94-
})))
97+
relations.push(
98+
...node.relations.map((relation) => ({
99+
source: node.id,
100+
target: relation.target,
101+
relation: relation.relation,
102+
}))
103+
)
95104

96105
const success = await Algorithms.insertBatch(batchID, nodes)
97106
if (success) {
@@ -100,8 +109,7 @@ export async function insertDataIntoDB(batchesDirPath: string) {
100109
errorBatches.add(batchID)
101110
}
102111
}
103-
if (errorBatches.size > 0)
104-
console.log("❌ Error batches", errorBatches)
112+
if (errorBatches.size > 0) console.log("❌ Error batches", errorBatches)
105113

106114
// Establish relations
107115
const success = await Algorithms.establishRelations(relations)

ingestion/src/process/prepare/codebase.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
existsSync,
3-
mkdirSync,
4-
rmSync,
5-
writeFileSync
6-
} from "fs"
1+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs"
72
import { glob } from "glob"
83
import path from "path"
94
import { v4 as uuid } from "uuid"
@@ -55,7 +50,7 @@ export class Codebase {
5550
}
5651

5752
private prepareFilesMetadata() {
58-
const extensions = ["ts", "tsx", "js", "jsx"]
53+
const extensions = ["ts", "js"]
5954

6055
console.log(`🕒 Preparing metadata for files: *.${extensions.join(", *.")}`)
6156
{
@@ -107,7 +102,7 @@ export class Codebase {
107102
const jobs = files.map((x) => this._fileProcessor.process(x, nodes))
108103
await Promise.all(jobs)
109104
} catch (e) {
110-
console.log(e);
105+
console.log(e)
111106
console.error(`Error in processing ${start}-${end} files`)
112107
}
113108

0 commit comments

Comments
 (0)