Skip to content

Commit 86db390

Browse files
authored
Merge pull request #4253 from ethereum/improve_model
Improve model
2 parents 2675918 + 4411dc2 commit 86db390

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const profile = {
66
name: 'copilot-suggestion',
77
displayName: 'copilot-suggestion',
88
description: 'copilot-suggestion',
9-
methods: ['suggest', 'init', 'uninstall', 'status']
9+
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate']
1010
}
1111

1212
export class CopilotSuggestion extends Plugin {
@@ -31,6 +31,15 @@ export class CopilotSuggestion extends Plugin {
3131
return this.ready
3232
}
3333

34+
async isActivate () {
35+
try {
36+
return await this.call('settings', 'get', 'settings/copilot/suggest/activate')
37+
} catch (e) {
38+
console.error(e)
39+
return false
40+
}
41+
}
42+
3443
async suggest(content: string) {
3544
if (!await this.call('settings', 'get', 'settings/copilot/suggest/activate')) return { output: [{ generated_text: ''}]}
3645

libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/* eslint-disable no-control-regex */
12
import { EditorUIProps, monacoTypes } from '@remix-ui/editor';
3+
import axios, {AxiosResponse} from 'axios'
24
const controller = new AbortController();
35
const { signal } = controller;
46
const result: string = ''
@@ -8,7 +10,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
810
monaco: any
911
constructor(props: any, monaco: any) {
1012
this.props = props
11-
this.monaco = monaco
13+
this.monaco = monaco
1214
}
1315

1416
async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> {
@@ -29,6 +31,34 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
2931
return;
3032
}
3133

34+
try {
35+
const isActivate = await this.props.plugin.call('copilot-suggestion', 'isActivate')
36+
if (!isActivate) return
37+
} catch (err) {
38+
return;
39+
}
40+
41+
try {
42+
const split = word.split('\n')
43+
if (!split.length) return
44+
const ask = split[split.length - 2].trimStart()
45+
if (split[split.length - 1].trim() === '' && ask.startsWith('///')) {
46+
// use the code generation model
47+
const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: ask.replace('///', '')})
48+
const parsedData = JSON.parse(data).trimStart()
49+
console.log('parsedData', parsedData)
50+
const item: monacoTypes.languages.InlineCompletion = {
51+
insertText: parsedData
52+
};
53+
return {
54+
items: [item],
55+
enableForwardStability: true
56+
}
57+
}
58+
} catch (e) {
59+
console.error(e)
60+
}
61+
3262
// abort if there is a signal
3363
if (token.isCancellationRequested) {
3464
console.log('aborted')
@@ -38,18 +68,17 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
3868
let result
3969
try {
4070
result = await this.props.plugin.call('copilot-suggestion', 'suggest', word)
41-
} catch (err) {
71+
} catch (err) {
4272
return
4373
}
44-
74+
4575
const generatedText = (result as any).output[0].generated_text as string
46-
// the generated text remove a space from the context. that why we need to remove all the spaces
47-
const clean = generatedText.replace(/ /g, '').replace(word.replace(/ /g, ''), '')
48-
console.log('suggest result', clean)
76+
// the generated text remove a space from the context...
77+
const clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '')
4978
const item: monacoTypes.languages.InlineCompletion = {
5079
insertText: clean
5180
};
52-
81+
5382
// abort if there is a signal
5483
if (token.isCancellationRequested) {
5584
console.log('aborted')
@@ -62,17 +91,17 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
6291

6392
}
6493
handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void {
65-
94+
6695
}
6796
handlePartialAccept?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, acceptedCharacters: number): void {
6897

6998
}
7099
freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>): void {
71-
100+
72101
}
73102
groupId?: string;
74103
yieldsToGroupIds?: string[];
75104
toString?(): string {
76105
throw new Error('Method not implemented.');
77106
}
78-
}
107+
}

0 commit comments

Comments
 (0)