enforced insertion on completion

pull/5241/head
STetsing 1 month ago
parent 5b69872e8e
commit b6eeacfb70
  1. 4
      apps/remix-ide/src/app/plugins/remixAIPlugin.tsx
  2. 8
      libs/remix-ai-core/src/inferencers/remote/remoteInference.ts
  3. 7
      libs/remix-ai-core/src/types/remix-project.code-workspace
  4. 31
      libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts

@ -112,11 +112,11 @@ export class RemixAIPlugin extends ViewPlugin {
} }
} }
async code_completion(prompt: string): Promise<any> { async code_completion(prompt: string, promptAfter: string): Promise<any> {
if (this.isOnDesktop) { if (this.isOnDesktop) {
return await this.call(this.remixDesktopPluginName, 'code_completion', prompt) return await this.call(this.remixDesktopPluginName, 'code_completion', prompt)
} else { } else {
return await this.remoteInferencer.code_completion(prompt) return await this.remoteInferencer.code_completion(prompt, promptAfter)
} }
} }

@ -110,19 +110,17 @@ export class RemoteInferencer implements ICompletions {
} }
} }
async code_completion(prompt, options:IParams=CompletionParams): Promise<any> { async code_completion(prompt, promptAfter, options:IParams=CompletionParams): Promise<any> {
const payload = { prompt, "endpoint":"code_completion", ...options } const payload = { prompt, 'context':promptAfter, "endpoint":"code_completion", ...options }
return this._makeRequest(payload, AIRequestType.COMPLETION) return this._makeRequest(payload, AIRequestType.COMPLETION)
} }
async code_insertion(msg_pfx, msg_sfx, options:IParams=InsertionParams): Promise<any> { async code_insertion(msg_pfx, msg_sfx, options:IParams=InsertionParams): Promise<any> {
// const payload = { "data":[msg_pfx, "code_insertion", msg_sfx, 1024, 0.5, 0.92, 50]}
const payload = { "endpoint":"code_insertion", msg_pfx, msg_sfx, ...options, prompt: '' } const payload = { "endpoint":"code_insertion", msg_pfx, msg_sfx, ...options, prompt: '' }
return this._makeRequest(payload, AIRequestType.COMPLETION) return this._makeRequest(payload, AIRequestType.COMPLETION)
} }
async code_generation(prompt, options:IParams=GenerationParams): Promise<any> { async code_generation(prompt, options:IParams=GenerationParams): Promise<any> {
// const payload = { "data":[prompt, "code_completion", "", false,1000,0.9,0.92,50]}
const payload = { prompt, "endpoint":"code_completion", ...options } const payload = { prompt, "endpoint":"code_completion", ...options }
if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.COMPLETION) if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.COMPLETION)
else return this._makeRequest(payload, AIRequestType.COMPLETION) else return this._makeRequest(payload, AIRequestType.COMPLETION)
@ -130,14 +128,12 @@ export class RemoteInferencer implements ICompletions {
async solidity_answer(prompt, options:IParams=GenerationParams): Promise<any> { async solidity_answer(prompt, options:IParams=GenerationParams): Promise<any> {
const main_prompt = buildSolgptPromt(prompt, this.model_op) const main_prompt = buildSolgptPromt(prompt, this.model_op)
// const payload = { "data":[main_prompt, "solidity_answer", false,2000,0.9,0.8,50]}
const payload = { 'prompt': main_prompt, "endpoint":"solidity_answer", ...options } const payload = { 'prompt': main_prompt, "endpoint":"solidity_answer", ...options }
if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL) if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL)
else return this._makeRequest(payload, AIRequestType.GENERAL) else return this._makeRequest(payload, AIRequestType.GENERAL)
} }
async code_explaining(prompt, context:string="", options:IParams=GenerationParams): Promise<any> { async code_explaining(prompt, context:string="", options:IParams=GenerationParams): Promise<any> {
// const payload = { "data":[prompt, "code_explaining", false,2000,0.9,0.8,50, context]}
const payload = { prompt, "endpoint":"code_explaining", context, ...options } const payload = { prompt, "endpoint":"code_explaining", context, ...options }
if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL) if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL)
else return this._makeRequest(payload, AIRequestType.GENERAL) else return this._makeRequest(payload, AIRequestType.GENERAL)

@ -0,0 +1,7 @@
{
"folders": [
{
"path": "../../../.."
}
]
}

@ -1,6 +1,8 @@
/* eslint-disable no-control-regex */ /* eslint-disable no-control-regex */
import { EditorUIProps, monacoTypes } from '@remix-ui/editor'; import { EditorUIProps, monacoTypes } from '@remix-ui/editor';
import { JsonStreamParser } from '@remix/remix-ai-core'; import { JsonStreamParser } from '@remix/remix-ai-core';
import * as monaco from 'monaco-editor';
const _paq = (window._paq = window._paq || []) const _paq = (window._paq = window._paq || [])
export class RemixInLineCompletionProvider implements monacoTypes.languages.InlineCompletionsProvider { export class RemixInLineCompletionProvider implements monacoTypes.languages.InlineCompletionsProvider {
@ -26,9 +28,8 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
} }
async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> { async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> {
if (context.selectedSuggestionInfo) { const isActivate = await await this.props.plugin.call('settings', 'get', 'settings/copilot/suggest/activate')
return { items: []}; if (!isActivate) return
}
const currentTime = Date.now(); const currentTime = Date.now();
const timeSinceLastRequest = currentTime - this.lastRequestTime; const timeSinceLastRequest = currentTime - this.lastRequestTime;
@ -65,13 +66,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
return; return;
} }
try {
const isActivate = await await this.props.plugin.call('settings', 'get', 'settings/copilot/suggest/activate')
if (!isActivate) return
} catch (err) {
return;
}
try { try {
const split = word.split('\n') const split = word.split('\n')
if (split.length < 2) return if (split.length < 2) return
@ -109,11 +103,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
return { items: []}; // do not do completion on single and multiline comment return { items: []}; // do not do completion on single and multiline comment
} }
// abort if there is a signal
if (token.isCancellationRequested) {
return
}
if (word.replace(/ +$/, '').endsWith('\n')){ if (word.replace(/ +$/, '').endsWith('\n')){
// Code insertion // Code insertion
try { try {
@ -122,7 +111,8 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
this.task = 'code_insertion' this.task = 'code_insertion'
const item: monacoTypes.languages.InlineCompletion = { const item: monacoTypes.languages.InlineCompletion = {
insertText: generatedText insertText: generatedText,
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column)
}; };
this.currentCompletion.text = generatedText this.currentCompletion.text = generatedText
this.currentCompletion.item = item this.currentCompletion.item = item
@ -141,25 +131,26 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
try { try {
// Code completion // Code completion
this.task = 'code_completion' this.task = 'code_completion'
const output = await this.props.plugin.call('remixAI', 'code_completion', word) const output = await this.props.plugin.call('remixAI', 'code_completion', word, word_after)
const generatedText = output const generatedText = output
let clean = generatedText let clean = generatedText
if (generatedText.indexOf('@custom:dev-run-script./') !== -1) { if (generatedText.indexOf('@custom:dev-run-script./') !== -1) {
clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ') clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ')
} }
clean = clean.replace(word, '').trimStart() clean = clean.replace(word, '')
clean = this.process_completion(clean) clean = this.process_completion(clean)
const item: monacoTypes.languages.InlineCompletion = { const item: monacoTypes.languages.InlineCompletion = {
insertText: clean, insertText: clean,
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column)
}; };
this.currentCompletion.text = clean this.currentCompletion.text = clean
this.currentCompletion.item = item this.currentCompletion.item = item
return { return {
items: [item], items: [item],
enableForwardStability: true enableForwardStability: false
} }
} catch (err) { } catch (err) {
return return
@ -174,7 +165,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
return "" return ""
} }
// remove comment inline // remove comment inline
clean = clean.split('//')[0].trimEnd() clean = clean.split('//')[0]
return clean return clean
} }

Loading…
Cancel
Save