feat: configure HuggingfaceToken via cortex.cpp

This commit is contained in:
Louis 2024-11-21 13:13:29 +07:00
parent e2a45095b2
commit fe6412e1d4
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -20,6 +20,10 @@ import { deleteModelFiles } from './legacy/delete'
declare const SETTINGS: Array<any>
export enum Settings {
huggingfaceToken = 'hugging-face-access-token',
}
/**
* A extension for models
*/
@ -33,10 +37,29 @@ export default class JanModelExtension extends ModelExtension {
async onLoad() {
this.registerSettings(SETTINGS)
// Configure huggingface token if available
const huggingfaceToken = await this.getSetting<string>(
Settings.huggingfaceToken,
undefined
)
if (huggingfaceToken)
this.cortexAPI.configs({ huggingface_token: huggingfaceToken })
// Listen to app download events
this.handleDesktopEvents()
}
/**
* Subscribe to settings update and make change accordingly
* @param key
* @param value
*/
onSettingUpdate<T>(key: string, value: T): void {
if (key === Settings.huggingfaceToken) {
this.cortexAPI.configs({ huggingface_token: value })
}
}
/**
* Called when the extension is unloaded.
* @override