chore: should have an option to not revalidate hardware information
This commit is contained in:
parent
8c0f88fb4e
commit
1d4567082b
@ -9,26 +9,28 @@ import PQueue from 'p-queue'
|
||||
export default class JSONHardwareManagementExtension extends HardwareManagementExtension {
|
||||
queue = new PQueue({ concurrency: 1 })
|
||||
|
||||
/**
|
||||
* Extended API instance for making requests to the Cortex API.
|
||||
* @returns
|
||||
*/
|
||||
api: KyInstance
|
||||
/**
|
||||
* Called when the extension is loaded.
|
||||
*/
|
||||
async onLoad() {
|
||||
const apiKey = await window.core?.api.appToken() ?? 'cortex.cpp'
|
||||
this.api = ky.extend({
|
||||
prefixUrl: API_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
})
|
||||
// Run Healthcheck
|
||||
this.queue.add(() => this.healthz())
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the API instance
|
||||
* @returns
|
||||
*/
|
||||
async apiInstance(): Promise<KyInstance> {
|
||||
const apiKey = (await window.core?.api.appToken()) ?? 'cortex.cpp'
|
||||
return ky.extend({
|
||||
prefixUrl: API_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the extension is unloaded.
|
||||
*/
|
||||
@ -39,11 +41,13 @@ export default class JSONHardwareManagementExtension extends HardwareManagementE
|
||||
* @returns
|
||||
*/
|
||||
async healthz(): Promise<void> {
|
||||
return this.api
|
||||
.get('healthz', {
|
||||
retry: { limit: 20, delay: () => 500, methods: ['get'] },
|
||||
})
|
||||
.then(() => {})
|
||||
return this.apiInstance().then((api) =>
|
||||
api
|
||||
.get('healthz', {
|
||||
retry: { limit: 20, delay: () => 500, methods: ['get'] },
|
||||
})
|
||||
.then(() => {})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,10 +55,12 @@ export default class JSONHardwareManagementExtension extends HardwareManagementE
|
||||
*/
|
||||
async getHardware(): Promise<HardwareInformation> {
|
||||
return this.queue.add(() =>
|
||||
this.api
|
||||
.get('v1/hardware')
|
||||
.json<HardwareInformation>()
|
||||
.then((e) => e)
|
||||
this.apiInstance().then((api) =>
|
||||
api
|
||||
.get('v1/hardware')
|
||||
.json<HardwareInformation>()
|
||||
.then((e) => e)
|
||||
)
|
||||
) as Promise<HardwareInformation>
|
||||
}
|
||||
|
||||
@ -66,7 +72,9 @@ export default class JSONHardwareManagementExtension extends HardwareManagementE
|
||||
activated_gpus: number[]
|
||||
}> {
|
||||
return this.queue.add(() =>
|
||||
this.api.post('v1/hardware/activate', { json: data }).then((e) => e)
|
||||
this.apiInstance().then((api) =>
|
||||
api.post('v1/hardware/activate', { json: data }).then((e) => e)
|
||||
)
|
||||
) as Promise<{
|
||||
message: string
|
||||
activated_gpus: number[]
|
||||
|
||||
@ -95,7 +95,7 @@ export default class JanModelExtension extends ModelExtension {
|
||||
*/
|
||||
return this.queue.add(() =>
|
||||
this.api
|
||||
.post('v1/models/pull', { json: { model, id, name } })
|
||||
.post('v1/models/pull', { json: { model, id, name }, timeout: false })
|
||||
.json()
|
||||
.catch(async (e) => {
|
||||
throw (await e.response?.json()) ?? e
|
||||
@ -232,7 +232,10 @@ export default class JanModelExtension extends ModelExtension {
|
||||
return this.queue
|
||||
.add(() =>
|
||||
this.api
|
||||
.patch(`v1/models/${model.id}`, { json: { ...model } })
|
||||
.patch(`v1/models/${model.id}`, {
|
||||
json: { ...model },
|
||||
timeout: false,
|
||||
})
|
||||
.json()
|
||||
.then()
|
||||
)
|
||||
@ -267,6 +270,7 @@ export default class JanModelExtension extends ModelExtension {
|
||||
this.api
|
||||
.post('v1/models/import', {
|
||||
json: { model, modelPath, name, option },
|
||||
timeout: false,
|
||||
})
|
||||
.json()
|
||||
.catch((e) => console.debug(e)) // Ignore error
|
||||
@ -313,6 +317,7 @@ export default class JanModelExtension extends ModelExtension {
|
||||
json: {
|
||||
source,
|
||||
},
|
||||
timeout: false,
|
||||
})
|
||||
)
|
||||
}
|
||||
@ -382,11 +387,7 @@ export default class JanModelExtension extends ModelExtension {
|
||||
[key: string]: any
|
||||
}): Promise<void> {
|
||||
return this.queue
|
||||
.add(() =>
|
||||
this.api
|
||||
.patch('v1/configs', { json: body })
|
||||
.then(() => {})
|
||||
)
|
||||
.add(() => this.api.patch('v1/configs', { json: body }).then(() => {}))
|
||||
.catch((e) => console.debug(e))
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ const DataLoader: React.FC = () => {
|
||||
const setJanSettingScreen = useSetAtom(janSettingScreenAtom)
|
||||
const { getData: loadModels } = useModels()
|
||||
const { mutate } = useGetEngines()
|
||||
const { mutate: getHardwareInfo } = useGetHardwareInfo()
|
||||
const { mutate: getHardwareInfo } = useGetHardwareInfo(false)
|
||||
|
||||
useThreads()
|
||||
useAssistants()
|
||||
|
||||
@ -32,7 +32,7 @@ const getExtension = () =>
|
||||
/**
|
||||
* @returns A Promise that resolves to an object of list engines.
|
||||
*/
|
||||
export function useGetHardwareInfo() {
|
||||
export function useGetHardwareInfo(updatePeriodically: boolean = true) {
|
||||
const setCpuUsage = useSetAtom(cpuUsageAtom)
|
||||
const setUsedRam = useSetAtom(usedRamAtom)
|
||||
const setTotalRam = useSetAtom(totalRamAtom)
|
||||
@ -56,7 +56,7 @@ export function useGetHardwareInfo() {
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
refreshInterval: 2000,
|
||||
refreshInterval: updatePeriodically ? 2000 : undefined,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user