Skip to content

Commit

Permalink
Merge pull request #4021 from janhq/main
Browse files Browse the repository at this point in the history
Sync release 0.5.8 to dev
  • Loading branch information
louis-jan authored Nov 14, 2024
2 parents e196aef + 54e8421 commit 3b48cb5
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions extensions/inference-cortex-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
extractModelLoadParams,
fs,
events,
ModelEvent
ModelEvent,
} from '@janhq/core'
import PQueue from 'p-queue'
import ky from 'ky'
Expand Down Expand Up @@ -45,6 +45,8 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {

provider: string = InferenceEngine.cortex

shouldReconnect = true

/**
* The URL for making inference requests.
*/
Expand Down Expand Up @@ -80,6 +82,8 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
}

onUnload(): void {
console.log('Clean up cortex.cpp services')
this.shouldReconnect = false
this.clean()
executeOnMain(NODE, 'dispose')
super.onUnload()
Expand Down Expand Up @@ -157,7 +161,7 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
methods: ['get'],
},
})
.then(() => { })
.then(() => {})
}

/**
Expand Down Expand Up @@ -195,14 +199,17 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
)
const percent = total > 0 ? transferred / total : 0

events.emit(DownloadTypes[data.type as keyof typeof DownloadTypes], {
modelId: data.task.id,
percent: percent,
size: {
transferred: transferred,
total: total,
},
})
events.emit(
DownloadTypes[data.type as keyof typeof DownloadTypes],
{
modelId: data.task.id,
percent: percent,
size: {
transferred: transferred,
total: total,
},
}
)
// Update models list from Hub
if (data.type === DownloadTypes.DownloadSuccess) {
// Delay for the state update from cortex.cpp
Expand All @@ -212,11 +219,19 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
}, 500)
}
})

this.socket.onclose = (event) => {
console.log('WebSocket closed:', event)
if (this.shouldReconnect) {
console.log(`Attempting to reconnect...`)
setTimeout(() => this.subscribeToEvents(), 1000)
}
}

resolve()
})
)
}

}

/// Legacy
Expand Down

0 comments on commit 3b48cb5

Please sign in to comment.