parent
8ed1077cb2
commit
ea506080a8
@ -1,56 +1,41 @@ |
||||
import { ElectronPlugin } from '@remixproject/engine-electron' |
||||
import { IModel, ModelType, DefaultModels } from '@remix/remix-ai-core'; |
||||
import axios from 'axios'; |
||||
import fs from 'fs'; |
||||
import { Model } from '@remix/remix-ai-core'; |
||||
|
||||
const desktop_profile = { |
||||
name: 'remixAID', |
||||
displayName: 'RemixAI Desktop', |
||||
maintainedBy: 'Remix', |
||||
description: 'RemixAI provides AI services to Remix IDE Desktop.', |
||||
documentation: 'https://remix-ide.readthedocs.io/en/latest/remixai.html', |
||||
icon: 'assets/img/remix-logo-blue.png', |
||||
methods: ['downloadModel'], |
||||
} |
||||
|
||||
export class remixAIDesktopPlugin extends ElectronPlugin { |
||||
selectedModel: IModel | null = DefaultModels()[0] |
||||
constructor() { |
||||
console.log('remixAIDesktopPlugin') |
||||
console.log('remixAIDesktopPlugin loaded') |
||||
super(desktop_profile) |
||||
|
||||
this |
||||
|
||||
} |
||||
|
||||
onActivation(): void { |
||||
this.on('remixAI', 'enabled', () => {console.log('someone enable the remixAI desktop plugin')} ) |
||||
console.log('remixAIDesktopPlugin ---------------------- activated') |
||||
console.log('remixAIDesktopPlugin Model: ', this.selectedModel)
|
||||
} |
||||
|
||||
async downloadModel(model: Model, outputLocationPath: string): Promise<void> { |
||||
console.log(`Downloading model ${model.name}`) |
||||
|
||||
// Make a HEAD request to get the file size
|
||||
const { headers } = await axios.head(model.download_url); |
||||
const totalSize = parseInt(headers['content-length'], 10); |
||||
|
||||
// Create a write stream to save the file
|
||||
const writer = fs.createWriteStream(outputLocationPath); |
||||
|
||||
// Start the file download
|
||||
const response = await axios({ |
||||
method: 'get', |
||||
url: model.download_url, |
||||
responseType: 'stream' |
||||
}); |
||||
|
||||
let downloadedSize = 0; |
||||
|
||||
response.data.on('data', (chunk: Buffer) => { |
||||
downloadedSize += chunk.length; |
||||
const progress = (downloadedSize / totalSize) * 100; |
||||
this.emit('download_progress', progress); |
||||
}); |
||||
|
||||
response.data.pipe(writer); |
||||
|
||||
} |
||||
|
||||
return new Promise((resolve, reject) => { |
||||
writer.on('finish', resolve); |
||||
writer.on('error', reject); |
||||
}); |
||||
} |
||||
} |
||||
// class RemixAIPlugin extends ElectronPlugin {
|
||||
// constructor() {
|
||||
// super(dek)
|
||||
// this.methods = ['downloadModel']
|
||||
// }
|
||||
// }
|
@ -1,7 +1,8 @@ |
||||
'use strict' |
||||
|
||||
import { Model, ModelResponse, ModelRequest, InferenceModel} from './types/types' |
||||
import { IModel, IModelResponse, IModelRequest, InferenceModel} from './types/types' |
||||
import { ModelType } from './types/constants'
|
||||
import { DefaultModels } from './types/models'
|
||||
|
||||
|
||||
export { Model, ModelResponse, ModelRequest, InferenceModel } |
||||
export { IModel, IModelResponse, IModelRequest, InferenceModel, ModelType, DefaultModels} |
Loading…
Reference in new issue