Skip to content

Commit

Permalink
Merge pull request #4286 from ethereum/copilotImprove
Browse files Browse the repository at this point in the history
Solidity copilot improvements
  • Loading branch information
yann300 authored Nov 30, 2023
2 parents a5e99c0 + bfd0159 commit 64b4d78
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const _paq = (window._paq = window._paq || []) //eslint-disable-line
const profile = {
name: 'copilot-suggestion',
displayName: 'copilot-suggestion',
description: 'copilot-suggestion',
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate']
description: 'Get Solidity suggestions in editor',
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate'],
version: '0.1.0-alpha',
maintainedBy: "Remix"
}

export class CopilotSuggestion extends Plugin {
Expand Down Expand Up @@ -45,7 +47,6 @@ 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')
console.log('suggest', max_new_tokens, temperature)
const options: SuggestOptions = {
do_sample: false,
top_k: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,31 @@ export class SuggestionService {
const onMessageReceived = (e) => {
switch (e.data.status) {
case 'initiate':
console.log(e.data)
this.events.emit(e.data.status, e.data)
// Model file start load: add a new progress item to the list.
break;

case 'progress':
this.events.emit(e.data.status, e.data)
console.log(e.data)
// Model file progress: update one of the progress items.
break;

case 'done':
this.events.emit(e.data.status, e.data)
console.log(e.data)
// Model file loaded: remove the progress item from the list.
break;

case 'ready':
this.events.emit(e.data.status, e.data)
console.log(e.data)
// Pipeline ready: the worker is ready to accept messages.
break;

case 'update':
this.events.emit(e.data.status, e.data)
console.log(e.data)
// Generation update: update the output text.
break;

case 'complete':
console.log(e.data)
if (this.responses[e.data.id]) {
if (this.current === e.data.id) {
this.responses[e.data.id](null, e.data)
Expand All @@ -67,8 +61,6 @@ export class SuggestionService {
}
delete this.responses[e.data.id]
this.current = null
} else {
console.log('no callback for', e.data)
}

// Generation complete: re-enable the "Generate" button
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide/src/app/tabs/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"settings.analyticsInRemix": "Analytics in Remix IDE",
"settings.copilot": "Solidity copilot - Alpha",
"settings.copilot.activate": "Load & Activate copilot",
"settings.copilot.max_new_tokens": "Maximum amount of new words to generate",
"settings.copilot.max_new_tokens": "Maximum number of words to generate",
"settings.copilot.temperature": "Temperature"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli

async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> {
if (context.selectedSuggestionInfo) {
console.log('return empty from provideInlineCompletions')
return;
}
// get text before the position of the completion
Expand All @@ -27,7 +26,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
});

if (!word.endsWith(' ') && !word.endsWith('\n') && !word.endsWith(';') && !word.endsWith('.')) {
console.log('not a trigger char')
return;
}

Expand All @@ -40,13 +38,12 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli

try {
const split = word.split('\n')
if (!split.length) return
if (split.length < 2) return
const ask = split[split.length - 2].trimStart()
if (split[split.length - 1].trim() === '' && ask.startsWith('///')) {
// use the code generation model
const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: ask.replace('///', '')})
const parsedData = JSON.parse(data).trimStart()
console.log('parsedData', parsedData)
const item: monacoTypes.languages.InlineCompletion = {
insertText: parsedData
};
Expand All @@ -61,7 +58,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli

// abort if there is a signal
if (token.isCancellationRequested) {
console.log('aborted')
return
}

Expand All @@ -81,7 +77,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli

// abort if there is a signal
if (token.isCancellationRequested) {
console.log('aborted')
return
}
return {
Expand Down
6 changes: 3 additions & 3 deletions libs/remix-ui/settings/src/lib/remix-ui-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
})
const modalActivate: AppModal = {
id: 'loadcopilotActivate',
title: 'Downloading Solidity copilot',
title: 'Download Solidity copilot',
modalType: ModalTypes.default,
okLabel: 'Close',
message,
Expand Down Expand Up @@ -466,7 +466,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<div className="text-secondary mb-0 h6">
<div>
<div className="mb-1">
<label className={`align-middle ${getTextClass('settings/copilot/suggest/max_new_tokens')}`} htmlFor="copilot-activate">
<label className={`form-check-label align-middle ${getTextClass('settings/copilot/suggest/max_new_tokens')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.max_new_tokens" /> - <span>{copilotMaxnewToken}</span>
</label>
<input onChange={onchangeCopilotMaxNewToken} id="copilot-max-new-token" value={copilotMaxnewToken} min='1' max='150' type="range" className="custom-range" />
Expand All @@ -479,7 +479,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<div className="text-secondary mb-0 h6">
<div>
<div className="mb-1">
<label className={`align-middle ${getTextClass('settings/copilot/suggest/temperature')}`} htmlFor="copilot-activate">
<label className={`form-check-label align-middle ${getTextClass('settings/copilot/suggest/temperature')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.temperature" /> - <span>{copilotTemperatureValue / 100}</span>
</label>
<input onChange={onchangeCopilotTemperature} id="copilot-temperature" value={copilotTemperatureValue} min='0' max='100' type="range" className="custom-range" />
Expand Down

0 comments on commit 64b4d78

Please sign in to comment.