0.1.8 • Published 1 year ago

monaco-editor-copilot v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Monaco Editor Copilot

Monaco Editor Copilot is a plugin for the Monaco Editor that integrates OpenAI's GPT-based code completion engine to provide a seamless and intelligent coding experience. This library is designed to work with the Monaco Editor and allows developers to easily configure and customize the plugin to suit their needs.

demo

Features

  • Integration with OpenAI GPT-based code completion
  • Customizable configuration options
  • Optional custom completion function for use with other completion engines
  • Automatically adjusts cursor style based on completion status
  • Easy to add to any Monaco Editor instance

Installation

# Using npm
npm install monaco-editor-copilot

# Using yarn
yarn add monaco-editor-copilot

# Using pnpm
pnpm add monaco-editor-copilot

Usage

import * as monaco from 'monaco-editor';
import MonacoEditorCopilot from 'monaco-editor-copilot';

const editor = monaco.editor.create(document.getElementById('container'), {
  value: '// Start typing your code here...',
  language: 'javascript',
});

const config = {
  openaiKey: 'your_openai_api_key',
};

const dispose = MonacoEditorCopilot(editor, config);

Keyboard Shortcut

Monaco Editor Copilot provides a keyboard shortcut to trigger the code completion feature. The keyboard shortcut is Ctrl + B (or Cmd + B on macOS).

Disabling Copilot

If you need to disable the Copilot functionality, you can call the dispose function:

dispose();

This will remove the Copilot functionality and clean up any associated resources.

More Examples

//  with custom openaiParams
const config = {
  openaiKey: 'your_openai_api_key',
  openaiParams: {
    temperature: 0.8,
    max_tokens: 64,
  },
}

//  with custom assistant message
const config = {
  openaiKey: key,
  assistantMessage: 'use nextjs typescript',
},

//  with custom cursorStyle
const config = {
  openaiKey: 'your_openai_api_key',
  cursorStyleLoading: 'block-outline',
  cursorStyleNormal: 'block',
}

//  with customCompletionFunction
const config = {
  customCompletionFunction: async (code) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve('// example with customCompletionFunction\n');
      }, 1000);
    });
  },
}

Configuration Options

The following options can be passed to the Config object:

OptionTypeDescriptionDefault
openaiKeystringYour OpenAI API key (required for OpenAI-based completions).
openaiUrlstringCustom OpenAI API URL (optional).'https://api.openai.com'
openaiParamsOpenaiParamsParameters for OpenAI completion (optional).
customCompletionFunction(code: string) => PromiseCustom completion function (optional).
assistantMessagestringAssistant message that helps complete the code. (optional).
maxCodeLinesToOpenainumberMaximum number of lines to send to OpenAI (optional).
cursorStyleLoadingstringCursor style during completion loading (optional).'underline'
cursorStyleNormalstringCursor style when not loading completions (optional).'line'

The following options can be passed to the OpenaiParams object:

ParameterTypeDescriptionDefault
modelstringThe name of the OpenAI model to use for code completions.'gpt-3.5-turbo-0301'
temperaturenumberControls the randomness of the generated code.0
max_tokensnumberThe maximum number of tokens to generate in the completion.64
top_pnumberControls the diversity of completions using nucleus sampling.1.0
frequency_penaltynumberPenalizes new tokens based on their frequency in the training data.0.0
presence_penaltynumberPenalizes new tokens based on their presence in the input.0.0
stopArrayA list of strings where the API will stop generating tokens.

License

MIT License

0.1.8

1 year ago

0.1.7

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago