|
|
@ -1,18 +1,20 @@ |
|
|
|
import {Plugin} from '@remixproject/engine' |
|
|
|
import {Plugin} from '@remixproject/engine' |
|
|
|
import {SuggestionService, SuggestOptions} from './suggestion-service' |
|
|
|
import {SuggestionService, SuggestOptions} from './suggestion-service' |
|
|
|
|
|
|
|
import axios, {AxiosResponse} from 'axios' |
|
|
|
const _paq = (window._paq = window._paq || []) //eslint-disable-line
|
|
|
|
const _paq = (window._paq = window._paq || []) //eslint-disable-line
|
|
|
|
|
|
|
|
|
|
|
|
const profile = { |
|
|
|
const profile = { |
|
|
|
name: 'copilot-suggestion', |
|
|
|
name: 'copilot-suggestion', |
|
|
|
displayName: 'copilot-suggestion', |
|
|
|
displayName: 'copilot-suggestion', |
|
|
|
description: 'Get Solidity suggestions in editor', |
|
|
|
description: 'Get Solidity suggestions in editor', |
|
|
|
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate'], |
|
|
|
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate', 'useRemoteService', 'discardRemoteService'], |
|
|
|
version: '0.1.0-alpha', |
|
|
|
version: '0.1.0-alpha', |
|
|
|
maintainedBy: "Remix" |
|
|
|
maintainedBy: "Remix" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class CopilotSuggestion extends Plugin { |
|
|
|
export class CopilotSuggestion extends Plugin { |
|
|
|
service: SuggestionService |
|
|
|
service: SuggestionService |
|
|
|
|
|
|
|
remoteService: string |
|
|
|
context: string |
|
|
|
context: string |
|
|
|
ready: boolean |
|
|
|
ready: boolean |
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
@ -29,6 +31,14 @@ export class CopilotSuggestion extends Plugin { |
|
|
|
})
|
|
|
|
})
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useRemoteService(service: string) { |
|
|
|
|
|
|
|
this.remoteService = service |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discardRemoteService() { |
|
|
|
|
|
|
|
this.remoteService = null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
status () { |
|
|
|
status () { |
|
|
|
return this.ready |
|
|
|
return this.ready |
|
|
|
} |
|
|
|
} |
|
|
@ -53,8 +63,15 @@ export class CopilotSuggestion extends Plugin { |
|
|
|
temperature: temperature || 0, |
|
|
|
temperature: temperature || 0, |
|
|
|
max_new_tokens: max_new_tokens || 0 |
|
|
|
max_new_tokens: max_new_tokens || 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.remoteService) { |
|
|
|
|
|
|
|
const {data} = await axios.post(this.remoteService, {context: content, max_new_words: options.max_new_tokens, temperature: options.temperature}) |
|
|
|
|
|
|
|
const parsedData = JSON.parse(data).trimStart() |
|
|
|
|
|
|
|
return {output: [{generated_text: parsedData}]} |
|
|
|
|
|
|
|
} else { |
|
|
|
return this.service.suggest(this.context ? this.context + '\n\n' + content : content, options) |
|
|
|
return this.service.suggest(this.context ? this.context + '\n\n' + content : content, options) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async loadModeContent() { |
|
|
|
async loadModeContent() { |
|
|
|
let importsContent = '' |
|
|
|
let importsContent = '' |
|
|
|