From ffde11c8dc5c49064b7626a5b400e352bc967eb5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 19 Nov 2023 09:45:43 +0100 Subject: [PATCH 01/17] fix stripping input/output --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 3e42da252b9..9cb25c4fa99 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -43,8 +43,9 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli } const generatedText = (result as any).output[0].generated_text as string - // the generated text remove a space from the context. that why we need to remove all the spaces - const clean = generatedText.replace(/ /g, '').replace(word.replace(/ /g, ''), '') + // the generated text remove a space from the context... + let clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') + clean = clean.replace(/_s_/g, ' ') console.log('suggest result', clean) const item: monacoTypes.languages.InlineCompletion = { insertText: clean From b9327b4cae009de1839402b733e147a77ea494dc Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 19 Nov 2023 10:25:22 +0100 Subject: [PATCH 02/17] use llm --- .../src/lib/providers/inlineCompletionProvider.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 9cb25c4fa99..916a48be691 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -1,4 +1,5 @@ import { EditorUIProps, monacoTypes } from '@remix-ui/editor'; +import axios, {AxiosResponse} from 'axios' const controller = new AbortController(); const { signal } = controller; const result: string = '' @@ -29,12 +30,26 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli return; } + const generativeComment = word.match(/\/\/(.*)\n /) + if (generativeComment[1]) { + // use the code generation model + const {data} = await axios.post('https://llm.remix-project.org', {comment: generativeComment[1]}) + const item: monacoTypes.languages.InlineCompletion = { + insertText: data + }; + return { + items: [item], + enableForwardStability: true + } + } + // abort if there is a signal if (token.isCancellationRequested) { console.log('aborted') return } + console.log(word) let result try { result = await this.props.plugin.call('copilot-suggestion', 'suggest', word) From 7b40a99f791e7944ac097650c5f2fc06d0a3b3a2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 19 Nov 2023 12:34:02 +0100 Subject: [PATCH 03/17] removed uneeded --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 916a48be691..fac024eb507 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -60,7 +60,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generatedText = (result as any).output[0].generated_text as string // the generated text remove a space from the context... let clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') - clean = clean.replace(/_s_/g, ' ') console.log('suggest result', clean) const item: monacoTypes.languages.InlineCompletion = { insertText: clean @@ -91,4 +90,4 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli toString?(): string { throw new Error('Method not implemented.'); } -} \ No newline at end of file +} From 7dfad0b6e836c48ec8273c1c8adce5d569d4938b Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sun, 19 Nov 2023 18:56:48 +0100 Subject: [PATCH 04/17] Update inlineCompletionProvider.ts change url of gpt endpoint --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index fac024eb507..eab2b722502 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -33,7 +33,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generativeComment = word.match(/\/\/(.*)\n /) if (generativeComment[1]) { // use the code generation model - const {data} = await axios.post('https://llm.remix-project.org', {comment: generativeComment[1]}) + const {data} = await axios.post('https://gpt-chat.remixproject.org', {comment: generativeComment[1]}) const item: monacoTypes.languages.InlineCompletion = { insertText: data }; From 7533ad575ec10a58daca160968a369e1087e5e25 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sun, 19 Nov 2023 19:04:54 +0100 Subject: [PATCH 05/17] update gpt endpoint for monaco --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index eab2b722502..a36ce601918 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -33,7 +33,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generativeComment = word.match(/\/\/(.*)\n /) if (generativeComment[1]) { // use the code generation model - const {data} = await axios.post('https://gpt-chat.remixproject.org', {comment: generativeComment[1]}) + const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[1]}) const item: monacoTypes.languages.InlineCompletion = { insertText: data }; From a8c0caccc763cf21c4b849a65e6a35e2c8745f81 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 19 Nov 2023 09:45:43 +0100 Subject: [PATCH 06/17] fix stripping input/output --- .../src/lib/providers/inlineCompletionProvider.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index a36ce601918..64037d31b31 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -9,7 +9,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli monaco: any constructor(props: any, monaco: any) { this.props = props - this.monaco = monaco + this.monaco = monaco } async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise> { @@ -53,18 +53,19 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli let result try { result = await this.props.plugin.call('copilot-suggestion', 'suggest', word) - } catch (err) { + } catch (err) { return } - + const generatedText = (result as any).output[0].generated_text as string // the generated text remove a space from the context... let clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') + clean = clean.replace(/_s_/g, ' ') console.log('suggest result', clean) const item: monacoTypes.languages.InlineCompletion = { insertText: clean }; - + // abort if there is a signal if (token.isCancellationRequested) { console.log('aborted') @@ -77,13 +78,13 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli } handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void { - + } handlePartialAccept?(completions: monacoTypes.languages.InlineCompletions, item: monacoTypes.languages.InlineCompletion, acceptedCharacters: number): void { } freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions): void { - + } groupId?: string; yieldsToGroupIds?: string[]; From 72feb52095b0247a1536dc6269bc88e03c7117b0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 19 Nov 2023 12:34:02 +0100 Subject: [PATCH 07/17] removed uneeded --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 64037d31b31..c57f8810e9b 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -60,7 +60,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generatedText = (result as any).output[0].generated_text as string // the generated text remove a space from the context... let clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') - clean = clean.replace(/_s_/g, ' ') console.log('suggest result', clean) const item: monacoTypes.languages.InlineCompletion = { insertText: clean From 7b422c2a53d4fbd8156e8fc602e49d1b7a162d23 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 20 Nov 2023 08:18:30 +0100 Subject: [PATCH 08/17] fix using regex --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index c57f8810e9b..b3dd48a7e9b 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -29,11 +29,12 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli console.log('not a trigger char') return; } - - const generativeComment = word.match(/\/\/(.*)\n /) - if (generativeComment[1]) { + let regex = new RegExp('\/\/(.*)\n ', 'g') + + const generativeComment = [...p.matchAll(regex)] + if (generativeComment && generativeComment.length) { // use the code generation model - const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[1]}) + const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1]}) const item: monacoTypes.languages.InlineCompletion = { insertText: data }; From cb9e4a90155c3642bffb9a33f027d7daad64156f Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 21 Nov 2023 10:16:37 +0100 Subject: [PATCH 09/17] fix wrong var name --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index b3dd48a7e9b..525248b82f7 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -31,7 +31,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli } let regex = new RegExp('\/\/(.*)\n ', 'g') - const generativeComment = [...p.matchAll(regex)] + const generativeComment = [...word.matchAll(regex)] if (generativeComment && generativeComment.length) { // use the code generation model const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1]}) From 4944c93dafe13784a3dc60a4d8148bd6e509b732 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 23 Nov 2023 13:57:03 +0100 Subject: [PATCH 10/17] fix eslint issues --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 525248b82f7..2ebd5e44789 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-control-regex */ import { EditorUIProps, monacoTypes } from '@remix-ui/editor'; import axios, {AxiosResponse} from 'axios' const controller = new AbortController(); @@ -29,8 +30,9 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli console.log('not a trigger char') return; } - let regex = new RegExp('\/\/(.*)\n ', 'g') - + // eslint-disable-next-line no-useless-escape + const regex = new RegExp('\/\/(.*)\n ', 'g') + const generativeComment = [...word.matchAll(regex)] if (generativeComment && generativeComment.length) { // use the code generation model @@ -60,7 +62,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generatedText = (result as any).output[0].generated_text as string // the generated text remove a space from the context... - let clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') + const clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') console.log('suggest result', clean) const item: monacoTypes.languages.InlineCompletion = { insertText: clean From 405ba952f57bcbef5cd2bf3471960fa8f5e31038 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 27 Nov 2023 18:29:15 +0100 Subject: [PATCH 11/17] patch inlineCompletionProvider --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 2ebd5e44789..6ffaba5aa59 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -36,7 +36,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generativeComment = [...word.matchAll(regex)] if (generativeComment && generativeComment.length) { // use the code generation model - const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1]}) + const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1][1]}) const item: monacoTypes.languages.InlineCompletion = { insertText: data }; From c978488416f85d1a4cb40eb9bde888bdae7d128a Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 28 Nov 2023 10:08:58 +0100 Subject: [PATCH 12/17] do not call the api if the feature isn't activated --- .../copilot/suggestion-service/copilot-suggestion.ts | 11 ++++++++++- .../src/lib/providers/inlineCompletionProvider.ts | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts index c8cfc0a9be4..3b289387324 100644 --- a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts +++ b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts @@ -6,7 +6,7 @@ const profile = { name: 'copilot-suggestion', displayName: 'copilot-suggestion', description: 'copilot-suggestion', - methods: ['suggest', 'init', 'uninstall', 'status'] + methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate'] } export class CopilotSuggestion extends Plugin { @@ -31,6 +31,15 @@ export class CopilotSuggestion extends Plugin { return this.ready } + async isActivate () { + try { + return await this.call('settings', 'get', 'settings/copilot/suggest/activate') + } catch (e) { + console.error(e) + return false + } + } + async suggest(content: string) { if (!await this.call('settings', 'get', 'settings/copilot/suggest/activate')) return { output: [{ generated_text: ''}]} diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 6ffaba5aa59..814a56bd1de 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -30,6 +30,14 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli console.log('not a trigger char') return; } + + try { + const isActivate = await this.props.plugin.call('copilot-suggestion', 'isActivate') + if (!isActivate) return + } catch (err) { + return; + } + // eslint-disable-next-line no-useless-escape const regex = new RegExp('\/\/(.*)\n ', 'g') From bdd386b068faacb7f3b837287a10a34f3d6cfe4e Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 29 Nov 2023 10:17:13 +0100 Subject: [PATCH 13/17] remove logs --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 814a56bd1de..58b926dc2fa 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -60,7 +60,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli return } - console.log(word) let result try { result = await this.props.plugin.call('copilot-suggestion', 'suggest', word) @@ -71,7 +70,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli const generatedText = (result as any).output[0].generated_text as string // the generated text remove a space from the context... const clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ').replace(word, '') - console.log('suggest result', clean) const item: monacoTypes.languages.InlineCompletion = { insertText: clean }; From 392f003c49ba0457e1f7e96f377aa1a25b76f101 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Wed, 29 Nov 2023 16:11:33 +0100 Subject: [PATCH 14/17] fix gpt response in editor --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 58b926dc2fa..a947f79af25 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -45,8 +45,9 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli if (generativeComment && generativeComment.length) { // use the code generation model const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1][1]}) + const parsedData = JSON.parse(data) const item: monacoTypes.languages.InlineCompletion = { - insertText: data + insertText: parsedData }; return { items: [item], From 8779bcbe5bc37b19ab94cf23465e5250ac5fa792 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Wed, 29 Nov 2023 17:03:29 +0100 Subject: [PATCH 15/17] updates --- .../editor/src/lib/providers/inlineCompletionProvider.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index a947f79af25..ac2594876aa 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -39,13 +39,14 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli } // eslint-disable-next-line no-useless-escape - const regex = new RegExp('\/\/(.*)\n ', 'g') + const regex = new RegExp('\/\/\/(.*)\n ', 'g') const generativeComment = [...word.matchAll(regex)] if (generativeComment && generativeComment.length) { // use the code generation model const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1][1]}) - const parsedData = JSON.parse(data) + const parsedData = JSON.parse(data).trimStart() + console.log('parsedData', parsedData) const item: monacoTypes.languages.InlineCompletion = { insertText: parsedData }; From b6966cd5c0a67cf65a6720f432911a4d7a1f2ff7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 29 Nov 2023 18:08:07 +0100 Subject: [PATCH 16/17] update model input --- .../src/lib/providers/inlineCompletionProvider.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index ac2594876aa..dbe5d06065b 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -19,7 +19,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli return; } // get text before the position of the completion - const word = model.getValueInRange({ + let word = model.getValueInRange({ startLineNumber: 1, startColumn: 1, endLineNumber: position.lineNumber, @@ -38,13 +38,12 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli return; } - // eslint-disable-next-line no-useless-escape - const regex = new RegExp('\/\/\/(.*)\n ', 'g') - - const generativeComment = [...word.matchAll(regex)] - if (generativeComment && generativeComment.length) { + word = word.split('\n') + if (!word.length) return + const ask = word[word.length - 2].trimStart() + if (word[word.length - 1] === '' && ask.startsWith('///')) { // use the code generation model - const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: generativeComment[generativeComment.length - 1][1]}) + const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: ask.replace('///', ''}) const parsedData = JSON.parse(data).trimStart() console.log('parsedData', parsedData) const item: monacoTypes.languages.InlineCompletion = { @@ -55,7 +54,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli enableForwardStability: true } } - + // abort if there is a signal if (token.isCancellationRequested) { console.log('aborted') From 4411dc2fcd451d88d04e52090b5958abd2a2a392 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 29 Nov 2023 18:24:27 +0100 Subject: [PATCH 17/17] fix parsing model input --- .../lib/providers/inlineCompletionProvider.ts | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index dbe5d06065b..0a3c17888db 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -19,7 +19,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli return; } // get text before the position of the completion - let word = model.getValueInRange({ + const word = model.getValueInRange({ startLineNumber: 1, startColumn: 1, endLineNumber: position.lineNumber, @@ -38,22 +38,26 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli return; } - word = word.split('\n') - if (!word.length) return - const ask = word[word.length - 2].trimStart() - if (word[word.length - 1] === '' && ask.startsWith('///')) { - // use the code generation model - const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: ask.replace('///', ''}) - const parsedData = JSON.parse(data).trimStart() - console.log('parsedData', parsedData) - const item: monacoTypes.languages.InlineCompletion = { - insertText: parsedData - }; - return { - items: [item], - enableForwardStability: true + try { + const split = word.split('\n') + if (!split.length) return + const ask = split[split.length - 2].trimStart() + if (split[split.length - 1].trim() === '' && ask.startsWith('///')) { + // use the code generation model + const {data} = await axios.post('https://gpt-chat.remixproject.org/infer', {comment: ask.replace('///', '')}) + const parsedData = JSON.parse(data).trimStart() + console.log('parsedData', parsedData) + const item: monacoTypes.languages.InlineCompletion = { + insertText: parsedData + }; + return { + items: [item], + enableForwardStability: true + } } - } + } catch (e) { + console.error(e) + } // abort if there is a signal if (token.isCancellationRequested) {