fixing copilot

aiui_fix
lianahus 11 months ago
parent c9f33bcc09
commit 9ab946a675
  1. 7
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts
  2. 16
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts
  3. 1
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/worker.js
  4. 6
      apps/remix-ide/src/app/tabs/settings-tab.tsx
  5. 8355
      diff.diff
  6. 86
      libs/remix-ui/settings/src/lib/remix-ui-settings.tsx
  7. 2
      libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

@ -20,8 +20,11 @@ export class CopilotSuggestion extends Plugin {
ready: boolean ready: boolean
constructor() { constructor() {
super(profile) super(profile)
this.service = new SuggestionService()
this.context = '' this.context = ''
}
onActivation(): void {
this.service = new SuggestionService()
this.service.events.on('progress', (data) => { this.service.events.on('progress', (data) => {
this.emit('loading', data) this.emit('loading', data)
}) })
@ -29,7 +32,7 @@ export class CopilotSuggestion extends Plugin {
}) })
this.service.events.on('ready', (data) => { this.service.events.on('ready', (data) => {
this.ready = true this.ready = true
}) })
} }
useRemoteService(service: string) { useRemoteService(service: string) {

@ -1,11 +1,13 @@
import EventEmitter from 'events' import EventEmitter from 'events'
export type SuggestOptions = { max_new_tokens: number, export type SuggestOptions = {
temperature: number, max_new_tokens: number,
do_sample:boolean temperature: number,
top_k: number, do_sample:boolean
top_p:number, top_k: number,
stream_result:boolean} top_p:number,
stream_result:boolean
}
export class SuggestionService { export class SuggestionService {
worker: Worker worker: Worker
@ -17,12 +19,12 @@ export class SuggestionService {
this.worker = new Worker(new URL('./worker.js', import.meta.url), { this.worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module' type: 'module'
}); });
this.init()
this.events = new EventEmitter() this.events = new EventEmitter()
this.responses = {} this.responses = {}
this.current this.current
} }
//todo ask Yann if we should keep the model
terminate(): void { terminate(): void {
this.worker.terminate() this.worker.terminate()
this.worker = new Worker(new URL('./worker.js', import.meta.url), { this.worker = new Worker(new URL('./worker.js', import.meta.url), {

@ -22,6 +22,7 @@ class CodeCompletionPipeline {
// Listen for messages from the main thread // Listen for messages from the main thread
self.addEventListener('message', async (event) => { self.addEventListener('message', async (event) => {
console.log("worker message ", event.data)
const { const {
id, model, text, max_new_tokens, cmd, id, model, text, max_new_tokens, cmd,

@ -60,6 +60,12 @@ module.exports = class SettingsTab extends ViewPlugin {
this.renderComponent() this.renderComponent()
} }
onActivation(): void {
this.on('copilot-suggestion', 'loading', (data) => {
this.call('terminal', 'log', { type: 'typewritererror', value: `.` })
console.log("oninit")
})
}
render() { render() {
return ( return (
<div id="settingsTab"> <div id="settingsTab">

File diff suppressed because it is too large Load Diff

@ -4,6 +4,12 @@ import React, {useState, useRef, useReducer, useEffect, useCallback} from 'react
import {AppModal, AlertModal, ModalTypes} from '@remix-ui/app' import {AppModal, AlertModal, ModalTypes} from '@remix-ui/app'
import {labels, textDark, textSecondary} from './constants' import {labels, textDark, textSecondary} from './constants'
enum CONSENT {
GIVEN = 0,
NOT_GIVEN,
NOT_ASKED
}
import './remix-ui-settings.css' import './remix-ui-settings.css'
import { import {
generateContractMetadat, generateContractMetadat,
@ -56,6 +62,7 @@ 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')
@ -72,7 +79,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
} }
useEffect(() => initValue(), [resetState, props.config]) useEffect(() => initValue(), [resetState, props.config])
useEffect(() => initValue(), []) useEffect(() => initValue(), [])
useEffect(() => { useEffect(() => {
const token = props.config.get('settings/' + labels['gist'].key) const token = props.config.get('settings/' + labels['gist'].key)
if (token) { if (token) {
@ -123,9 +130,14 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
}, [props.useMatomoAnalytics]) }, [props.useMatomoAnalytics])
useEffect(() => { useEffect(() => {
console.log("useEffect on useCopilot")
if (props.useCopilot !== null) copilotActivate(props.config, props.useCopilot, dispatch) if (props.useCopilot !== null) copilotActivate(props.config, props.useCopilot, dispatch)
if (props.useCopilot) {
const a = async () => await onchangeCopilotActivate()
}
console.log("useEffect on useCopilot finish")
}, [props.useCopilot]) }, [props.useCopilot])
const onchangeGenerateContractMetadata = (event) => { const onchangeGenerateContractMetadata = (event) => {
generateContractMetadat(props.config, event.target.checked, dispatch) generateContractMetadat(props.config, event.target.checked, dispatch)
} }
@ -134,9 +146,10 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
textWrapEventAction(props.config, props.editor, event.target.checked, dispatch) textWrapEventAction(props.config, props.editor, event.target.checked, dispatch)
} }
const onchangeCopilotActivate = async (event) => { const onchangeCopilotActivate = async () => {
if (!event.target.checked) { console.log("onchangeCopilotActivate ", props.useCopilot)
copilotActivate(props.config, event.target.checked, dispatch) if (!props.useCopilot) {
copilotActivate(props.config, props.useCopilot, dispatch)
props.plugin.call('copilot-suggestion', 'uninstall') props.plugin.call('copilot-suggestion', 'uninstall')
return return
} }
@ -148,31 +161,46 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const dot = loaded.match(/(.*)\./g) const dot = loaded.match(/(.*)\./g)
copilotDownload.current.innerText = dot ? dot[0].replace('.', '') : loaded copilotDownload.current.innerText = dot ? dot[0].replace('.', '') : loaded
}) })
const startCopilot = async () => {
await props.plugin.call('copilot-suggestion', 'init')
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)
}
}
const modalActivate: AppModal = { const modalActivate: AppModal = {
id: 'loadcopilotActivate', id: 'loadcopilotActivate',
title: 'Download Solidity copilot', title: 'Download Solidity copilot',
modalType: ModalTypes.default, modalType: ModalTypes.default,
okLabel: 'Close', okLabel: 'OK',
//cancelLabel: 'Cancel',
message, message,
okFn: async() => { okFn: async() => {
props.plugin.off('copilot-suggestion', 'loading') consentGivenForAI = CONSENT.GIVEN
if (await props.plugin.call('copilot-suggestion', 'status')) { startCopilot()
copilotActivate(props.config, true, dispatch)
} else {
props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch)
}
}, },
hideFn: async () => { hideFn: async () => {
consentGivenForAI = CONSENT.NOT_GIVEN
props.plugin.off('copilot-suggestion', 'loading') 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)
} else { // } else {
props.plugin.call('copilot-suggestion', 'uninstall') // props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch) // copilotActivate(props.config, false, dispatch)
} // }
} }
} }
if (consentGivenForAI === CONSENT.NOT_ASKED) {
props.plugin.call('notification', 'modal', modalActivate)
} else if (consentGivenForAI === CONSENT.GIVEN) {
startCopilot()
} else {
// NOT_GIVEN
}
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)
@ -180,10 +208,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
props.plugin.call('copilot-suggestion', 'uninstall') props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch) copilotActivate(props.config, false, dispatch)
} }
}
props.plugin.call('copilot-suggestion', 'init')
props.plugin.call('notification', 'modal', modalActivate)
}
const onchangeCopilotMaxNewToken = (event) => { const onchangeCopilotMaxNewToken = (event) => {
copilotMaxNewToken(props.config, parseInt(event.target.value), dispatch) copilotMaxNewToken(props.config, parseInt(event.target.value), dispatch)
@ -460,7 +485,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
copilotTemperatureValue = 0.5 copilotTemperatureValue = 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">
<div className="card-body pt-3 pb-2"> <div className="card-body pt-3 pb-2">
@ -468,19 +493,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<FormattedMessage id="settings.copilot" /> <FormattedMessage id="settings.copilot" />
</h6> </h6>
<div className="pt-2 mb-0">
<div className="text-secondary mb-0 h6">
<div>
<div className="custom-control custom-checkbox mb-1">
<input onChange={onchangeCopilotActivate} id="copilot-activate" type="checkbox" className="custom-control-input" checked={isCopilotActivated} />
<label className={`form-check-label custom-control-label align-middle ${getTextClass('settings/copilot/suggest/activate')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.activate" />
</label>
</div>
</div>
</div>
</div>
<div className="pt-2 mb-0"> <div className="pt-2 mb-0">
<div className="text-secondary mb-0 h6"> <div className="text-secondary mb-0 h6">
<div> <div>

@ -267,7 +267,7 @@ export const TabsUI = (props: TabsUIProps) => {
className="btn ai-switch text-ai pl-2 pr-0 py-0 d-flex" className="btn ai-switch text-ai pl-2 pr-0 py-0 d-flex"
disabled={!(tabsState.currentExt === 'sol' )} disabled={!(tabsState.currentExt === 'sol' )}
onClick={async () => { onClick={async () => {
await props.plugin.call('settings', 'updateCopilotChoice', ai_switch) await props.plugin.call('settings', 'updateCopilotChoice', !ai_switch)
setAI_switch(!ai_switch) setAI_switch(!ai_switch)
}} }}
> >

Loading…
Cancel
Save