fix: attempt to establish the WebSocket connection on a connection issue
This commit is contained in:
parent
31d0b8d336
commit
8053ff9eb8
@ -17,7 +17,7 @@ import {
|
|||||||
extractModelLoadParams,
|
extractModelLoadParams,
|
||||||
fs,
|
fs,
|
||||||
events,
|
events,
|
||||||
ModelEvent
|
ModelEvent,
|
||||||
} from '@janhq/core'
|
} from '@janhq/core'
|
||||||
import PQueue from 'p-queue'
|
import PQueue from 'p-queue'
|
||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
@ -45,6 +45,8 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
|
|
||||||
provider: string = InferenceEngine.cortex
|
provider: string = InferenceEngine.cortex
|
||||||
|
|
||||||
|
shouldReconnect = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL for making inference requests.
|
* The URL for making inference requests.
|
||||||
*/
|
*/
|
||||||
@ -80,6 +82,8 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onUnload(): void {
|
onUnload(): void {
|
||||||
|
console.log('Clean up cortex.cpp services')
|
||||||
|
this.shouldReconnect = false
|
||||||
this.clean()
|
this.clean()
|
||||||
executeOnMain(NODE, 'dispose')
|
executeOnMain(NODE, 'dispose')
|
||||||
super.onUnload()
|
super.onUnload()
|
||||||
@ -157,7 +161,7 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
methods: ['get'],
|
methods: ['get'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => { })
|
.then(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,14 +199,17 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
)
|
)
|
||||||
const percent = total > 0 ? transferred / total : 0
|
const percent = total > 0 ? transferred / total : 0
|
||||||
|
|
||||||
events.emit(DownloadTypes[data.type as keyof typeof DownloadTypes], {
|
events.emit(
|
||||||
modelId: data.task.id,
|
DownloadTypes[data.type as keyof typeof DownloadTypes],
|
||||||
percent: percent,
|
{
|
||||||
size: {
|
modelId: data.task.id,
|
||||||
transferred: transferred,
|
percent: percent,
|
||||||
total: total,
|
size: {
|
||||||
},
|
transferred: transferred,
|
||||||
})
|
total: total,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
// Update models list from Hub
|
// Update models list from Hub
|
||||||
if (data.type === DownloadTypes.DownloadSuccess) {
|
if (data.type === DownloadTypes.DownloadSuccess) {
|
||||||
// Delay for the state update from cortex.cpp
|
// Delay for the state update from cortex.cpp
|
||||||
@ -212,11 +219,19 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.socket.onclose = (event) => {
|
||||||
|
console.log('WebSocket closed:', event)
|
||||||
|
if (this.shouldReconnect) {
|
||||||
|
console.log(`Attempting to reconnect...`)
|
||||||
|
setTimeout(() => this.subscribeToEvents(), 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Legacy
|
/// Legacy
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user