matt HOFFNER commited on
Commit
e82c85b
β€’
1 Parent(s): b801bb1

handle file embedding

Browse files
package-lock.json CHANGED
@@ -15,11 +15,13 @@
15
  "@types/react": "18.2.6",
16
  "@types/react-dom": "18.2.4",
17
  "@xenova/transformers": "^2.1.1",
 
18
  "eslint": "8.40.0",
19
  "eslint-config-next": "13.4.2",
20
  "fs-extra": "^11.1.1",
21
  "langchain": "^0.0.90",
22
  "next": "13.4.2",
 
23
  "react": "18.2.0",
24
  "react-dom": "18.2.0",
25
  "react-dropzone": "^14.2.3",
@@ -987,6 +989,26 @@
987
  "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz",
988
  "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
989
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
990
  "node_modules/@next/env": {
991
  "version": "13.4.2",
992
  "resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.2.tgz",
@@ -1583,6 +1605,12 @@
1583
  "onnxruntime-node": "1.14.0"
1584
  }
1585
  },
 
 
 
 
 
 
1586
  "node_modules/acorn": {
1587
  "version": "8.8.2",
1588
  "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",
@@ -1602,6 +1630,18 @@
1602
  "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
1603
  }
1604
  },
 
 
 
 
 
 
 
 
 
 
 
 
1605
  "node_modules/ajv": {
1606
  "version": "6.12.6",
1607
  "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
@@ -1639,6 +1679,25 @@
1639
  "url": "https://github.com/chalk/ansi-styles?sponsor=1"
1640
  }
1641
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1642
  "node_modules/argparse": {
1643
  "version": "2.0.1",
1644
  "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@@ -2061,6 +2120,56 @@
2061
  }
2062
  ]
2063
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2064
  "node_modules/chalk": {
2065
  "version": "4.1.2",
2066
  "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
@@ -2123,6 +2232,15 @@
2123
  "simple-swizzle": "^0.2.2"
2124
  }
2125
  },
 
 
 
 
 
 
 
 
 
2126
  "node_modules/combined-stream": {
2127
  "version": "1.0.8",
2128
  "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
@@ -2149,6 +2267,12 @@
2149
  "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
2150
  "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
2151
  },
 
 
 
 
 
 
2152
  "node_modules/convert-source-map": {
2153
  "version": "1.9.0",
2154
  "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz",
@@ -2343,6 +2467,12 @@
2343
  "node": ">=0.4.0"
2344
  }
2345
  },
 
 
 
 
 
 
2346
  "node_modules/detect-libc": {
2347
  "version": "2.0.1",
2348
  "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
@@ -2351,6 +2481,14 @@
2351
  "node": ">=8"
2352
  }
2353
  },
 
 
 
 
 
 
 
 
2354
  "node_modules/dir-glob": {
2355
  "version": "3.0.1",
2356
  "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@@ -3288,6 +3426,30 @@
3288
  "node": ">=14.14"
3289
  }
3290
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3291
  "node_modules/fs.realpath": {
3292
  "version": "1.0.0",
3293
  "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -3337,6 +3499,26 @@
3337
  "url": "https://github.com/sponsors/ljharb"
3338
  }
3339
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3340
  "node_modules/gensync": {
3341
  "version": "1.0.0-beta.2",
3342
  "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
@@ -3579,6 +3761,12 @@
3579
  "url": "https://github.com/sponsors/ljharb"
3580
  }
3581
  },
 
 
 
 
 
 
3582
  "node_modules/hoist-non-react-statics": {
3583
  "version": "3.3.2",
3584
  "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
@@ -3588,6 +3776,19 @@
3588
  "react-is": "^16.7.0"
3589
  }
3590
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
3591
  "node_modules/human-signals": {
3592
  "version": "4.3.1",
3593
  "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz",
@@ -3800,6 +4001,15 @@
3800
  "node": ">=0.10.0"
3801
  }
3802
  },
 
 
 
 
 
 
 
 
 
3803
  "node_modules/is-glob": {
3804
  "version": "4.0.3",
3805
  "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
@@ -4577,6 +4787,52 @@
4577
  "url": "https://github.com/sponsors/ljharb"
4578
  }
4579
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4580
  "node_modules/mkdirp-classic": {
4581
  "version": "0.5.3",
4582
  "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
@@ -4627,6 +4883,12 @@
4627
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
4628
  "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
4629
  },
 
 
 
 
 
 
4630
  "node_modules/nanoid": {
4631
  "version": "3.3.6",
4632
  "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz",
@@ -4747,6 +5009,21 @@
4747
  "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.12.tgz",
4748
  "integrity": "sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ=="
4749
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4750
  "node_modules/normalize-range": {
4751
  "version": "0.1.2",
4752
  "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz",
@@ -4780,6 +5057,18 @@
4780
  "url": "https://github.com/sponsors/sindresorhus"
4781
  }
4782
  },
 
 
 
 
 
 
 
 
 
 
 
 
4783
  "node_modules/num-sort": {
4784
  "version": "2.1.0",
4785
  "resolved": "https://registry.npmjs.org/num-sort/-/num-sort-2.1.0.tgz",
@@ -5146,6 +5435,27 @@
5146
  "node": ">=8"
5147
  }
5148
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5149
  "node_modules/picocolors": {
5150
  "version": "1.0.0",
5151
  "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
@@ -5790,6 +6100,12 @@
5790
  "node": ">=10"
5791
  }
5792
  },
 
 
 
 
 
 
5793
  "node_modules/shallowequal": {
5794
  "version": "1.1.0",
5795
  "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz",
@@ -5955,6 +6271,26 @@
5955
  "safe-buffer": "~5.2.0"
5956
  }
5957
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5958
  "node_modules/string.prototype.matchall": {
5959
  "version": "4.0.8",
5960
  "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.8.tgz",
@@ -6174,6 +6510,23 @@
6174
  "node": ">=6"
6175
  }
6176
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6177
  "node_modules/tar-fs": {
6178
  "version": "2.1.1",
6179
  "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
@@ -6200,6 +6553,15 @@
6200
  "node": ">=6"
6201
  }
6202
  },
 
 
 
 
 
 
 
 
 
6203
  "node_modules/text-table": {
6204
  "version": "0.2.0",
6205
  "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
@@ -6497,6 +6859,15 @@
6497
  "url": "https://github.com/sponsors/ljharb"
6498
  }
6499
  },
 
 
 
 
 
 
 
 
 
6500
  "node_modules/word-wrap": {
6501
  "version": "1.2.3",
6502
  "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
 
15
  "@types/react": "18.2.6",
16
  "@types/react-dom": "18.2.4",
17
  "@xenova/transformers": "^2.1.1",
18
+ "dexie": "^3.2.4",
19
  "eslint": "8.40.0",
20
  "eslint-config-next": "13.4.2",
21
  "fs-extra": "^11.1.1",
22
  "langchain": "^0.0.90",
23
  "next": "13.4.2",
24
+ "pdfjs-dist": "^3.7.107",
25
  "react": "18.2.0",
26
  "react-dom": "18.2.0",
27
  "react-dropzone": "^14.2.3",
 
989
  "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz",
990
  "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
991
  },
992
+ "node_modules/@mapbox/node-pre-gyp": {
993
+ "version": "1.0.10",
994
+ "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz",
995
+ "integrity": "sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==",
996
+ "optional": true,
997
+ "dependencies": {
998
+ "detect-libc": "^2.0.0",
999
+ "https-proxy-agent": "^5.0.0",
1000
+ "make-dir": "^3.1.0",
1001
+ "node-fetch": "^2.6.7",
1002
+ "nopt": "^5.0.0",
1003
+ "npmlog": "^5.0.1",
1004
+ "rimraf": "^3.0.2",
1005
+ "semver": "^7.3.5",
1006
+ "tar": "^6.1.11"
1007
+ },
1008
+ "bin": {
1009
+ "node-pre-gyp": "bin/node-pre-gyp"
1010
+ }
1011
+ },
1012
  "node_modules/@next/env": {
1013
  "version": "13.4.2",
1014
  "resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.2.tgz",
 
1605
  "onnxruntime-node": "1.14.0"
1606
  }
1607
  },
1608
+ "node_modules/abbrev": {
1609
+ "version": "1.1.1",
1610
+ "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
1611
+ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
1612
+ "optional": true
1613
+ },
1614
  "node_modules/acorn": {
1615
  "version": "8.8.2",
1616
  "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",
 
1630
  "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
1631
  }
1632
  },
1633
+ "node_modules/agent-base": {
1634
+ "version": "6.0.2",
1635
+ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
1636
+ "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
1637
+ "optional": true,
1638
+ "dependencies": {
1639
+ "debug": "4"
1640
+ },
1641
+ "engines": {
1642
+ "node": ">= 6.0.0"
1643
+ }
1644
+ },
1645
  "node_modules/ajv": {
1646
  "version": "6.12.6",
1647
  "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
 
1679
  "url": "https://github.com/chalk/ansi-styles?sponsor=1"
1680
  }
1681
  },
1682
+ "node_modules/aproba": {
1683
+ "version": "2.0.0",
1684
+ "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz",
1685
+ "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==",
1686
+ "optional": true
1687
+ },
1688
+ "node_modules/are-we-there-yet": {
1689
+ "version": "2.0.0",
1690
+ "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz",
1691
+ "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==",
1692
+ "optional": true,
1693
+ "dependencies": {
1694
+ "delegates": "^1.0.0",
1695
+ "readable-stream": "^3.6.0"
1696
+ },
1697
+ "engines": {
1698
+ "node": ">=10"
1699
+ }
1700
+ },
1701
  "node_modules/argparse": {
1702
  "version": "2.0.1",
1703
  "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
 
2120
  }
2121
  ]
2122
  },
2123
+ "node_modules/canvas": {
2124
+ "version": "2.11.2",
2125
+ "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.11.2.tgz",
2126
+ "integrity": "sha512-ItanGBMrmRV7Py2Z+Xhs7cT+FNt5K0vPL4p9EZ/UX/Mu7hFbkxSjKF2KVtPwX7UYWp7dRKnrTvReflgrItJbdw==",
2127
+ "hasInstallScript": true,
2128
+ "optional": true,
2129
+ "dependencies": {
2130
+ "@mapbox/node-pre-gyp": "^1.0.0",
2131
+ "nan": "^2.17.0",
2132
+ "simple-get": "^3.0.3"
2133
+ },
2134
+ "engines": {
2135
+ "node": ">=6"
2136
+ }
2137
+ },
2138
+ "node_modules/canvas/node_modules/decompress-response": {
2139
+ "version": "4.2.1",
2140
+ "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz",
2141
+ "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==",
2142
+ "optional": true,
2143
+ "dependencies": {
2144
+ "mimic-response": "^2.0.0"
2145
+ },
2146
+ "engines": {
2147
+ "node": ">=8"
2148
+ }
2149
+ },
2150
+ "node_modules/canvas/node_modules/mimic-response": {
2151
+ "version": "2.1.0",
2152
+ "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
2153
+ "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==",
2154
+ "optional": true,
2155
+ "engines": {
2156
+ "node": ">=8"
2157
+ },
2158
+ "funding": {
2159
+ "url": "https://github.com/sponsors/sindresorhus"
2160
+ }
2161
+ },
2162
+ "node_modules/canvas/node_modules/simple-get": {
2163
+ "version": "3.1.1",
2164
+ "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz",
2165
+ "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==",
2166
+ "optional": true,
2167
+ "dependencies": {
2168
+ "decompress-response": "^4.2.0",
2169
+ "once": "^1.3.1",
2170
+ "simple-concat": "^1.0.0"
2171
+ }
2172
+ },
2173
  "node_modules/chalk": {
2174
  "version": "4.1.2",
2175
  "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
 
2232
  "simple-swizzle": "^0.2.2"
2233
  }
2234
  },
2235
+ "node_modules/color-support": {
2236
+ "version": "1.1.3",
2237
+ "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
2238
+ "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==",
2239
+ "optional": true,
2240
+ "bin": {
2241
+ "color-support": "bin.js"
2242
+ }
2243
+ },
2244
  "node_modules/combined-stream": {
2245
  "version": "1.0.8",
2246
  "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
 
2267
  "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
2268
  "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
2269
  },
2270
+ "node_modules/console-control-strings": {
2271
+ "version": "1.1.0",
2272
+ "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
2273
+ "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==",
2274
+ "optional": true
2275
+ },
2276
  "node_modules/convert-source-map": {
2277
  "version": "1.9.0",
2278
  "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz",
 
2467
  "node": ">=0.4.0"
2468
  }
2469
  },
2470
+ "node_modules/delegates": {
2471
+ "version": "1.0.0",
2472
+ "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
2473
+ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==",
2474
+ "optional": true
2475
+ },
2476
  "node_modules/detect-libc": {
2477
  "version": "2.0.1",
2478
  "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
 
2481
  "node": ">=8"
2482
  }
2483
  },
2484
+ "node_modules/dexie": {
2485
+ "version": "3.2.4",
2486
+ "resolved": "https://registry.npmjs.org/dexie/-/dexie-3.2.4.tgz",
2487
+ "integrity": "sha512-VKoTQRSv7+RnffpOJ3Dh6ozknBqzWw/F3iqMdsZg958R0AS8AnY9x9d1lbwENr0gzeGJHXKcGhAMRaqys6SxqA==",
2488
+ "engines": {
2489
+ "node": ">=6.0"
2490
+ }
2491
+ },
2492
  "node_modules/dir-glob": {
2493
  "version": "3.0.1",
2494
  "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
 
3426
  "node": ">=14.14"
3427
  }
3428
  },
3429
+ "node_modules/fs-minipass": {
3430
+ "version": "2.1.0",
3431
+ "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
3432
+ "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
3433
+ "optional": true,
3434
+ "dependencies": {
3435
+ "minipass": "^3.0.0"
3436
+ },
3437
+ "engines": {
3438
+ "node": ">= 8"
3439
+ }
3440
+ },
3441
+ "node_modules/fs-minipass/node_modules/minipass": {
3442
+ "version": "3.3.6",
3443
+ "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
3444
+ "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
3445
+ "optional": true,
3446
+ "dependencies": {
3447
+ "yallist": "^4.0.0"
3448
+ },
3449
+ "engines": {
3450
+ "node": ">=8"
3451
+ }
3452
+ },
3453
  "node_modules/fs.realpath": {
3454
  "version": "1.0.0",
3455
  "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
 
3499
  "url": "https://github.com/sponsors/ljharb"
3500
  }
3501
  },
3502
+ "node_modules/gauge": {
3503
+ "version": "3.0.2",
3504
+ "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz",
3505
+ "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==",
3506
+ "optional": true,
3507
+ "dependencies": {
3508
+ "aproba": "^1.0.3 || ^2.0.0",
3509
+ "color-support": "^1.1.2",
3510
+ "console-control-strings": "^1.0.0",
3511
+ "has-unicode": "^2.0.1",
3512
+ "object-assign": "^4.1.1",
3513
+ "signal-exit": "^3.0.0",
3514
+ "string-width": "^4.2.3",
3515
+ "strip-ansi": "^6.0.1",
3516
+ "wide-align": "^1.1.2"
3517
+ },
3518
+ "engines": {
3519
+ "node": ">=10"
3520
+ }
3521
+ },
3522
  "node_modules/gensync": {
3523
  "version": "1.0.0-beta.2",
3524
  "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
 
3761
  "url": "https://github.com/sponsors/ljharb"
3762
  }
3763
  },
3764
+ "node_modules/has-unicode": {
3765
+ "version": "2.0.1",
3766
+ "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
3767
+ "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==",
3768
+ "optional": true
3769
+ },
3770
  "node_modules/hoist-non-react-statics": {
3771
  "version": "3.3.2",
3772
  "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
 
3776
  "react-is": "^16.7.0"
3777
  }
3778
  },
3779
+ "node_modules/https-proxy-agent": {
3780
+ "version": "5.0.1",
3781
+ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
3782
+ "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
3783
+ "optional": true,
3784
+ "dependencies": {
3785
+ "agent-base": "6",
3786
+ "debug": "4"
3787
+ },
3788
+ "engines": {
3789
+ "node": ">= 6"
3790
+ }
3791
+ },
3792
  "node_modules/human-signals": {
3793
  "version": "4.3.1",
3794
  "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz",
 
4001
  "node": ">=0.10.0"
4002
  }
4003
  },
4004
+ "node_modules/is-fullwidth-code-point": {
4005
+ "version": "3.0.0",
4006
+ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
4007
+ "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
4008
+ "optional": true,
4009
+ "engines": {
4010
+ "node": ">=8"
4011
+ }
4012
+ },
4013
  "node_modules/is-glob": {
4014
  "version": "4.0.3",
4015
  "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
 
4787
  "url": "https://github.com/sponsors/ljharb"
4788
  }
4789
  },
4790
+ "node_modules/minipass": {
4791
+ "version": "5.0.0",
4792
+ "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz",
4793
+ "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==",
4794
+ "optional": true,
4795
+ "engines": {
4796
+ "node": ">=8"
4797
+ }
4798
+ },
4799
+ "node_modules/minizlib": {
4800
+ "version": "2.1.2",
4801
+ "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
4802
+ "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
4803
+ "optional": true,
4804
+ "dependencies": {
4805
+ "minipass": "^3.0.0",
4806
+ "yallist": "^4.0.0"
4807
+ },
4808
+ "engines": {
4809
+ "node": ">= 8"
4810
+ }
4811
+ },
4812
+ "node_modules/minizlib/node_modules/minipass": {
4813
+ "version": "3.3.6",
4814
+ "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
4815
+ "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
4816
+ "optional": true,
4817
+ "dependencies": {
4818
+ "yallist": "^4.0.0"
4819
+ },
4820
+ "engines": {
4821
+ "node": ">=8"
4822
+ }
4823
+ },
4824
+ "node_modules/mkdirp": {
4825
+ "version": "1.0.4",
4826
+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
4827
+ "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
4828
+ "optional": true,
4829
+ "bin": {
4830
+ "mkdirp": "bin/cmd.js"
4831
+ },
4832
+ "engines": {
4833
+ "node": ">=10"
4834
+ }
4835
+ },
4836
  "node_modules/mkdirp-classic": {
4837
  "version": "0.5.3",
4838
  "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
 
4883
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
4884
  "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
4885
  },
4886
+ "node_modules/nan": {
4887
+ "version": "2.17.0",
4888
+ "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz",
4889
+ "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==",
4890
+ "optional": true
4891
+ },
4892
  "node_modules/nanoid": {
4893
  "version": "3.3.6",
4894
  "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz",
 
5009
  "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.12.tgz",
5010
  "integrity": "sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ=="
5011
  },
5012
+ "node_modules/nopt": {
5013
+ "version": "5.0.0",
5014
+ "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
5015
+ "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==",
5016
+ "optional": true,
5017
+ "dependencies": {
5018
+ "abbrev": "1"
5019
+ },
5020
+ "bin": {
5021
+ "nopt": "bin/nopt.js"
5022
+ },
5023
+ "engines": {
5024
+ "node": ">=6"
5025
+ }
5026
+ },
5027
  "node_modules/normalize-range": {
5028
  "version": "0.1.2",
5029
  "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz",
 
5057
  "url": "https://github.com/sponsors/sindresorhus"
5058
  }
5059
  },
5060
+ "node_modules/npmlog": {
5061
+ "version": "5.0.1",
5062
+ "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz",
5063
+ "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==",
5064
+ "optional": true,
5065
+ "dependencies": {
5066
+ "are-we-there-yet": "^2.0.0",
5067
+ "console-control-strings": "^1.1.0",
5068
+ "gauge": "^3.0.0",
5069
+ "set-blocking": "^2.0.0"
5070
+ }
5071
+ },
5072
  "node_modules/num-sort": {
5073
  "version": "2.1.0",
5074
  "resolved": "https://registry.npmjs.org/num-sort/-/num-sort-2.1.0.tgz",
 
5435
  "node": ">=8"
5436
  }
5437
  },
5438
+ "node_modules/path2d-polyfill": {
5439
+ "version": "2.0.1",
5440
+ "resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz",
5441
+ "integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==",
5442
+ "optional": true,
5443
+ "engines": {
5444
+ "node": ">=8"
5445
+ }
5446
+ },
5447
+ "node_modules/pdfjs-dist": {
5448
+ "version": "3.7.107",
5449
+ "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-3.7.107.tgz",
5450
+ "integrity": "sha512-D0pZgz4u8VNjCCXfNCjzeFcenxKFGh2RnGlLIvDHgpT+ZvOlsBlHugpOfmcLQyKk7csHBhPalf+mCM6thiclSQ==",
5451
+ "engines": {
5452
+ "node": ">=18"
5453
+ },
5454
+ "optionalDependencies": {
5455
+ "canvas": "^2.11.2",
5456
+ "path2d-polyfill": "^2.0.1"
5457
+ }
5458
+ },
5459
  "node_modules/picocolors": {
5460
  "version": "1.0.0",
5461
  "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
 
6100
  "node": ">=10"
6101
  }
6102
  },
6103
+ "node_modules/set-blocking": {
6104
+ "version": "2.0.0",
6105
+ "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
6106
+ "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==",
6107
+ "optional": true
6108
+ },
6109
  "node_modules/shallowequal": {
6110
  "version": "1.1.0",
6111
  "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz",
 
6271
  "safe-buffer": "~5.2.0"
6272
  }
6273
  },
6274
+ "node_modules/string-width": {
6275
+ "version": "4.2.3",
6276
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
6277
+ "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
6278
+ "optional": true,
6279
+ "dependencies": {
6280
+ "emoji-regex": "^8.0.0",
6281
+ "is-fullwidth-code-point": "^3.0.0",
6282
+ "strip-ansi": "^6.0.1"
6283
+ },
6284
+ "engines": {
6285
+ "node": ">=8"
6286
+ }
6287
+ },
6288
+ "node_modules/string-width/node_modules/emoji-regex": {
6289
+ "version": "8.0.0",
6290
+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
6291
+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
6292
+ "optional": true
6293
+ },
6294
  "node_modules/string.prototype.matchall": {
6295
  "version": "4.0.8",
6296
  "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.8.tgz",
 
6510
  "node": ">=6"
6511
  }
6512
  },
6513
+ "node_modules/tar": {
6514
+ "version": "6.1.15",
6515
+ "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.15.tgz",
6516
+ "integrity": "sha512-/zKt9UyngnxIT/EAGYuxaMYgOIJiP81ab9ZfkILq4oNLPFX50qyYmu7jRj9qeXoxmJHjGlbH0+cm2uy1WCs10A==",
6517
+ "optional": true,
6518
+ "dependencies": {
6519
+ "chownr": "^2.0.0",
6520
+ "fs-minipass": "^2.0.0",
6521
+ "minipass": "^5.0.0",
6522
+ "minizlib": "^2.1.1",
6523
+ "mkdirp": "^1.0.3",
6524
+ "yallist": "^4.0.0"
6525
+ },
6526
+ "engines": {
6527
+ "node": ">=10"
6528
+ }
6529
+ },
6530
  "node_modules/tar-fs": {
6531
  "version": "2.1.1",
6532
  "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
 
6553
  "node": ">=6"
6554
  }
6555
  },
6556
+ "node_modules/tar/node_modules/chownr": {
6557
+ "version": "2.0.0",
6558
+ "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
6559
+ "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
6560
+ "optional": true,
6561
+ "engines": {
6562
+ "node": ">=10"
6563
+ }
6564
+ },
6565
  "node_modules/text-table": {
6566
  "version": "0.2.0",
6567
  "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
 
6859
  "url": "https://github.com/sponsors/ljharb"
6860
  }
6861
  },
6862
+ "node_modules/wide-align": {
6863
+ "version": "1.1.5",
6864
+ "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz",
6865
+ "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==",
6866
+ "optional": true,
6867
+ "dependencies": {
6868
+ "string-width": "^1.0.2 || 2 || 3 || 4"
6869
+ }
6870
+ },
6871
  "node_modules/word-wrap": {
6872
  "version": "1.2.3",
6873
  "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
package.json CHANGED
@@ -15,11 +15,13 @@
15
  "@types/react": "18.2.6",
16
  "@types/react-dom": "18.2.4",
17
  "@xenova/transformers": "^2.1.1",
 
18
  "eslint": "8.40.0",
19
  "eslint-config-next": "13.4.2",
20
  "fs-extra": "^11.1.1",
21
  "langchain": "^0.0.90",
22
  "next": "13.4.2",
 
23
  "react": "18.2.0",
24
  "react-dom": "18.2.0",
25
  "react-dropzone": "^14.2.3",
 
15
  "@types/react": "18.2.6",
16
  "@types/react-dom": "18.2.4",
17
  "@xenova/transformers": "^2.1.1",
18
+ "dexie": "^3.2.4",
19
  "eslint": "8.40.0",
20
  "eslint-config-next": "13.4.2",
21
  "fs-extra": "^11.1.1",
22
  "langchain": "^0.0.90",
23
  "next": "13.4.2",
24
+ "pdfjs-dist": "^3.7.107",
25
  "react": "18.2.0",
26
  "react-dom": "18.2.0",
27
  "react-dropzone": "^14.2.3",
src/components/DashButton.tsx ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react';
2
+ import { MouseEventHandler, ReactElement } from 'react';
3
+
4
+ interface Props {
5
+ handleClick: MouseEventHandler<HTMLButtonElement>;
6
+ children: ReactElement;
7
+ }
8
+ const DashButton = ({ handleClick, children }: Props) => {
9
+ return (
10
+ <button
11
+ className="border-dashed border-2 border-black rounded-lg py-2 px-4 text-black hover:bg-black hover:text-white transition-all duration-300 ease-in-out"
12
+ onClick={handleClick}
13
+ >
14
+ {children}
15
+ </button>
16
+ );
17
+ };
18
+
19
+ export { DashButton };
src/components/FileLoader.jsx ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react';
2
+ import { db } from '@/utils/db-client';
3
+ import { DashButton } from './DashButton'
4
+ import { FileEmbedder } from './FileEmbedder';
5
+ import * as PDFJS from 'pdfjs-dist/build/pdf';
6
+
7
+ PDFJS.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${PDFJS.version}/pdf.worker.min.js`;
8
+
9
+ export default class Pdf {
10
+ static async getPageText(pdf, pageNo) {
11
+ const page = await pdf.getPage(pageNo);
12
+ const tokenizedText = await page.getTextContent();
13
+ const pageText = tokenizedText.items.map((token) => token.str).join('');
14
+ return pageText;
15
+ }
16
+
17
+ static async getPDFText(source) {
18
+ const pdf = await PDFJS.getDocument(source).promise;
19
+ const maxPages = pdf.numPages;
20
+ const pageTextPromises = [];
21
+ for (let pageNo = 1; pageNo <= maxPages; pageNo += 1) {
22
+ pageTextPromises.push(Pdf.getPageText(pdf, pageNo));
23
+ }
24
+ const pageTexts = await Promise.all(pageTextPromises);
25
+ return pageTexts.join(' ');
26
+ }
27
+ }
28
+
29
+ export const FileLoader = () => {
30
+ const [files, setFiles] = useState();
31
+ const [uploadStatus, setUploadStatus] = useState("Embed");
32
+ const handleEmbed = (files) => {
33
+ setFiles(files)
34
+ };
35
+
36
+ return (
37
+ <>
38
+ <FileEmbedder handleEmbed={handleEmbed} />
39
+ <DashButton
40
+ handleClick={async () => {
41
+ if (files && files.length) {
42
+ const file = files[0];
43
+ let text;
44
+ const blob = new Blob([file], { type: 'text/plain' });
45
+ if (file.type === "application/pdf") {
46
+ text = await Pdf.getPDFText(URL.createObjectURL(blob));
47
+ } else {
48
+ text = URL.createObjectURL(blob);
49
+ }
50
+ const response = await fetch('/api/docHandle', {
51
+ method: 'POST',
52
+ body: JSON.stringify({ text }),
53
+ });
54
+ const docChat = await response.json();
55
+ console.log('handleDocs-getModels: ', docChat);
56
+ const id = await db.docs.add({
57
+ fileName: file.name || '',
58
+ fileSourceData: pdfText,
59
+ model: docChat,
60
+ });
61
+ setUploadStatus("Embedding Completed");
62
+ console.log('handleDocs-setToDb', id);
63
+ }
64
+ }}
65
+ >
66
+ <div>{uploadStatus}</div>
67
+ </DashButton>
68
+ </>
69
+ );
70
+ };
src/components/FileLoader.tsx DELETED
@@ -1,29 +0,0 @@
1
- import { useState } from 'react';
2
- import { MouseEventHandler, ReactElement } from 'react';
3
-
4
- import { FileEmbedder } from './FileEmbedder';
5
-
6
- export const FileLoader = () => {
7
- const [files, setFiles] = useState<File[]>()
8
- const handleEmbed = (files: File[]) => {
9
- setFiles(files)
10
- console.log(files);
11
- };
12
-
13
- const handleClick: MouseEventHandler<HTMLButtonElement> = (e) => {
14
- console.log(e);
15
- };
16
-
17
- return (
18
- <>
19
- <FileEmbedder handleEmbed={handleEmbed} />
20
- <button
21
- onClick={() => {
22
- console.log('sure');
23
- }}
24
- >
25
- <div>Embed</div>
26
- </button>
27
- </>
28
- );
29
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/pages/api/docChat.ts ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+
3
+ import { storesDir } from '@/utils/file-handler';
4
+
5
+ import { makeChain } from '@/utils/make-chain';
6
+ import { XenovaTransformersEmbeddings } from '../../embed/hf';
7
+ import { HNSWLib } from 'langchain/vectorstores/hnswlib';
8
+
9
+ let vectorStore: HNSWLib;
10
+
11
+ export default async function handler(
12
+ req: NextApiRequest,
13
+ res: NextApiResponse,
14
+ ) {
15
+ const { prompt, messages } = req.body;
16
+
17
+ if (!prompt) {
18
+ return res.status(400).json({ message: 'No question in the request' });
19
+ }
20
+ // OpenAI recommends replacing newlines with spaces for best results
21
+ const sanitizedQuestion = prompt.trim().replaceAll('\n', ' ');
22
+
23
+ res.writeHead(200, {
24
+ 'Content-Type': 'text/event-stream',
25
+ 'Cache-Control': 'no-cache, no-transform',
26
+ Connection: 'keep-alive',
27
+ });
28
+
29
+ const sendData = (data: string) => {
30
+ res.write(`${data}\n\n`);
31
+ };
32
+
33
+ // load store
34
+ if (!vectorStore) {
35
+ vectorStore = await HNSWLib.load(storesDir, new XenovaTransformersEmbeddings());
36
+ }
37
+ //create chain
38
+ const chain = makeChain(vectorStore, (token: string) => {
39
+ // skipping stremaing for now
40
+ // sendData(JSON.stringify({ data: token }));
41
+ });
42
+
43
+ try {
44
+ //Ask a question
45
+ const response = await chain.call({
46
+ question: sanitizedQuestion,
47
+ chat_history: messages || [],
48
+ });
49
+
50
+ console.log('response', response);
51
+ sendData(response.text);
52
+ } catch (error) {
53
+ console.log('error', error);
54
+ } finally {
55
+ // sendData('[DONE]');
56
+ res.end();
57
+ }
58
+ }
src/utils/db-client.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // import { IDocMeta } from '@/types';
2
+ import Dexie, { Table } from 'dexie';
3
+
4
+ export class MyDocDb extends Dexie {
5
+ constructor() {
6
+ super('myDocDb');
7
+ this.version(1).stores({
8
+ docs: '++id, folderName, fileName, fileSourceData, model',
9
+ });
10
+ }
11
+ }
12
+
13
+ export const db = new MyDocDb();
src/utils/make-chain.ts ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { CallbackManager } from 'langchain/callbacks';
2
+ import { ConversationalRetrievalQAChain } from 'langchain/chains';
3
+ import { OpenAIChat } from 'langchain/llms';
4
+ import { PromptTemplate } from 'langchain/prompts';
5
+ import { BufferMemory } from "langchain/memory";
6
+ import { HNSWLib } from 'langchain/vectorstores/hnswlib';
7
+
8
+ export const defaultPrompts = {
9
+ CONDENSE_PROMPT: `Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
10
+
11
+ Chat History:
12
+ {chat_history}
13
+ Follow Up Input: {question}
14
+ Standalone question:`,
15
+ QA_PROMPT: `You are an AI assistant providing helpful advice. You are given the following extracted parts of a long document and a question. Provide a conversational answer based on the context provided.
16
+ You should only provide hyperlinks that reference the context below. Do NOT make up hyperlinks.
17
+ If you can't find the answer in the context below, just say "Hmm, I'm not sure." Don't try to make up an answer.
18
+ If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context.
19
+
20
+ Question: {question}
21
+ =========
22
+ {context}
23
+ =========
24
+ Answer:`,
25
+ };
26
+
27
+ const CONDENSE_PROMPT = PromptTemplate.fromTemplate(
28
+ defaultPrompts.CONDENSE_PROMPT,
29
+ );
30
+
31
+ const QA_PROMPT = PromptTemplate.fromTemplate(defaultPrompts.QA_PROMPT);
32
+
33
+ export const makeChain = (
34
+ vectorstore: HNSWLib,
35
+ onTokenStream?: (token: string) => void,
36
+ ) => {
37
+
38
+ const model = new OpenAIChat({
39
+ temperature: 0.8,
40
+ modelName: "OpenAIModelID.GPT_3_5",
41
+ streaming: false,
42
+ callbackManager: onTokenStream
43
+ ? CallbackManager.fromHandlers({
44
+ async handleLLMNewToken(token) {
45
+ onTokenStream(token);
46
+ },
47
+ })
48
+ : undefined,
49
+ })
50
+
51
+ return ConversationalRetrievalQAChain.fromLLM(
52
+ model, vectorstore.asRetriever(),
53
+ {
54
+ memory: new BufferMemory({
55
+ memoryKey: "chat_history", // Must be set to "chat_history"
56
+ }), qaTemplate: defaultPrompts.QA_PROMPT, questionGeneratorTemplate: defaultPrompts.CONDENSE_PROMPT })
57
+ };
tsconfig.json CHANGED
@@ -18,6 +18,6 @@
18
  "@/*": ["./src/*"]
19
  }
20
  },
21
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "src/components/ChatV2.jsx", "src/pages/index.jsx"],
22
  "exclude": ["node_modules"]
23
  }
 
18
  "@/*": ["./src/*"]
19
  }
20
  },
21
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "src/components/ChatV2.jsx", "src/pages/index.jsx", "src/utils/db-client.js", "src/components/FileLoader.jsx"],
22
  "exclude": ["node_modules"]
23
  }