reverted the inline completion to browser model

explain_function
Stéphane Tetsing 12 months ago
parent 0c99119f7f
commit b8c8d4014d
  1. 36
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts
  2. 4
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts
  3. 16
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/worker.js
  4. 2
      apps/remix-ide/src/app/tabs/locales/en/settings.json
  5. 2
      apps/remix-ide/src/app/tabs/settings-tab.tsx
  6. 8355
      diff.diff
  7. 8
      libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts
  8. 48
      libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

@ -8,31 +8,36 @@ const profile = {
name: 'copilot-suggestion',
displayName: 'copilot-suggestion',
description: 'Get Solidity suggestions in editor',
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate', 'discardRemoteService', 'useconfig'],
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate', 'useRemoteService', 'discardRemoteService'],
version: '0.1.0-alpha',
maintainedBy: "Remix"
}
export class CopilotSuggestion extends Plugin {
service: SuggestionService
remoteService: string
context: string
ready: boolean
config: { [id: string]: string }
constructor() {
super(profile)
this.service = new SuggestionService()
this.context = ''
this.ready = true // always ready for service
this.config = {}
this.service.events.on('progress', (data) => {
this.emit('loading', data)
})
this.service.events.on('done', (data) => {
})
this.service.events.on('ready', (data) => {
this.ready = true
})
}
useconfig(config ){
this.config = config
useRemoteService(service: string) {
this.remoteService = service
}
discardRemoteService() {
this.ready = false
this.remoteService = null
}
status () {
@ -54,19 +59,20 @@ export class CopilotSuggestion extends Plugin {
const max_new_tokens = await this.call('settings', 'get', 'settings/copilot/suggest/max_new_tokens')
const temperature = await this.call('settings', 'get', 'settings/copilot/suggest/temperature')
const options: SuggestOptions = {
do_sample: true,
top_k: 50,
top_p: 0.92,
top_p: 0.92,
stream_result: false,
temperature: temperature || 0.9,
temperature: temperature || 0,
max_new_tokens: max_new_tokens || 0
}
if (this.ready){
const data = await this.call('solcoder', 'code_completion', content.split(" ").slice(-1000).join(" "), options)
const parsedData = data[0].trimStart()
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
} else {
return this.service.suggest(this.context ? this.context + '\n\n' + content : content, options)
}
}

@ -1,7 +1,8 @@
import EventEmitter from 'events'
export type SuggestOptions = { max_new_tokens: number,
temperature: number,
temperature: number,
do_sample:boolean
top_k: number,
top_p:number,
stream_result:boolean}
@ -16,6 +17,7 @@ export class SuggestionService {
this.worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module'
});
this.init()
this.events = new EventEmitter()
this.responses = {}
this.current

@ -34,12 +34,12 @@ self.addEventListener('message', async (event) => {
if (cmd === 'init') {
// Retrieve the code-completion pipeline. When called for the first time,
// this will load the pipeline and save it for future use.
// CodeCompletionPipeline.model = model
// await CodeCompletionPipeline.getInstance(x => {
// // We also add a progress callback to the pipeline so that we can
// // track model loading.
// self.postMessage(x);
// });
CodeCompletionPipeline.model = model
await CodeCompletionPipeline.getInstance(x => {
// We also add a progress callback to the pipeline so that we can
// track model loading.
self.postMessage(x);
});
return
}
@ -47,8 +47,8 @@ self.addEventListener('message', async (event) => {
// Send the output back to the main thread
self.postMessage({
id,
status: 'info',
message: 'model not longer supported'
status: 'error',
message: 'model not yet loaded'
});
}

@ -38,7 +38,7 @@
"settings.projectSecret": "PROJECT SECRET",
"settings.analyticsInRemix": "Analytics in Remix IDE",
"settings.copilot": "Solidity copilot - Alpha",
"settings.copilot.activate": "Enable copilot",
"settings.copilot.activate": "Load & Activate copilot",
"settings.copilot.max_new_tokens": "Maximum number of words to generate",
"settings.copilot.temperature": "Temperature",
"settings.copilot.top_k": "top_k",

@ -52,7 +52,7 @@ module.exports = class SettingsTab extends ViewPlugin {
this.element = document.createElement('div')
this.element.setAttribute('id', 'settingsTab')
this.useMatomoAnalytics = null
this.useCopilot = null
this.useCopilot = false
}
setDispatch(dispatch: React.Dispatch<any>) {

File diff suppressed because it is too large Load Diff

@ -31,7 +31,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
});
if (!word.endsWith('\n') &&
if (!word.endsWith(' ') &&
!word.endsWith(';') &&
!word.endsWith('.') &&
!word.endsWith('(')) {
@ -94,8 +94,12 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
}
const generatedText = (result as any).output[0].generated_text as string
const clean = generatedText
let clean = generatedText
console.log('solcoder inline data:\n', clean)
if (generatedText.indexOf('@custom:dev-run-script./') !== -1) {
clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ')
}
clean = clean.replace(word, '')
const item: monacoTypes.languages.InlineCompletion = {
insertText: clean

@ -136,15 +136,49 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
props.plugin.call('copilot-suggestion', 'uninstall')
return
}
if (await props.plugin.call('copilot-suggestion', 'status')) {
copilotActivate(props.config, true, dispatch)
} else {
props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch)
const message = <div>Please wait while the copilot is downloaded. <span ref={copilotDownload}>0</span>/100 .</div>
props.plugin.on('copilot-suggestion', 'loading', (data) => {
if (!copilotDownload.current) return
const loaded = ((data.loaded / data.total) * 100).toString()
const dot = loaded.match(/(.*)\./g)
copilotDownload.current.innerText = dot ? dot[0].replace('.', '') : loaded
})
const modalActivate: AppModal = {
id: 'loadcopilotActivate',
title: 'Download Solidity copilot',
modalType: ModalTypes.default,
okLabel: 'Close',
message,
okFn: async() => {
props.plugin.off('copilot-suggestion', 'loading')
if (await props.plugin.call('copilot-suggestion', 'status')) {
copilotActivate(props.config, true, dispatch)
} else {
props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch)
}
},
hideFn: async () => {
props.plugin.off('copilot-suggestion', 'loading')
if (await props.plugin.call('copilot-suggestion', 'status')) {
copilotActivate(props.config, true, dispatch)
} else {
props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch)
}
}
}
if (await props.plugin.call('copilot-suggestion', 'status')) {
copilotActivate(props.config, true, dispatch)
} else {
props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch)
}
props.plugin.call('copilot-suggestion', 'init')
props.plugin.call('copilot-suggestion', 'init')
props.plugin.call('notification', 'modal', modalActivate)
}
const onchangeCopilotMaxNewToken = (event) => {

Loading…
Cancel
Save