-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2398 from janhq/dev
Release cut 0.4.9
- Loading branch information
Showing
163 changed files
with
9,994 additions
and
2,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getJanDataFolderPath, joinPath } from '../../core' | ||
import { events } from '../../events' | ||
import { BaseExtension } from '../../extension' | ||
import { fs } from '../../fs' | ||
import { Model, ModelEvent } from '../../types' | ||
|
||
/** | ||
* Base AIEngine | ||
* Applicable to all AI Engines | ||
*/ | ||
export abstract class AIEngine extends BaseExtension { | ||
// The inference engine | ||
abstract provider: string | ||
// The model folder | ||
modelFolder: string = 'models' | ||
|
||
abstract models(): Promise<Model[]> | ||
|
||
/** | ||
* On extension load, subscribe to events. | ||
*/ | ||
onLoad() { | ||
this.prePopulateModels() | ||
} | ||
|
||
/** | ||
* Pre-populate models to App Data Folder | ||
*/ | ||
prePopulateModels(): Promise<void> { | ||
return this.models().then((models) => { | ||
const prePoluateOperations = models.map((model) => | ||
getJanDataFolderPath() | ||
.then((janDataFolder) => | ||
// Attempt to create the model folder | ||
joinPath([janDataFolder, this.modelFolder, model.id]).then((path) => | ||
fs | ||
.mkdirSync(path) | ||
.catch() | ||
.then(() => path) | ||
) | ||
) | ||
.then((path) => joinPath([path, 'model.json'])) | ||
.then((path) => { | ||
// Do not overwite existing model.json | ||
return fs.existsSync(path).then((exist: any) => { | ||
if (!exist) return fs.writeFileSync(path, JSON.stringify(model, null, 2)) | ||
}) | ||
}) | ||
.catch((e: Error) => { | ||
console.error('Error', e) | ||
}) | ||
) | ||
Promise.all(prePoluateOperations).then(() => | ||
// Emit event to update models | ||
// So the UI can update the models list | ||
events.emit(ModelEvent.OnModelsUpdate, {}) | ||
) | ||
}) | ||
} | ||
} |
Oops, something went wrong.