Merge branch 'main' into docs/improve-syntax

This commit is contained in:
0xSage 2024-01-06 09:47:23 +08:00 committed by GitHub
commit a747ed24f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View File

@ -70,25 +70,25 @@ Jan is an open-source ChatGPT alternative that runs 100% offline on your compute
<tr style="text-align:center">
<td style="text-align:center"><b>Experimental (Nightly Build)</b></td>
<td style="text-align:center">
<a href='https://delta.jan.ai/0.4.3-124/jan-win-x64-0.4.3-124.exe'>
<a href='https://delta.jan.ai/0.4.3-126/jan-win-x64-0.4.3-126.exe'>
<img src='./docs/static/img/windows.png' style="height:14px; width: 14px" />
<b>jan.exe</b>
</a>
</td>
<td style="text-align:center">
<a href='https://delta.jan.ai/0.4.3-124/jan-mac-x64-0.4.3-124.dmg'>
<a href='https://delta.jan.ai/0.4.3-126/jan-mac-x64-0.4.3-126.dmg'>
<img src='./docs/static/img/mac.png' style="height:15px; width: 15px" />
<b>Intel</b>
</a>
</td>
<td style="text-align:center">
<a href='https://delta.jan.ai/0.4.3-124/jan-mac-arm64-0.4.3-124.dmg'>
<a href='https://delta.jan.ai/0.4.3-126/jan-mac-arm64-0.4.3-126.dmg'>
<img src='./docs/static/img/mac.png' style="height:15px; width: 15px" />
<b>M1/M2</b>
</a>
</td>
<td style="text-align:center">
<a href='https://delta.jan.ai/0.4.3-124/jan-linux-amd64-0.4.3-124.deb'>
<a href='https://delta.jan.ai/0.4.3-126/jan-linux-amd64-0.4.3-126.deb'>
<img src='./docs/static/img/linux.png' style="height:14px; width: 14px" />
<b>jan.deb</b>
</a>

View File

@ -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`)
}