Skip to content

Commit 2271c8d

Browse files
Merge pull request #4822 from menloresearch/chore/add-option-to-not-revalidate-hardware-infor
chore: should have an option to not revalidate hardware information
2 parents 8c0f88f + 1d45670 commit 2271c8d

File tree

4 files changed

+41
-32
lines changed

4 files changed

+41
-32
lines changed

extensions/hardware-management-extension/src/index.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,28 @@ import PQueue from 'p-queue'
99
export default class JSONHardwareManagementExtension extends HardwareManagementExtension {
1010
queue = new PQueue({ concurrency: 1 })
1111

12-
/**
13-
* Extended API instance for making requests to the Cortex API.
14-
* @returns
15-
*/
16-
api: KyInstance
1712
/**
1813
* Called when the extension is loaded.
1914
*/
2015
async onLoad() {
21-
const apiKey = await window.core?.api.appToken() ?? 'cortex.cpp'
22-
this.api = ky.extend({
23-
prefixUrl: API_URL,
24-
headers: {
25-
Authorization: `Bearer ${apiKey}`,
26-
},
27-
})
2816
// Run Healthcheck
2917
this.queue.add(() => this.healthz())
3018
}
3119

20+
/**
21+
* Get the API instance
22+
* @returns
23+
*/
24+
async apiInstance(): Promise<KyInstance> {
25+
const apiKey = (await window.core?.api.appToken()) ?? 'cortex.cpp'
26+
return ky.extend({
27+
prefixUrl: API_URL,
28+
headers: {
29+
Authorization: `Bearer ${apiKey}`,
30+
},
31+
})
32+
}
33+
3234
/**
3335
* Called when the extension is unloaded.
3436
*/
@@ -39,22 +41,26 @@ export default class JSONHardwareManagementExtension extends HardwareManagementE
3941
* @returns
4042
*/
4143
async healthz(): Promise<void> {
42-
return this.api
43-
.get('healthz', {
44-
retry: { limit: 20, delay: () => 500, methods: ['get'] },
45-
})
46-
.then(() => {})
44+
return this.apiInstance().then((api) =>
45+
api
46+
.get('healthz', {
47+
retry: { limit: 20, delay: () => 500, methods: ['get'] },
48+
})
49+
.then(() => {})
50+
)
4751
}
4852

4953
/**
5054
* @returns A Promise that resolves to an object of hardware.
5155
*/
5256
async getHardware(): Promise<HardwareInformation> {
5357
return this.queue.add(() =>
54-
this.api
55-
.get('v1/hardware')
56-
.json<HardwareInformation>()
57-
.then((e) => e)
58+
this.apiInstance().then((api) =>
59+
api
60+
.get('v1/hardware')
61+
.json<HardwareInformation>()
62+
.then((e) => e)
63+
)
5864
) as Promise<HardwareInformation>
5965
}
6066

@@ -66,7 +72,9 @@ export default class JSONHardwareManagementExtension extends HardwareManagementE
6672
activated_gpus: number[]
6773
}> {
6874
return this.queue.add(() =>
69-
this.api.post('v1/hardware/activate', { json: data }).then((e) => e)
75+
this.apiInstance().then((api) =>
76+
api.post('v1/hardware/activate', { json: data }).then((e) => e)
77+
)
7078
) as Promise<{
7179
message: string
7280
activated_gpus: number[]

extensions/model-extension/src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class JanModelExtension extends ModelExtension {
9595
*/
9696
return this.queue.add(() =>
9797
this.api
98-
.post('v1/models/pull', { json: { model, id, name } })
98+
.post('v1/models/pull', { json: { model, id, name }, timeout: false })
9999
.json()
100100
.catch(async (e) => {
101101
throw (await e.response?.json()) ?? e
@@ -232,7 +232,10 @@ export default class JanModelExtension extends ModelExtension {
232232
return this.queue
233233
.add(() =>
234234
this.api
235-
.patch(`v1/models/${model.id}`, { json: { ...model } })
235+
.patch(`v1/models/${model.id}`, {
236+
json: { ...model },
237+
timeout: false,
238+
})
236239
.json()
237240
.then()
238241
)
@@ -267,6 +270,7 @@ export default class JanModelExtension extends ModelExtension {
267270
this.api
268271
.post('v1/models/import', {
269272
json: { model, modelPath, name, option },
273+
timeout: false,
270274
})
271275
.json()
272276
.catch((e) => console.debug(e)) // Ignore error
@@ -313,6 +317,7 @@ export default class JanModelExtension extends ModelExtension {
313317
json: {
314318
source,
315319
},
320+
timeout: false,
316321
})
317322
)
318323
}
@@ -382,11 +387,7 @@ export default class JanModelExtension extends ModelExtension {
382387
[key: string]: any
383388
}): Promise<void> {
384389
return this.queue
385-
.add(() =>
386-
this.api
387-
.patch('v1/configs', { json: body })
388-
.then(() => {})
389-
)
390+
.add(() => this.api.patch('v1/configs', { json: body }).then(() => {}))
390391
.catch((e) => console.debug(e))
391392
}
392393

web/containers/Providers/DataLoader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const DataLoader: React.FC = () => {
3535
const setJanSettingScreen = useSetAtom(janSettingScreenAtom)
3636
const { getData: loadModels } = useModels()
3737
const { mutate } = useGetEngines()
38-
const { mutate: getHardwareInfo } = useGetHardwareInfo()
38+
const { mutate: getHardwareInfo } = useGetHardwareInfo(false)
3939

4040
useThreads()
4141
useAssistants()

web/hooks/useHardwareManagement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const getExtension = () =>
3232
/**
3333
* @returns A Promise that resolves to an object of list engines.
3434
*/
35-
export function useGetHardwareInfo() {
35+
export function useGetHardwareInfo(updatePeriodically: boolean = true) {
3636
const setCpuUsage = useSetAtom(cpuUsageAtom)
3737
const setUsedRam = useSetAtom(usedRamAtom)
3838
const setTotalRam = useSetAtom(totalRamAtom)
@@ -56,7 +56,7 @@ export function useGetHardwareInfo() {
5656
{
5757
revalidateOnFocus: false,
5858
revalidateOnReconnect: false,
59-
refreshInterval: 2000,
59+
refreshInterval: updatePeriodically ? 2000 : undefined,
6060
}
6161
)
6262

0 commit comments

Comments
 (0)