monacopilot 0.9.15 → 0.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -278
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,278 +1,179 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# Monacopilot
|
|
4
|
-
|
|
5
|
-
**Monacopilot** integrates AI auto-completion into the Monaco Editor, inspired by GitHub Copilot.
|
|
6
|
-
|
|
7
|
-
## Table of Contents
|
|
8
|
-
|
|
9
|
-
- [
|
|
10
|
-
- [Installation](#installation)
|
|
11
|
-
- [Usage](#usage)
|
|
12
|
-
- [Configuration Options](#configuration-options)
|
|
13
|
-
- [External Context](#external-context)
|
|
14
|
-
- [Changing the Provider and Model](#changing-the-provider-and-model)
|
|
15
|
-
- [Filename](#filename)
|
|
16
|
-
- [Completions for Specific Technologies](#completions-for-specific-technologies)
|
|
17
|
-
- [
|
|
18
|
-
|
|
19
|
-
- [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
app
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const body = await req.json();
|
|
181
|
-
const completion = await copilot.complete(body);
|
|
182
|
-
|
|
183
|
-
return Response.json(completion, { status: 200 });
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
**Pages Router:**
|
|
188
|
-
|
|
189
|
-
```javascript
|
|
190
|
-
// pages/api/copilot.ts
|
|
191
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
192
|
-
import { Copilot } from 'monacopilot';
|
|
193
|
-
|
|
194
|
-
const copilot = new Copilot(process.env.GROQ_API_KEY);
|
|
195
|
-
|
|
196
|
-
export default async function handler(req, res) {
|
|
197
|
-
const completion = await copilot.complete(req.body);
|
|
198
|
-
|
|
199
|
-
res.status(200).json(completion);
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
#### Install Monaco Editor
|
|
204
|
-
|
|
205
|
-
Install a React-compatible Monaco editor package such as `@monaco-editor/react`:
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
npm install @monaco-editor/react
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
#### Register Copilot with the Monaco Editor
|
|
212
|
-
|
|
213
|
-
Next, register Copilot with the Monaco editor.
|
|
214
|
-
|
|
215
|
-
```tsx
|
|
216
|
-
'use client';
|
|
217
|
-
|
|
218
|
-
import { useEffect, useState } from 'react';
|
|
219
|
-
import MonacoEditor from '@monaco-editor/react';
|
|
220
|
-
import { registerCopilot, type Monaco, type StandaloneCodeEditor } from 'monacopilot';
|
|
221
|
-
|
|
222
|
-
export default function CodeEditor() {
|
|
223
|
-
const [editor, setEditor] = useState<StandaloneCodeEditor | null>(null);
|
|
224
|
-
const [monaco, setMonaco] = useState<Monaco | null>(null);
|
|
225
|
-
|
|
226
|
-
useEffect(() => {
|
|
227
|
-
if (!monaco || !editor) return;
|
|
228
|
-
|
|
229
|
-
const copilot = registerCopilot(
|
|
230
|
-
monaco,
|
|
231
|
-
editor,
|
|
232
|
-
{
|
|
233
|
-
endpoint: '/api/copilot',
|
|
234
|
-
language: 'javascript',
|
|
235
|
-
},
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
return () => {
|
|
239
|
-
copilot.deregister();
|
|
240
|
-
};
|
|
241
|
-
}, [monaco, editor]);
|
|
242
|
-
|
|
243
|
-
return (
|
|
244
|
-
<MonacoEditor
|
|
245
|
-
language="javascript"
|
|
246
|
-
onMount={(editor, monaco) => {
|
|
247
|
-
setEditor(editor);
|
|
248
|
-
setMonaco(monaco);
|
|
249
|
-
}}
|
|
250
|
-
/>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
---
|
|
255
|
-
|
|
256
|
-
## Cost Overview
|
|
257
|
-
|
|
258
|
-
The cost of completions is very affordable. See the table below for an estimate of the costs you will need to pay for completions.
|
|
259
|
-
|
|
260
|
-
| Provider | Model | Avg. Cost per 1000 Code Completions |
|
|
261
|
-
|------------|-------------|-------------------------------------|
|
|
262
|
-
| Groq | llama-3-70b | $0.939 |
|
|
263
|
-
| OpenAI | gpt-4o-mini | $0.821 |
|
|
264
|
-
| OpenAI | gpt-4o | $3.46 |
|
|
265
|
-
|
|
266
|
-
> **Note:** Currently, Groq does not implement billing, allowing free usage of their API. During this free period, you will experience minimal rate limiting and some latency in completions. You can opt for Groq's enterprise plan to benefit from increased rate limits and get quick completions without visible latency.
|
|
267
|
-
|
|
268
|
-
## FAQ
|
|
269
|
-
|
|
270
|
-
### Is AI Auto Completion Free?
|
|
271
|
-
|
|
272
|
-
You use your own Groq or OpenAI API key for AI auto-completion. The cost of completions is very affordable, and we implement various methods to minimize these costs as much as possible. Costs vary depending on the model you use; see this [cost overview](#cost-overview) for an idea of the cost.
|
|
273
|
-
|
|
274
|
-
## Contributing
|
|
275
|
-
|
|
276
|
-
For guidelines on contributing, Please read the [contributing guide](https://github.com/arshad-yaseen/monacopilot/blob/main/CONTRIBUTING.md).
|
|
277
|
-
|
|
278
|
-
We welcome contributions from the community to enhance Monacopilot's capabilities and make it even more powerful ❤️
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Monacopilot
|
|
4
|
+
|
|
5
|
+
**Monacopilot** integrates AI auto-completion into the Monaco Editor, inspired by GitHub Copilot.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Examples](#examples)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Configuration Options](#configuration-options)
|
|
13
|
+
- [External Context](#external-context)
|
|
14
|
+
- [Changing the Provider and Model](#changing-the-provider-and-model)
|
|
15
|
+
- [Filename](#filename)
|
|
16
|
+
- [Completions for Specific Technologies](#completions-for-specific-technologies)
|
|
17
|
+
- [Cost Overview](#cost-overview)
|
|
18
|
+
- [FAQ](#faq)
|
|
19
|
+
- [Contributing](#contributing)
|
|
20
|
+
|
|
21
|
+
## Demo
|
|
22
|
+
|
|
23
|
+
https://github.com/user-attachments/assets/4af4e24a-1b05-4bee-84aa-1521ad7098cd
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
Here are some examples of how to use Monacopilot in different project setups:
|
|
28
|
+
|
|
29
|
+
- [Next.js App Router](https://github.com/arshad-yaseen/monacopilot/tree/main/examples/nextjs/app-router)
|
|
30
|
+
- [Next.js Pages Router](https://github.com/arshad-yaseen/monacopilot/tree/main/examples/nextjs/pages-router)
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
To install Monacopilot, run:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install monacopilot
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
#### Setting Up the API Key
|
|
43
|
+
|
|
44
|
+
Start by obtaining an API key from the [Groq console](https://console.groq.com/keys). Once you have your API key, define it as an environment variable in your project:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# .env.local
|
|
48
|
+
GROQ_API_KEY=your-api-key
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### API Handler
|
|
52
|
+
|
|
53
|
+
Set up an API handler to manage auto-completion requests. An example using Express.js:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
const express = require('express');
|
|
57
|
+
const {Copilot} = require('monacopilot');
|
|
58
|
+
|
|
59
|
+
const app = express();
|
|
60
|
+
const port = process.env.PORT || 3000;
|
|
61
|
+
const copilot = new Copilot(process.env.GROQ_API_KEY);
|
|
62
|
+
|
|
63
|
+
app.use(express.json());
|
|
64
|
+
|
|
65
|
+
app.post('/copilot', async (req, res) => {
|
|
66
|
+
const completion = await copilot.complete(req.body);
|
|
67
|
+
res.status(200).json(completion);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
app.listen(port);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Register Copilot with the Monaco Editor
|
|
74
|
+
|
|
75
|
+
Next, register Copilot with the Monaco editor.
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
import * as monaco from 'monaco-editor';
|
|
79
|
+
import {registerCopilot} from 'monacopilot';
|
|
80
|
+
|
|
81
|
+
const editor = monaco.editor.create(document.getElementById('container'), {
|
|
82
|
+
language: 'javascript',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
registerCopilot(monaco, editor, {
|
|
86
|
+
endpoint: 'https://api.example.com/copilot',
|
|
87
|
+
language: 'javascript',
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Configuration Options
|
|
92
|
+
|
|
93
|
+
### External Context
|
|
94
|
+
|
|
95
|
+
Enhance the accuracy and relevance of Copilot's completions by providing additional code context from your workspace.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
registerCopilot(monaco, editor, {
|
|
99
|
+
// ...other options
|
|
100
|
+
externalContext: [
|
|
101
|
+
{
|
|
102
|
+
path: './utils.js',
|
|
103
|
+
content:
|
|
104
|
+
'export const reverse = (str) => str.split("").reverse().join("")',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
By providing external context, Copilot can offer more intelligent suggestions. For example, if you start typing `const isPalindrome = `, Copilot may suggest using the `reverse` function from `utils.js`.
|
|
111
|
+
|
|
112
|
+
### Changing the Provider and Model
|
|
113
|
+
|
|
114
|
+
You can specify a different provider and model for completions by setting the `provider` and `model` parameters in the `Copilot` instance.
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
const copilot = new Copilot(process.env.OPENAI_API_KEY, {
|
|
118
|
+
provider: 'openai',
|
|
119
|
+
model: 'gpt-4o',
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The default provider is `groq` and the default model is `llama-3-70b`.
|
|
124
|
+
|
|
125
|
+
| Provider | Model | Description | Avg. Response Time |
|
|
126
|
+
| -------- | ----------- | ------------------------------------------------- | ------------------ |
|
|
127
|
+
| Groq | llama-3-70b | Fast and efficient, suitable for most tasks | <0.5s |
|
|
128
|
+
| OpenAI | gpt-4o-mini | Mini version of gpt-4o, cheaper | 1.5-3s |
|
|
129
|
+
| OpenAI | gpt-4o | Highly intelligent, ideal for complex completions | 1-2s |
|
|
130
|
+
|
|
131
|
+
### Filename
|
|
132
|
+
|
|
133
|
+
Specify the name of the file being edited to receive more contextually relevant completions.
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
registerCopilot(monaco, editor, {
|
|
137
|
+
// ...other options
|
|
138
|
+
filename: 'utils.js', // e.g., "index.js", "utils/objects.js"
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Now, the completions will be more relevant to utilities.
|
|
143
|
+
|
|
144
|
+
### Completions for Specific Technologies
|
|
145
|
+
|
|
146
|
+
Enable completions tailored to specific technologies by using the `technologies` option.
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
registerCopilot(monaco, editor, {
|
|
150
|
+
// ...other options
|
|
151
|
+
technologies: ['react', 'next.js', 'tailwindcss'],
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This configuration will provide completions relevant to React, Next.js, and Tailwind CSS.
|
|
156
|
+
|
|
157
|
+
## Cost Overview
|
|
158
|
+
|
|
159
|
+
The cost of completions is very affordable. See the table below for an estimate of the costs you will need to pay for completions.
|
|
160
|
+
|
|
161
|
+
| Provider | Model | Avg. Cost per 1000 Code Completions |
|
|
162
|
+
| -------- | ----------- | ----------------------------------- |
|
|
163
|
+
| Groq | llama-3-70b | $0.939 |
|
|
164
|
+
| OpenAI | gpt-4o-mini | $0.821 |
|
|
165
|
+
| OpenAI | gpt-4o | $3.46 |
|
|
166
|
+
|
|
167
|
+
> **Note:** Currently, Groq does not implement billing, allowing free usage of their API. During this free period, you will experience minimal rate limiting and some latency in completions. You can opt for Groq's enterprise plan to benefit from increased rate limits and get quick completions without visible latency.
|
|
168
|
+
|
|
169
|
+
## FAQ
|
|
170
|
+
|
|
171
|
+
### Is AI Auto Completion Free?
|
|
172
|
+
|
|
173
|
+
You use your own Groq or OpenAI API key for AI auto-completion. The cost of completions is very affordable, and we implement various methods to minimize these costs as much as possible. Costs vary depending on the model you use; see this [cost overview](#cost-overview) for an idea of the cost.
|
|
174
|
+
|
|
175
|
+
## Contributing
|
|
176
|
+
|
|
177
|
+
For guidelines on contributing, Please read the [contributing guide](https://github.com/arshad-yaseen/monacopilot/blob/main/CONTRIBUTING.md).
|
|
178
|
+
|
|
179
|
+
We welcome contributions from the community to enhance Monacopilot's capabilities and make it even more powerful ❤️
|