From c558c978d492f8c69653cbf941f38dc703756831 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 29 Nov 2023 18:24:27 +0100 Subject: [PATCH] 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 dbe5d06065..0a3c17888d 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) {