Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom endpoint for AI suggestion #4319

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import {Plugin} from '@remixproject/engine'
import {SuggestionService, SuggestOptions} from './suggestion-service'
import axios, {AxiosResponse} from 'axios'
const _paq = (window._paq = window._paq || []) //eslint-disable-line

const profile = {
name: 'copilot-suggestion',
displayName: 'copilot-suggestion',
description: 'Get Solidity suggestions in editor',
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate'],
methods: ['suggest', 'init', 'uninstall', 'status', 'isActivate', 'useRemoteService', 'discardRemoteService'],
version: '0.1.0-alpha',
maintainedBy: "Remix"
}

export class CopilotSuggestion extends Plugin {
service: SuggestionService
remoteService: string
context: string
ready: boolean
constructor() {
Expand All @@ -29,6 +31,14 @@ export class CopilotSuggestion extends Plugin {
})
}

useRemoteService(service: string) {
this.remoteService = service
}

discardRemoteService() {
this.remoteService = null
}

status () {
return this.ready
}
Expand All @@ -53,7 +63,14 @@ export class CopilotSuggestion extends Plugin {
temperature: temperature || 0,
max_new_tokens: max_new_tokens || 0
}
return this.service.suggest(this.context ? this.context + '\n\n' + content : content, options)

if (this.remoteService) {
const {data} = await axios.post(this.remoteService, {context: content, max_new_words: options.max_new_tokens, temperature: options.temperature})
const parsedData = JSON.parse(data).trimStart()
return {output: [{generated_text: parsedData}]}
} else {
return this.service.suggest(this.context ? this.context + '\n\n' + content : content, options)
}
}

async loadModeContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ 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, '')
let clean = generatedText
if (generatedText.indexOf('@custom:dev-run-script./') !== -1) {
clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ')
}
clean = clean.replace(word, '')
const item: monacoTypes.languages.InlineCompletion = {
insertText: clean
};
Expand Down
Loading