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