From e9d55e23046643ccb9cce2c22f76e9bdfaa8835f Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 5 Jan 2024 23:15:51 +0700 Subject: [PATCH 1/3] fix: GET /models does not work due to new default model dir (#1392) --- core/src/node/api/common/builder.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/core/src/node/api/common/builder.ts b/core/src/node/api/common/builder.ts index 4081e859f..54ce9159f 100644 --- a/core/src/node/api/common/builder.ts +++ b/core/src/node/api/common/builder.ts @@ -14,14 +14,13 @@ const path = join(os.homedir(), 'jan') export const getBuilder = async (configuration: RouteConfiguration) => { const directoryPath = join(path, configuration.dirName) - try { - if (!(await fs.existsSync(directoryPath))) { + if (!fs.existsSync(directoryPath)) { console.debug('model folder not found') return [] } - const files: string[] = await fs.readdirSync(directoryPath) + const files: string[] = fs.readdirSync(directoryPath) const allDirectories: string[] = [] for (const file of files) { @@ -29,12 +28,12 @@ export const getBuilder = async (configuration: RouteConfiguration) => { allDirectories.push(file) } - const readJsonPromises = allDirectories.map(async (dirName) => { - const jsonPath = join(directoryPath, dirName, configuration.metadataFileName) - return await readModelMetadata(jsonPath) - }) - - const results = await Promise.all(readJsonPromises) + const results = allDirectories + .map((dirName) => { + const jsonPath = join(directoryPath, dirName, configuration.metadataFileName) + return readModelMetadata(jsonPath) + }) + .filter((data) => !!data) const modelData = results .map((result: any) => { try { @@ -52,8 +51,12 @@ export const getBuilder = async (configuration: RouteConfiguration) => { } } -const readModelMetadata = async (path: string) => { - return fs.readFileSync(path, 'utf-8') +const readModelMetadata = (path: string): string | undefined => { + if (fs.existsSync(path)) { + return fs.readFileSync(path, 'utf-8') + } else { + return undefined + } } export const retrieveBuilder = async (configuration: RouteConfiguration, id: string) => { @@ -99,7 +102,7 @@ export const getMessages = async (threadId: string) => { const threadDirPath = join(path, 'threads', threadId) const messageFile = 'messages.jsonl' try { - const files: string[] = await fs.readdirSync(threadDirPath) + const files: string[] = fs.readdirSync(threadDirPath) if (!files.includes(messageFile)) { throw Error(`${threadDirPath} not contains message file`) } From 6abdf51c28b35f671eb230b2e1c60b95323c571a Mon Sep 17 00:00:00 2001 From: Service Account Date: Fri, 5 Jan 2024 16:33:50 +0000 Subject: [PATCH 2/3] janhq/jan: Update README.md with nightly build artifact URL --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9d02d181d..5be6bbedd 100644 --- a/README.md +++ b/README.md @@ -70,25 +70,25 @@ Jan is an open-source ChatGPT alternative that runs 100% offline on your compute Experimental (Nightly Build) - + jan.exe - + Intel - + M1/M2 - + jan.deb From 1eeaca1144b7b47e20eca10d537b2b15dda76d8d Mon Sep 17 00:00:00 2001 From: Service Account Date: Fri, 5 Jan 2024 20:18:22 +0000 Subject: [PATCH 3/3] janhq/jan: Update README.md with nightly build artifact URL --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5be6bbedd..cb09f70fa 100644 --- a/README.md +++ b/README.md @@ -70,25 +70,25 @@ Jan is an open-source ChatGPT alternative that runs 100% offline on your compute Experimental (Nightly Build) - + jan.exe - + Intel - + M1/M2 - + jan.deb