pull/4584/head
Stéphane Tetsing 8 months ago
parent 56bfd93b8f
commit 38d088e6a0
  1. 1
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts
  2. 3
      apps/remix-ide/src/app/tabs/settings-tab.tsx
  3. 51
      libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts
  4. 33
      libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

@ -31,6 +31,7 @@ export class CopilotSuggestion extends Plugin {
this.service.events.on('done', (data) => { this.service.events.on('done', (data) => {
}) })
this.service.events.on('ready', (data) => { this.service.events.on('ready', (data) => {
this.emit('ready', data)
this.ready = true this.ready = true
}) })
} }

@ -62,8 +62,7 @@ module.exports = class SettingsTab extends ViewPlugin {
onActivation(): void { onActivation(): void {
this.on('copilot-suggestion', 'loading', (data) => { this.on('copilot-suggestion', 'loading', (data) => {
this.call('terminal', 'log', { type: 'typewritererror', value: `.` }) this.call('terminal', 'log', {type: 'typewriterlog', value: `loading Solidity copilot: ${(data.loaded / data.total) * 100}%.` })
console.log("oninit")
}) })
} }
render() { render() {

@ -15,7 +15,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
constructor(props: any, monaco: any) { constructor(props: any, monaco: any) {
this.props = props this.props = props
this.monaco = monaco this.monaco = monaco
this.running = false
} }
async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> { async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> {
@ -49,24 +48,24 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
const split = word.split('\n') const split = word.split('\n')
if (split.length < 2) return if (split.length < 2) return
const ask = split[split.length - 2].trimStart() const ask = split[split.length - 2].trimStart()
if (split[split.length - 1].trim() === '' && ask.startsWith('///') && (!this.running)) { if (split[split.length - 1].trim() === '' && ask.startsWith('///')) {
// use the code generation model, only take max 1000 word as context // use the code generation model, only take max 1000 word as context
this.running = true this.props.plugin.call('terminal', 'log', {type: 'typewritersuccess', value: 'Solcoder - generating code for following comment: ' + ask})
const data = await this.props.plugin.call('solcoder', 'code_completion', word) const data = await this.props.plugin.call('solcoder', 'code_completion', word)
console.log("solcoder completion data", data) console.log("solcoder completion data", data)
const parsedData = data[0].trimStart() //JSON.parse(data).trimStart() const parsedData = data[0].trimStart() //JSON.parse(data).trimStart()
const item: monacoTypes.languages.InlineCompletion = { const item: monacoTypes.languages.InlineCompletion = {
insertText: parsedData insertText: parsedData
}; };
this.running =false
return { return {
items: [item], items: [item],
enableForwardStability: true enableForwardStability: true
} }
} }
} catch (e) { } catch (e) {
console.error(e) return
} }
if (word.split('\n').at(-1).trimStart().startsWith('//') || if (word.split('\n').at(-1).trimStart().startsWith('//') ||
word.split('\n').at(-1).trimStart().startsWith('/*') || word.split('\n').at(-1).trimStart().startsWith('/*') ||
@ -84,37 +83,33 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
let result let result
try { try {
if (!this.running){ result = await this.props.plugin.call('copilot-suggestion', 'suggest', word)
result = await this.props.plugin.call('copilot-suggestion', 'suggest', word) this.running=false
this.running = true const generatedText = (result as any).output[0].generated_text as string
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
};
return {
items: [item],
enableForwardStability: true
} }
} catch (err) { } catch (err) {
this.running=false this.running=false
return return
} }
const generatedText = (result as any).output[0].generated_text as string
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
};
this.running=false
// abort if there is a signal // abort if there is a signal
if (token.isCancellationRequested) { if (token.isCancellationRequested) {
return return
} }
return {
items: [item],
enableForwardStability: true
}
} }
handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void { handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void {

@ -9,6 +9,7 @@ enum CONSENT {
NOT_GIVEN, NOT_GIVEN,
NOT_ASKED NOT_ASKED
} }
let consentGivenForAI = CONSENT.NOT_ASKED
import './remix-ui-settings.css' import './remix-ui-settings.css'
import { import {
@ -62,7 +63,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [ipfsProjectSecret, setipfsProjectSecret] = useState('') const [ipfsProjectSecret, setipfsProjectSecret] = useState('')
const copilotDownload = useRef(null) const copilotDownload = useRef(null)
let consentGivenForAI = CONSENT.NOT_ASKED
const intl = useIntl() const intl = useIntl()
const initValue = () => { const initValue = () => {
const metadataConfig = props.config.get('settings/generate-contract-metadata') const metadataConfig = props.config.get('settings/generate-contract-metadata')
@ -151,21 +151,18 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
if (!props.useCopilot) { if (!props.useCopilot) {
copilotActivate(props.config, props.useCopilot, dispatch) copilotActivate(props.config, props.useCopilot, dispatch)
props.plugin.call('copilot-suggestion', 'uninstall') props.plugin.call('copilot-suggestion', 'uninstall')
props.plugin.call('terminal', 'log', {type: 'typewriterlog', value: `Solidity copilot deactivated` })
return return
} }
const message = <div>Please wait while the copilot is downloaded. <span ref={copilotDownload}>0</span>/100 .</div>
props.plugin.on('copilot-suggestion', 'loading', (data) => { props.plugin.on('copilot-suggestion', 'loading', (data) => {
if (!copilotDownload.current) return props.plugin.call('terminal', 'log', {type: 'typewriterlog', value: `loading Solidity copilot: ${(data.loaded / data.total) * 100}% done.` })
const loaded = ((data.loaded / data.total) * 100).toString()
const dot = loaded.match(/(.*)\./g)
copilotDownload.current.innerText = dot ? dot[0].replace('.', '') : loaded
}) })
const startCopilot = async () => { const startCopilot = async () => {
await props.plugin.call('copilot-suggestion', 'init') await props.plugin.call('copilot-suggestion', 'init')
props.plugin.off('copilot-suggestion', 'loading')
if (await props.plugin.call('copilot-suggestion', 'status')) { if (await props.plugin.call('copilot-suggestion', 'status')) {
copilotActivate(props.config, true, dispatch) copilotActivate(props.config, true, dispatch)
<<<<<<< HEAD
} else { } else {
props.plugin.call('copilot-suggestion', 'uninstall') props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch) copilotActivate(props.config, false, dispatch)
@ -204,13 +201,29 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
} }
if (props.plugin.call('copilot-suggestion', 'status')) { if (props.plugin.call('copilot-suggestion', 'status')) {
=======
}
}
props.plugin.on('copilot-suggestion', 'ready', (data) => {
copilotActivate(props.config, true, dispatch)
props.plugin.call('terminal', 'log', {type: 'typewriterlog', value: `Solidity Copilot activated` })
})
if (await props.plugin.call('copilot-suggestion', 'status')) {
>>>>>>> f63484701 (removed user consens)
copilotActivate(props.config, true, dispatch) copilotActivate(props.config, true, dispatch)
} else { }else {
props.plugin.call('copilot-suggestion', 'uninstall') startCopilot()
copilotActivate(props.config, false, dispatch)
} }
} }
useEffect(() => {
if (props.useCopilot !== null) copilotActivate(props.config, props.useCopilot, dispatch)
onchangeCopilotActivate()
}, [props.useCopilot])
const onchangeCopilotMaxNewToken = (event) => { const onchangeCopilotMaxNewToken = (event) => {
copilotMaxNewToken(props.config, parseInt(event.target.value), dispatch) copilotMaxNewToken(props.config, parseInt(event.target.value), dispatch)
} }

Loading…
Cancel
Save