Skip to content

Commit 03c128b

Browse files
committed
wip to fix node module
1 parent fbc5286 commit 03c128b

File tree

15 files changed

+5345
-243
lines changed

15 files changed

+5345
-243
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

examples/express-together-llamaindex/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
"name": "restack-examples-ts-express",
33
"version": "0.0.1",
44
"description": "Basic Express example",
5-
"main": "server.ts",
65
"scripts": {
7-
"start": "ts-node src/server.ts",
8-
"start.watch": "nodemon src/server.ts",
9-
"dev": "pnpm start.watch",
10-
"build": "tsc --build",
6+
"dev": "tsx watch --include src src/server.ts",
117
"clean": "rm -rf node_modules",
128
"docker:build": "docker build -t restack-express .",
139
"docker:run": "docker run -p 8000:8000 restack-express",
@@ -28,14 +24,20 @@
2824
"@temporalio/workflow": "^1.11.2",
2925
"dotenv": "^16.4.5",
3026
"express": "^4.21.1",
27+
"llamaindex": "^0.8.4",
3128
"together-ai": "^0.9.0",
29+
"tsx": "^4.19.2",
3230
"zod": "^3.23.8",
3331
"zod-to-json-schema": "^3.23.5"
3432
},
3533
"devDependencies": {
3634
"@restackio/restack-sdk-cloud-ts": "^1.0.16",
3735
"@types/express": "^5.0.0",
3836
"@types/node": "^20.16.9",
39-
"ts-node": "^10.9.2"
37+
"@typescript-eslint/eslint-plugin": "^8.13.0",
38+
"@typescript-eslint/parser": "^8.13.0",
39+
"eslint": "^9.14.0",
40+
"ts-node": "^10.9.2",
41+
"typescript": "^5.6.3"
4042
}
4143
}

examples/express-together-llamaindex/pnpm-lock.yaml

Lines changed: 5227 additions & 203 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './llamaindex';
12
export * from './together-ai';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {
2+
Document,
3+
} from "llamaindex";
4+
5+
export async function createDocument(essay: string, path: string): Promise<Document> {
6+
return new Document({ text: essay, id_: path });
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { VectorStoreIndex, Document } from "llamaindex";
2+
3+
export async function createIndex(document: Document): Promise<VectorStoreIndex> {
4+
return await VectorStoreIndex.fromDocuments([document]);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './createDocument';
2+
export * from './createIndex';
3+
export * from './loadEssay';
4+
export * from './outputResponse';
5+
export * from './queryIndex';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import fs from "node:fs/promises";
2+
3+
export async function loadEssay(path: string): Promise<string> {
4+
return await fs.readFile(path, "utf-8");
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
MetadataMode,
3+
NodeWithScore,
4+
} from "llamaindex";
5+
6+
export async function outputResponse(response: any, sourceNodes: NodeWithScore[]): Promise<void> {
7+
console.log(response);
8+
if (sourceNodes) {
9+
sourceNodes.forEach((source: NodeWithScore, index: number) => {
10+
console.log(
11+
`\n${index}: Score: ${source.score} - ${source.node.getContent(MetadataMode.NONE).substring(0, 50)}...\n`,
12+
);
13+
});
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {
2+
NodeWithScore,
3+
VectorStoreIndex,
4+
} from "llamaindex";
5+
6+
export async function queryIndex(index: VectorStoreIndex, query: string): Promise<{ response: any; sourceNodes: NodeWithScore[] }> {
7+
const queryEngine = index.asQueryEngine();
8+
const result = await queryEngine.query({ query });
9+
return {
10+
response: result.response,
11+
sourceNodes: result.sourceNodes || [],
12+
};
13+
}

0 commit comments

Comments
 (0)