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.
Files changed (2) hide show
  1. package/README.md +179 -278
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,278 +1,179 @@
1
- ![Hero Image](https://i.postimg.cc/PrsQ1KLb/Frame-1.png)
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
- - [Demo](#demo)
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
- - [Guides](#guides)
18
- - [Next.js Integration](#nextjs-integration)
19
- - [Cost Overview](#cost-overview)
20
- - [FAQ](#faq)
21
- - [Contributing](#contributing)
22
-
23
- ## Demo
24
-
25
- https://github.com/user-attachments/assets/4af4e24a-1b05-4bee-84aa-1521ad7098cd
26
-
27
- ## Installation
28
-
29
- To install Monacopilot, run:
30
-
31
- ```bash
32
- npm install monacopilot
33
- ```
34
-
35
- ## Usage
36
-
37
- #### Setting Up the API Key
38
-
39
- 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:
40
-
41
- ```bash
42
- # .env.local
43
- GROQ_API_KEY=your-api-key
44
- ```
45
-
46
- #### API Handler
47
-
48
- Set up an API handler to manage auto-completion requests. An example using Express.js:
49
-
50
- ```javascript
51
- const express = require('express');
52
- const bodyParser = require('body-parser');
53
- const { Copilot } = require('monacopilot');
54
-
55
- const app = express();
56
-
57
- const copilot = new Copilot(process.env.GROQ_API_KEY);
58
-
59
- app.use(bodyParser.json());
60
-
61
- app.post('/copilot', async (req, res) => {
62
- const completion = await copilot.complete(req.body);
63
- res.status(200).json(completion);
64
- });
65
-
66
- app.listen(3000)
67
- ```
68
-
69
- #### Register Copilot with the Monaco Editor
70
-
71
- Next, register Copilot with the Monaco editor.
72
-
73
- ```javascript
74
- import * as monaco from 'monaco-editor';
75
- import { registerCopilot } from 'monacopilot';
76
-
77
- const editor = monaco.editor.create(document.getElementById('container'), {
78
- language: 'javascript'
79
- });
80
-
81
- registerCopilot(monaco, editor, {
82
- endpoint: 'https://api.example.com/copilot',
83
- language: 'javascript',
84
- });
85
- ```
86
-
87
- ## Configuration Options
88
-
89
- ### External Context
90
-
91
- Enhance the accuracy and relevance of Copilot's completions by providing additional code context from your workspace.
92
-
93
- ```javascript
94
- registerCopilot(monaco, editor, {
95
- // ...other options
96
- externalContext: [
97
- {
98
- path: './utils.js',
99
- content: 'export const reverse = (str) => str.split("").reverse().join("")'
100
- }
101
- ]
102
- });
103
- ```
104
-
105
- 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`.
106
-
107
- ### Changing the Provider and Model
108
-
109
- You can specify a different provider and model for completions by setting the `provider` and `model` parameters in the `Copilot` instance.
110
-
111
- ```javascript
112
- const copilot = new Copilot(process.env.OPENAI_API_KEY, {
113
- provider: 'openai',
114
- model: 'gpt-4o'
115
- });
116
- ```
117
-
118
- The default provider is `groq` and the default model is `llama-3-70b`.
119
-
120
- | Provider | Model | Description | Avg. Response Time |
121
- |----------|-------------|----------------------------------------------------|--------------------|
122
- | Groq | llama-3-70b | Fast and efficient, suitable for most tasks | <0.5s |
123
- | OpenAI | gpt-4o-mini | Mini version of gpt-4o, cheaper | 1.5-3s |
124
- | OpenAI | gpt-4o | Highly intelligent, ideal for complex completions | 1-2s |
125
-
126
- ### Filename
127
-
128
- Specify the name of the file being edited to receive more contextually relevant completions.
129
-
130
- ```javascript
131
- registerCopilot(monaco, editor, {
132
- // ...other options
133
- filename: 'utils.js' // e.g., "index.js", "utils/objects.js"
134
- });
135
- ```
136
-
137
- Now, the completions will be more relevant to utilities.
138
-
139
- ### Completions for Specific Technologies
140
-
141
- Enable completions tailored to specific technologies by using the `technologies` option.
142
-
143
- ```javascript
144
- registerCopilot(monaco, editor, {
145
- // ...other options
146
- technologies: ['react', 'next.js', 'tailwindcss']
147
- });
148
- ```
149
-
150
- This configuration will provide completions relevant to React, Next.js, and Tailwind CSS.
151
-
152
- ## Guides
153
-
154
- ### Next.js Integration
155
-
156
- Follow the steps below to integrate AI auto-completion into your Next.js project.
157
-
158
- #### Setting Up the API Key
159
-
160
- 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:
161
-
162
- ```bash
163
- # .env.local
164
- GROQ_API_KEY=your-api-key
165
- ```
166
-
167
- #### API Handler
168
-
169
- Set up an API handler to manage auto-completion requests.
170
-
171
- **App Router:**
172
-
173
- ```javascript
174
- // app/api/copilot/route.ts
175
- import { Copilot } from 'monacopilot';
176
-
177
- const copilot = new Copilot(process.env.GROQ_API_KEY);
178
-
179
- export async function POST(req) {
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
+ ![Hero Image](https://i.postimg.cc/PrsQ1KLb/Frame-1.png)
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 ❤️
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monacopilot",
3
- "version": "0.9.15",
3
+ "version": "0.9.16",
4
4
  "description": "AI auto-completion for Monaco Editor",
5
5
  "main": "./build/index.js",
6
6
  "module": "./build/index.mjs",