improve settings (add modal)

pull/5370/head
yann300 1 year ago
parent b22e611aac
commit 19668ef3e8
  1. 16
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts
  2. 7
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts
  3. 2
      libs/remix-ui/app/src/lib/remix-app/interface/index.ts
  4. 49
      libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

@ -6,27 +6,31 @@ const profile = {
name: 'copilot-suggestion', name: 'copilot-suggestion',
displayName: 'copilot-suggestion', displayName: 'copilot-suggestion',
description: 'copilot-suggestion', description: 'copilot-suggestion',
methods: ['suggest', 'init', 'uninstall'] methods: ['suggest', 'init', 'uninstall', 'status']
} }
export class CopilotSuggestion extends Plugin { export class CopilotSuggestion extends Plugin {
service: SuggestionService service: SuggestionService
context: string context: string
ready: boolean
constructor() { constructor() {
super(profile) super(profile)
this.service = new SuggestionService() this.service = new SuggestionService()
this.context = '' this.context = ''
this.service.events.on('progress', (data) => { this.service.events.on('progress', (data) => {
this.call('terminal', 'log', {type: 'info', value: `loading Solidity copilot: ${(data.loaded / data.total) * 100}% done.` }) this.emit('loading', data)
}) })
this.service.events.on('done', (data) => { this.service.events.on('done', (data) => {
this.call('terminal', 'log', { type: 'info', value: `Solidity copilot loaded.`})
}) })
this.service.events.on('ready', (data) => { this.service.events.on('ready', (data) => {
this.call('terminal', 'log', { type: 'info', value: `Solidity copilot ready to use.`}) this.ready = true
}) })
} }
status () {
return this.ready
}
async suggest(content: string) { async suggest(content: string) {
if (!await this.call('settings', 'get', 'settings/copilot/suggest/activate')) return { output: [{ generated_text: ''}]} if (!await this.call('settings', 'get', 'settings/copilot/suggest/activate')) return { output: [{ generated_text: ''}]}
@ -59,5 +63,7 @@ export class CopilotSuggestion extends Plugin {
return this.service.init() return this.service.init()
} }
async uninstall() {} async uninstall() {
this.service.terminate()
}
} }

@ -17,6 +17,13 @@ export class SuggestionService {
this.current this.current
} }
terminate(): void {
this.worker.terminate()
this.worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module'
});
}
async init() { async init() {
const onMessageReceived = (e) => { const onMessageReceived = (e) => {
switch (e.data.status) { switch (e.data.status) {

@ -15,7 +15,7 @@ export interface AppModal {
message: string | JSX.Element message: string | JSX.Element
okLabel: string | JSX.Element okLabel: string | JSX.Element
okFn?: (value?:any) => void okFn?: (value?:any) => void
cancelLabel: string | JSX.Element cancelLabel?: string | JSX.Element
cancelFn?: () => void, cancelFn?: () => void,
modalType?: ModalTypes, modalType?: ModalTypes,
defaultValue?: string defaultValue?: string

@ -1,6 +1,7 @@
import {ViewPlugin} from '@remixproject/engine-web' import {ViewPlugin} from '@remixproject/engine-web'
import React, {useState, useReducer, useEffect, useCallback} from 'react' // eslint-disable-line import React, {useState, useRef, useReducer, useEffect, useCallback} from 'react' // eslint-disable-line
import {AppModal, AlertModal, ModalTypes} from '@remix-ui/app'
import {labels, textDark, textSecondary} from './constants' import {labels, textDark, textSecondary} from './constants'
import './remix-ui-settings.css' import './remix-ui-settings.css'
@ -52,6 +53,8 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [ipfsProtocol, setipfsProtocol] = useState('') const [ipfsProtocol, setipfsProtocol] = useState('')
const [ipfsProjectId, setipfsProjectId] = useState('') const [ipfsProjectId, setipfsProjectId] = useState('')
const [ipfsProjectSecret, setipfsProjectSecret] = useState('') const [ipfsProjectSecret, setipfsProjectSecret] = useState('')
const copilotDownload = useRef(null)
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')
@ -128,10 +131,43 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const onchangeCopilotActivate = (event) => { const onchangeCopilotActivate = (event) => {
copilotActivate(props.config, event.target.checked, dispatch) copilotActivate(props.config, event.target.checked, dispatch)
if (event.target.checked) props.plugin.call('copilot-suggestion', 'init') if (!event.target.checked) {
else { copilotActivate(props.config, event.target.checked, dispatch)
props.plugin.call('copilot-suggestion', 'uninstall') props.plugin.call('copilot-suggestion', 'uninstall')
return
}
const message = <div>Please wait while the copilot is downloaded. <span ref={copilotDownload}>0</span>/100 .</div>
copilotActivate(props.config, event.target.checked, dispatch)
const modalActivate: AppModal = {
id: 'loadcopilotActivate',
title: 'Downloading 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)
}
}
} }
props.plugin.call('notification', 'modal', modalActivate)
props.plugin.on('copilot-suggestion', 'loading', (data) => {
if (!copilotDownload.current) return
copilotDownload.current.innerText = (data.loaded / data.total) * 100
})
} }
const onchangeCopilotMaxNewToken = (event) => { const onchangeCopilotMaxNewToken = (event) => {
@ -398,8 +434,11 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
} }
const isCopilotActivated = props.config.get('settings/copilot/suggest/activate') || false const isCopilotActivated = props.config.get('settings/copilot/suggest/activate') || false
const copilotMaxnewToken = props.config.get('settings/copilot/suggest/max_new_tokens') || 5 const copilotMaxnewToken = props.config.get('settings/copilot/suggest/max_new_tokens')
const copilotTemperatureValue = (props.config.get('settings/copilot/suggest/temperature') || 0.5) * 100 if (!copilotMaxnewToken) props.config.set('settings/copilot/suggest/max_new_tokens', 5)
const copilotTemperatureValue = (props.config.get('settings/copilot/suggest/temperature')) * 100
if (!copilotTemperatureValue) props.config.set('settings/copilot/suggest/temperature', 0.5)
if (isCopilotActivated) props.plugin.call('copilot-suggestion', 'init') if (isCopilotActivated) props.plugin.call('copilot-suggestion', 'init')
const copilotSettings = () => ( const copilotSettings = () => (
<div className="border-top"> <div className="border-top">

Loading…
Cancel
Save