diff --git a/database/index.js b/database/index.js new file mode 100644 index 0000000..9b029af --- /dev/null +++ b/database/index.js @@ -0,0 +1,42 @@ +import * as lancedb from "@lancedb/lancedb"; +import { get, post } from "../tools/request.js" +import { Schema, Field, FixedSizeList, Int16, Float16, Utf8 } from "apache-arrow"; + +const uri = "/tmp/lancedb/"; +const db = await lancedb.connect(uri); + +const table = await db.createEmptyTable("rag_data", new Schema([ + new Field("id", new Int16()), + new Field("vector", new FixedSizeList(384, new Field("item", new Float16(), true)), false), + new Field("question", new Utf8()), + new Field("answer", new Utf8()) +]), { + // mode: "overwrite", + existOk: true +}) + +export async function loadDataset(dataset_link) { + const {rows, http_error} = await get('', {}, { URL: dataset_link }) + if(http_error) { + return false; + } + await table.add(rows.map(({ row_id, row })=>{ + const { question, answer, question_embedding } = row; + return { id: row_id, question, answer, vector: question_embedding } + })) + return true; +} + +export async function searchByEmbedding(vector) { + const record = await table.search(vector).limit(1).toArray(); + if(!record.length) return null; + const { question, answer } = record[0]; + return { question, answer }; +} + +export async function searchByMessage(msg) { + const { embedding } = await post('embedding', {body: { + content: msg + }}, { eng: "embedding" }); + return await searchByEmbedding(embedding); +} \ No newline at end of file diff --git a/package.json b/package.json index 79bcfc6..9f43f66 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "description": "OpenAI like APIs", "main": "index.js", "scripts": { - "start": "node index.js --disable-warning=ExperimentalWarning", - "dev": "nodemon index.js --disable-warning=ExperimentalWarning", + "start": "node --disable-warning=ExperimentalWarning index.js", + "dev": "nodemon --disable-warning=ExperimentalWarning index.js", "lint": "npx eslint .", "build": "npm install && node index.js" }, @@ -17,6 +17,8 @@ "@babel/eslint-parser": "^7.25.1", "@babel/plugin-syntax-import-attributes": "^7.24.7", "@eslint/js": "^9.8.0", + "@lancedb/lancedb": "^0.8.0", + "apache-arrow": "^17.0.0", "body-parser": "^1.20.2", "cors": "^2.8.5", "dotenv": "^16.4.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 44fd9a5..6164dfe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,12 @@ importers: '@eslint/js': specifier: ^9.8.0 version: 9.8.0 + '@lancedb/lancedb': + specifier: ^0.8.0 + version: 0.8.0(apache-arrow@17.0.0) + apache-arrow: + specifier: ^17.0.0 + version: 17.0.0 body-parser: specifier: ^1.20.2 version: 1.20.2 @@ -191,6 +197,44 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} + '@lancedb/lancedb-darwin-arm64@0.8.0': + resolution: {integrity: sha512-GiVab/VnQpsxDD7rLcTDRFQygQhYU3sMYGXzK0Q88GVPo3Ng2fU9x7NoaRNQbV8k4X4gR7IdbNiqEAjmSLNMBA==} + engines: {node: '>= 18'} + cpu: [arm64] + os: [darwin] + + '@lancedb/lancedb-darwin-x64@0.8.0': + resolution: {integrity: sha512-NGEM8rLFkkPnTtVDVZ88+IcRB+wtsWtiuDd6Rd8fh19uwcid36idc8iFVPuRQEoLfCNyzugmSHf4yC0WNNaK9Q==} + engines: {node: '>= 18'} + cpu: [x64] + os: [darwin] + + '@lancedb/lancedb-linux-arm64-gnu@0.8.0': + resolution: {integrity: sha512-loBnUaKoTu3zLMJ++hNAg7LquN4UAuNPPEfYHr3i53TZrJ3/W/Ozx0Gwqxl7vqKIJ97g+iV7vTsmJhq+98/MDQ==} + engines: {node: '>= 18'} + cpu: [arm64] + os: [linux] + + '@lancedb/lancedb-linux-x64-gnu@0.8.0': + resolution: {integrity: sha512-3PoQSLVK0txXn2nTIzvSde1w3aiOIz31Qz4wLavtH7K3xNYYQ6JfPWpV8ac6e0y9LM+Pj+fyKEDHf0lK/JbQRw==} + engines: {node: '>= 18'} + cpu: [x64] + os: [linux] + + '@lancedb/lancedb-win32-x64-msvc@0.8.0': + resolution: {integrity: sha512-Ugj3N7LFwh45LSUQeJqs7Z7466/YWUC8DPgEblcsoCSSzgV09MPGv6cnCy6ssRVmMk9aKUmEDm/9Z/k8ETt9KQ==} + engines: {node: '>= 18'} + cpu: [x64] + os: [win32] + + '@lancedb/lancedb@0.8.0': + resolution: {integrity: sha512-nU7Wxaz3QN7FlXD8kCVu90v870jrt4mM+NsVmAtAW/MAv1xLlbp8jfKgETnxPIukPTy+6hyxrC74TJqdnEf+hA==} + engines: {node: '>= 18'} + cpu: [x64, arm64] + os: [darwin, linux, win32] + peerDependencies: + apache-arrow: '>=13.0.0 <=17.0.0' + '@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1': resolution: {integrity: sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==} @@ -206,6 +250,18 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@swc/helpers@0.5.12': + resolution: {integrity: sha512-KMZNXiGibsW9kvZAO1Pam2JPTDBm+KSHMMHWdsyI/1DbIZjT2A6Gy3hblVXUMEDvUAKq+e0vL0X0o54owWji7g==} + + '@types/command-line-args@5.2.3': + resolution: {integrity: sha512-uv0aG6R0Y8WHZLTamZwtfsDLVRnOa+n+n5rEvFWL5Na5gZ8V2Teab/duDPFzIIIhs9qizDpcavCusCLJZu62Kw==} + + '@types/command-line-usage@5.0.4': + resolution: {integrity: sha512-BwR5KP3Es/CSht0xqBcUXS3qCAUVXwpRKsV2+arxeb65atasuXG9LykC9Ab10Cw3s2raH92ZqOeILaQbsB2ACg==} + + '@types/node@20.14.14': + resolution: {integrity: sha512-d64f00982fS9YoOgJkAMolK7MN8Iq3TDdVjchbYHdEmjth/DHowx82GnoA+tVUAN+7vxfYUgAzi+JXbKNd2SDQ==} + accepts@1.3.8: resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==} engines: {node: '>= 0.6'} @@ -235,9 +291,21 @@ packages: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} + apache-arrow@17.0.0: + resolution: {integrity: sha512-X0p7auzdnGuhYMVKYINdQssS4EcKec9TCXyez/qtJt32DrIMGbzqiaMiQ0X6fQlQpw8Fl0Qygcv4dfRAr5Gu9Q==} + hasBin: true + argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} + array-back@3.1.0: + resolution: {integrity: sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==} + engines: {node: '>=6'} + + array-back@6.2.2: + resolution: {integrity: sha512-gUAZ7HPyb4SJczXAMUXMGAvI976JoK3qEx9v1FTmeYuJj0IBiaKttG1ydtGKdkfqWkIkouke7nG8ufGy77+Cvw==} + engines: {node: '>=12.17'} + array-flatten@1.1.1: resolution: {integrity: sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==} @@ -284,6 +352,10 @@ packages: caniuse-lite@1.0.30001643: resolution: {integrity: sha512-ERgWGNleEilSrHM6iUz/zJNSQTP8Mr21wDWpdgvRwcTXGAq6jMtOUPP4dqFPTdKqZ2wKTdtB+uucZ3MRpAUSmg==} + chalk-template@0.4.0: + resolution: {integrity: sha512-/ghrgmhfY8RaSdeo43hNXxpoHAtxdbskUHjPpfqUWGttFgycUhYPGx3YZBCnUCvOa7Doivn1IZec3DEGFoMgLg==} + engines: {node: '>=12'} + chalk@2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} engines: {node: '>=4'} @@ -309,6 +381,14 @@ packages: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} + command-line-args@5.2.1: + resolution: {integrity: sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==} + engines: {node: '>=4.0.0'} + + command-line-usage@7.0.3: + resolution: {integrity: sha512-PqMLy5+YGwhMh1wS04mVG44oqDsgyLRSKJBdOo1bnYhMKBW65gZF1dRp2OZRhiTjgUHljy99qkO7bsctLaw35Q==} + engines: {node: '>=12.20.0'} + concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} @@ -492,6 +572,10 @@ packages: resolution: {integrity: sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==} engines: {node: '>= 0.8'} + find-replace@3.0.0: + resolution: {integrity: sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==} + engines: {node: '>=4.0.0'} + find-up@5.0.0: resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} engines: {node: '>=10'} @@ -500,6 +584,9 @@ packages: resolution: {integrity: sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==} engines: {node: '>=16'} + flatbuffers@24.3.25: + resolution: {integrity: sha512-3HDgPbgiwWMI9zVB7VYBHaMrbOO7Gm0v+yD2FV/sCKj+9NDeVL7BOBYUuhWAQGKWOzBo8S9WdMvV0eixO233XQ==} + flatted@3.3.1: resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} @@ -631,6 +718,10 @@ packages: engines: {node: '>=4'} hasBin: true + json-bignum@0.0.3: + resolution: {integrity: sha512-2WHyXj3OfHSgNyuzDbSxI1w2jgw5gkWSWhS7Qg4bWXx1nLk3jnbwfUeS0PSba3IzpTUWdHxBieELUzXRjQB2zg==} + engines: {node: '>=0.8'} + json-buffer@3.0.1: resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==} @@ -660,6 +751,9 @@ packages: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} + lodash.camelcase@4.3.0: + resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==} + lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} @@ -802,6 +896,9 @@ packages: resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==} engines: {node: '>= 0.8'} + reflect-metadata@0.2.2: + resolution: {integrity: sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==} + resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} @@ -887,6 +984,10 @@ packages: peerDependencies: express: '>=4.0.0 || >=5.0.0-beta' + table-layout@4.1.1: + resolution: {integrity: sha512-iK5/YhZxq5GO5z8wb0bY1317uDF3Zjpha0QFFLA8/trAoiLbQD0HUbMesEaxyzUgDxi2QlcbM8IvqOlEjgoXBA==} + engines: {node: '>=12.17'} + tdigest@0.1.2: resolution: {integrity: sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA==} @@ -901,6 +1002,9 @@ packages: resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} engines: {node: '>=0.6'} + tslib@2.6.3: + resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==} + tsscmp@1.0.6: resolution: {integrity: sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==} engines: {node: '>=0.6.x'} @@ -913,6 +1017,17 @@ packages: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} + typical@4.0.0: + resolution: {integrity: sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==} + engines: {node: '>=8'} + + typical@7.1.1: + resolution: {integrity: sha512-T+tKVNs6Wu7IWiAce5BgMd7OZfNYUndHwc5MknN+UHOudi7sGZzuHdCadllRuqJ3fPtgFtIH9+lt9qRv6lmpfA==} + engines: {node: '>=12.17'} + + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + unpipe@1.0.0: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} @@ -947,6 +1062,10 @@ packages: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} + wordwrapjs@5.1.0: + resolution: {integrity: sha512-JNjcULU2e4KJwUNv6CHgI46UvDGitb6dGryHajXTDiLgg1/RiGoPSDw4kZfYnwGtEXf2ZMeIewDQgFGzkCB2Sg==} + engines: {node: '>=12.17'} + yallist@3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} @@ -1142,6 +1261,35 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 + '@lancedb/lancedb-darwin-arm64@0.8.0': + optional: true + + '@lancedb/lancedb-darwin-x64@0.8.0': + optional: true + + '@lancedb/lancedb-linux-arm64-gnu@0.8.0': + optional: true + + '@lancedb/lancedb-linux-x64-gnu@0.8.0': + optional: true + + '@lancedb/lancedb-win32-x64-msvc@0.8.0': + optional: true + + '@lancedb/lancedb@0.8.0(apache-arrow@17.0.0)': + dependencies: + apache-arrow: 17.0.0 + axios: 1.7.2(debug@4.3.6) + reflect-metadata: 0.2.2 + optionalDependencies: + '@lancedb/lancedb-darwin-arm64': 0.8.0 + '@lancedb/lancedb-darwin-x64': 0.8.0 + '@lancedb/lancedb-linux-arm64-gnu': 0.8.0 + '@lancedb/lancedb-linux-x64-gnu': 0.8.0 + '@lancedb/lancedb-win32-x64-msvc': 0.8.0 + transitivePeerDependencies: + - debug + '@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1': dependencies: eslint-scope: 5.1.1 @@ -1158,6 +1306,18 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@swc/helpers@0.5.12': + dependencies: + tslib: 2.6.3 + + '@types/command-line-args@5.2.3': {} + + '@types/command-line-usage@5.0.4': {} + + '@types/node@20.14.14': + dependencies: + undici-types: 5.26.5 + accepts@1.3.8: dependencies: mime-types: 2.1.35 @@ -1186,8 +1346,24 @@ snapshots: dependencies: color-convert: 2.0.1 + apache-arrow@17.0.0: + dependencies: + '@swc/helpers': 0.5.12 + '@types/command-line-args': 5.2.3 + '@types/command-line-usage': 5.0.4 + '@types/node': 20.14.14 + command-line-args: 5.2.1 + command-line-usage: 7.0.3 + flatbuffers: 24.3.25 + json-bignum: 0.0.3 + tslib: 2.6.3 + argparse@2.0.1: {} + array-back@3.1.0: {} + + array-back@6.2.2: {} + array-flatten@1.1.1: {} asynckit@0.4.0: {} @@ -1251,6 +1427,10 @@ snapshots: caniuse-lite@1.0.30001643: {} + chalk-template@0.4.0: + dependencies: + chalk: 4.1.2 + chalk@2.4.2: dependencies: ansi-styles: 3.2.1 @@ -1278,6 +1458,20 @@ snapshots: dependencies: delayed-stream: 1.0.0 + command-line-args@5.2.1: + dependencies: + array-back: 3.1.0 + find-replace: 3.0.0 + lodash.camelcase: 4.3.0 + typical: 4.0.0 + + command-line-usage@7.0.3: + dependencies: + array-back: 6.2.2 + chalk-template: 0.4.0 + table-layout: 4.1.1 + typical: 7.1.1 + concat-map@0.0.1: {} content-disposition@0.5.4: @@ -1491,6 +1685,10 @@ snapshots: transitivePeerDependencies: - supports-color + find-replace@3.0.0: + dependencies: + array-back: 3.1.0 + find-up@5.0.0: dependencies: locate-path: 6.0.0 @@ -1501,6 +1699,8 @@ snapshots: flatted: 3.3.1 keyv: 4.5.4 + flatbuffers@24.3.25: {} + flatted@3.3.1: {} follow-redirects@1.15.6(debug@4.3.6): @@ -1602,6 +1802,8 @@ snapshots: jsesc@2.5.2: {} + json-bignum@0.0.3: {} + json-buffer@3.0.1: {} json-schema-traverse@0.4.1: {} @@ -1627,6 +1829,8 @@ snapshots: dependencies: p-locate: 5.0.0 + lodash.camelcase@4.3.0: {} + lodash.merge@4.6.2: {} lru-cache@5.1.1: @@ -1740,6 +1944,8 @@ snapshots: iconv-lite: 0.4.24 unpipe: 1.0.0 + reflect-metadata@0.2.2: {} + resolve-from@4.0.0: {} reusify@1.0.4: {} @@ -1845,6 +2051,11 @@ snapshots: express: 4.19.2 swagger-ui-dist: 5.17.14 + table-layout@4.1.1: + dependencies: + array-back: 6.2.2 + wordwrapjs: 5.1.0 + tdigest@0.1.2: dependencies: bintrees: 1.0.2 @@ -1855,6 +2066,8 @@ snapshots: toidentifier@1.0.1: {} + tslib@2.6.3: {} + tsscmp@1.0.6: {} type-check@0.4.0: @@ -1866,6 +2079,12 @@ snapshots: media-typer: 0.3.0 mime-types: 2.1.35 + typical@4.0.0: {} + + typical@7.1.1: {} + + undici-types@5.26.5: {} + unpipe@1.0.0: {} update-browserslist-db@1.1.0(browserslist@4.23.2): @@ -1890,6 +2109,8 @@ snapshots: word-wrap@1.2.5: {} + wordwrapjs@5.1.0: {} + yallist@3.1.1: {} yocto-queue@0.1.0: {} diff --git a/tools/request.js b/tools/request.js index 9b57029..aa0d254 100644 --- a/tools/request.js +++ b/tools/request.js @@ -14,8 +14,8 @@ // limitations under the License. const BASE_URL = { - "chat": `http://${process.env.INFERENCE_ENG || 'llamacpp'}:${process.env.INFERENCE_ENG_PORT || 8080}`, - "rag": `http://${process.env.EMBEDDING_ENG || 'embedding_eng'}:${process.env.EMBEDDING_ENG_PORT || 8081}` + "chat": `http://${process.env.INFERENCE_ENG || 'llamacpp'}:${process.env.ENG_ACCESS_PORT || 8080}`, + "embedding": `http://${process.env.EMBEDDING_ENG || 'embedding_eng'}:${process.env.ENG_ACCESS_PORT || 8080}` } const default_options = { @@ -26,12 +26,13 @@ const default_options = { /** * @typedef RequestOptions - * @property {"rag"|"chat"} eng select between rag engine or chat engine, default value is `chat` + * @property {"embedding"|"chat"} eng select between embedding engine or chat engine, default value is `chat` * @property {Boolean} getJSON * * If set to `true`, this function will return the result of `await(await fetch(...)).json();` * and include an attribute `http_error: true` if there's any http error occurs during fetch(). * * If set to `false`, this function will return the result of `await fetch(...);`, without error handling * * default value is `true`; + * @property {String} URL specify the url of request instead of generated use base route */ /** @@ -45,7 +46,7 @@ export default async function request(url, options={}, request_options={}) { const eng = request_options.eng || "chat"; const getJSON = Object.hasOwn(request_options, 'getJSON') ? request_options.getJSON : true - url = `${BASE_URL[eng]}${url[0]!=='/' && '/'}${url}`; + url = request_options.URL || `${BASE_URL[eng]}${url[0]!=='/' && '/'}${url}`; options = { ...default_options,