fixing copilot

pull/5370/head
lianahus 9 months ago
parent a0a151b1c8
commit 3bd1ca2a1e
  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
constructor() {
super(profile)
this.service = new SuggestionService()
this.context = ''
}
onActivation(): void {
this.service = new SuggestionService()
this.service.events.on('progress', (data) => {
this.emit('loading', data)
})
@ -29,7 +32,7 @@ export class CopilotSuggestion extends Plugin {
})
this.service.events.on('ready', (data) => {
this.ready = true
})
})
}
useRemoteService(service: string) {

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

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

@ -60,6 +60,12 @@ module.exports = class SettingsTab extends ViewPlugin {
this.renderComponent()
}
onActivation(): void {
this.on('copilot-suggestion', 'loading', (data) => {
this.call('terminal', 'log', { type: 'typewritererror', value: `.` })
console.log("oninit")
})
}
render() {
return (
<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 {labels, textDark, textSecondary} from './constants'
enum CONSENT {
GIVEN = 0,
NOT_GIVEN,
NOT_ASKED
}
import './remix-ui-settings.css'
import {
generateContractMetadat,
@ -56,6 +62,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [ipfsProjectSecret, setipfsProjectSecret] = useState('')
const copilotDownload = useRef(null)
let consentGivenForAI = CONSENT.NOT_ASKED
const intl = useIntl()
const initValue = () => {
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(), [])
useEffect(() => {
const token = props.config.get('settings/' + labels['gist'].key)
if (token) {
@ -123,9 +130,14 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
}, [props.useMatomoAnalytics])
useEffect(() => {
console.log("useEffect on useCopilot")
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])
const onchangeGenerateContractMetadata = (event) => {
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)
}
const onchangeCopilotActivate = async (event) => {
if (!event.target.checked) {
copilotActivate(props.config, event.target.checked, dispatch)
const onchangeCopilotActivate = async () => {
console.log("onchangeCopilotActivate ", props.useCopilot)
if (!props.useCopilot) {
copilotActivate(props.config, props.useCopilot, dispatch)
props.plugin.call('copilot-suggestion', 'uninstall')
return
}
@ -148,31 +161,46 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const dot = loaded.match(/(.*)\./g)
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 = {
id: 'loadcopilotActivate',
title: 'Download Solidity copilot',
modalType: ModalTypes.default,
okLabel: 'Close',
okLabel: 'OK',
//cancelLabel: 'Cancel',
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)
}
consentGivenForAI = CONSENT.GIVEN
startCopilot()
},
hideFn: async () => {
consentGivenForAI = CONSENT.NOT_GIVEN
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)
// }
}
}
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')) {
copilotActivate(props.config, true, dispatch)
@ -180,10 +208,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
props.plugin.call('copilot-suggestion', 'uninstall')
copilotActivate(props.config, false, dispatch)
}
props.plugin.call('copilot-suggestion', 'init')
props.plugin.call('notification', 'modal', modalActivate)
}
}
const onchangeCopilotMaxNewToken = (event) => {
copilotMaxNewToken(props.config, parseInt(event.target.value), dispatch)
@ -460,7 +485,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
copilotTemperatureValue = 0.5
}
if (isCopilotActivated) props.plugin.call('copilot-suggestion', 'init')
//if (isCopilotActivated) props.plugin.call('copilot-suggestion', 'init')
const copilotSettings = () => (
<div className="border-top">
<div className="card-body pt-3 pb-2">
@ -468,19 +493,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<FormattedMessage id="settings.copilot" />
</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="text-secondary mb-0 h6">
<div>

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

Loading…
Cancel
Save