TechxGenus commited on
Commit
3159be9
1 Parent(s): 0b0f2ab

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +417 -0
README.md ADDED
@@ -0,0 +1,417 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - code
4
+ base_model:
5
+ - TechxGenus/CursorCore-Yi-9B
6
+ library_name: transformers
7
+ pipeline_tag: text-generation
8
+ license: apache-2.0
9
+ ---
10
+
11
+ # CursorCore: Assist Programming through Aligning Anything
12
+
13
+ <p align="center">
14
+ <a href="http://arxiv.org/abs/2410.07002">[📄arXiv]</a> |
15
+ <a href="https://hf.co/papers/2410.07002">[🤗HF Paper]</a> |
16
+ <a href="https://huggingface.co/collections/TechxGenus/cursorcore-series-6706618c38598468866b60e2">[🤖Models]</a> |
17
+ <a href="https://github.com/TechxGenus/CursorCore">[🛠️Code]</a> |
18
+ <a href="https://github.com/TechxGenus/CursorWeb">[<img src="https://github.com/TechxGenus/CursorCore/blob/main/pictures/cursorcore.png" width="12.5px">Web]</a> |
19
+ <a href="https://discord.gg/Z5Tev8fV">[<img src="https://github.com/TechxGenus/CursorCore/blob/main/pictures/discord.png" width="15x">Discord]</a>
20
+ </p>
21
+
22
+ <hr>
23
+
24
+ - [CursorCore: Assist Programming through Aligning Anything](#cursorcore-assist-programming-through-aligning-anything)
25
+ - [Introduction](#introduction)
26
+ - [Models](#models)
27
+ - [Usage](#usage)
28
+ - [1) Normal chat](#1-normal-chat)
29
+ - [2) Assistant-Conversation](#2-assistant-conversation)
30
+ - [3) Web Demo](#3-web-demo)
31
+ - [Future Work](#future-work)
32
+ - [Citation](#citation)
33
+ - [Contribution](#contribution)
34
+
35
+ <hr>
36
+
37
+ ## Introduction
38
+
39
+ CursorCore is a series of open-source models designed for AI-assisted programming. It aims to support features such as automated editing and inline chat, replicating the core abilities of closed-source AI-assisted programming tools like Cursor. This is achieved by aligning data generated through Programming-Instruct. Please read [our paper](http://arxiv.org/abs/2410.07002) to learn more.
40
+
41
+ <p align="center">
42
+ <img width="100%" alt="conversation" src="https://github.com/TechxGenus/CursorCore/blob/main/pictures/conversation.png">
43
+ </p>
44
+
45
+ ![CursorWeb](https://github.com/TechxGenus/CursorCore/blob/main/pictures/CursorWeb.gif)
46
+
47
+ ## Models
48
+
49
+ Our models have been open-sourced on Hugging Face. You can access our models here: [CursorCore-Series](https://huggingface.co/collections/TechxGenus/cursorcore-series-6706618c38598468866b60e2"). We also provide pre-quantized weights for GPTQ and AWQ here: [CursorCore-Quantization](https://huggingface.co/collections/TechxGenus/cursorcore-quantization-67066431f29f252494ee8cf3)
50
+
51
+ ## Usage
52
+
53
+ Here are some examples of how to use our model:
54
+
55
+ ### 1) Normal chat
56
+
57
+ Script:
58
+
59
+ ````python
60
+ import torch
61
+ from transformers import AutoTokenizer, AutoModelForCausalLM
62
+
63
+ tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CursorCore-Yi-9B")
64
+ model = AutoModelForCausalLM.from_pretrained(
65
+ "TechxGenus/CursorCore-Yi-9B",
66
+ torch_dtype=torch.bfloat16,
67
+ device_map="auto"
68
+ )
69
+
70
+ messages = [
71
+ {"role": "user", "content": "Hi!"},
72
+ ]
73
+ prompt = tokenizer.apply_chat_template(
74
+ messages,
75
+ tokenize=False,
76
+ add_generation_prompt=True
77
+ )
78
+
79
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
80
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512)
81
+ print(tokenizer.decode(outputs[0]))
82
+ ````
83
+
84
+ Output:
85
+
86
+ ````txt
87
+ <|im_start|>system
88
+ You are a helpful programming assistant.<|im_end|>
89
+ <|im_start|>user
90
+ Hi!<|im_end|>
91
+ <|im_start|>assistant
92
+ Hello! I'm an AI language model and I can help you with any programming questions you might have. What specific problem or task are you trying to solve?<|im_end|>
93
+ ````
94
+
95
+ ### 2) Assistant-Conversation
96
+
97
+ In our work, we introduce a new framework of AI-assisted programming task. It is designed for aligning anything during programming process, used for the implementation of features like Tab and Inline Chat.
98
+
99
+ Script 1:
100
+
101
+ ````python
102
+ import torch
103
+ from transformers import AutoTokenizer, AutoModelForCausalLM
104
+ from eval.utils import prepare_input_for_wf
105
+
106
+ tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CursorCore-Yi-9B")
107
+ model = AutoModelForCausalLM.from_pretrained(
108
+ "TechxGenus/CursorCore-Yi-9B",
109
+ torch_dtype=torch.bfloat16,
110
+ device_map="auto"
111
+ )
112
+ sample = {
113
+ "history": [
114
+ {
115
+ "type": "code",
116
+ "lang": "python",
117
+ "code": """def quick_sort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)"""
118
+ }
119
+ ],
120
+ "current": {
121
+ "type": "code",
122
+ "lang": "python",
123
+ "code": """def quick_sort(array):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)"""
124
+ },
125
+ "user": ""
126
+ }
127
+
128
+ prompt = tokenizer.apply_chat_template(
129
+ prepare_input_for_wf(sample),
130
+ tokenize=False,
131
+ chat_template="assistant-conversation",
132
+ add_generation_prompt=True
133
+ )
134
+
135
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
136
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512, do_sample=False)
137
+ print(tokenizer.decode(outputs[0]))
138
+ ````
139
+
140
+ Output 1:
141
+
142
+ ````txt
143
+ <|im_start|>system
144
+ You are a helpful programming assistant.<|im_end|>
145
+ <|im_start|>history
146
+ ```python
147
+ def quick_sort(arr):
148
+ if len(arr) <= 1:
149
+ return arr
150
+ pivot = arr[len(arr) // 2]
151
+ left = [x for x in arr if x < pivot]
152
+ middle = [x for x in arr if x == pivot]
153
+ right = [x for x in arr if x > pivot]
154
+ return quick_sort(left) + middle + quick_sort(right)
155
+ ```<|im_end|>
156
+ <|im_start|>current
157
+ ```python
158
+ def quick_sort(array):
159
+ if len(arr) <= 1:
160
+ return arr
161
+ pivot = arr[len(arr) // 2]
162
+ left = [x for x in arr if x < pivot]
163
+ middle = [x for x in arr if x == pivot]
164
+ right = [x for x in arr if x > pivot]
165
+ return quick_sort(left) + middle + quick_sort(right)
166
+ ```<|im_end|>
167
+ <|im_start|>assistant
168
+ <|next_start|>```python
169
+ def quick_sort(array):
170
+ if len(array) <= 1:
171
+ return array
172
+ pivot = array[len(array) // 2]
173
+ left = [x for x in array if x < pivot]
174
+ middle = [x for x in array if x == pivot]
175
+ right = [x for x in array if x > pivot]
176
+ return quick_sort(left) + middle + quick_sort(right)
177
+ ```<|next_end|>
178
+ The user has provided a revised code change that corrects the parameter name from `arr` to `array` in the `quick_sort` function. This change ensures consistency in the function definition and avoids potential confusion or errors.
179
+
180
+ To implement this, we will:
181
+ 1. Update the parameter name in the function definition from `arr` to `array`.
182
+ 2. Ensure that all references to `arr` within the function are updated to `array`.
183
+
184
+ This will make the function definition and internal references consistent, improving code readability and maintainability.<|im_end|>
185
+ ````
186
+
187
+ Script 2:
188
+
189
+ ````python
190
+ import torch
191
+ from transformers import AutoTokenizer, AutoModelForCausalLM
192
+ from eval.utils import prepare_input_for_wf
193
+
194
+ tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CursorCore-Yi-9B")
195
+ model = AutoModelForCausalLM.from_pretrained(
196
+ "TechxGenus/CursorCore-Yi-9B",
197
+ torch_dtype=torch.bfloat16,
198
+ device_map="auto"
199
+ )
200
+ sample = {
201
+ "history": [],
202
+ "current": {
203
+ "type": "code",
204
+ "lang": "python",
205
+ "code": """def quick_sort(array):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)"""
206
+ },
207
+ "user": "Add Docstring."
208
+ }
209
+
210
+ prompt = tokenizer.apply_chat_template(
211
+ prepare_input_for_wf(sample),
212
+ tokenize=False,
213
+ chat_template="assistant-conversation",
214
+ add_generation_prompt=True
215
+ )
216
+
217
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
218
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512, do_sample=False)
219
+ print(tokenizer.decode(outputs[0]))
220
+ ````
221
+
222
+ Output 2:
223
+
224
+ ````txt
225
+ <|im_start|>system
226
+ You are a helpful programming assistant.<|im_end|>
227
+ <|im_start|>current
228
+ ```python
229
+ def quick_sort(array):
230
+ if len(arr) <= 1:
231
+ return arr
232
+ pivot = arr[len(arr) // 2]
233
+ left = [x for x in arr if x < pivot]
234
+ middle = [x for x in arr if x == pivot]
235
+ right = [x for x in arr if x > pivot]
236
+ return quick_sort(left) + middle + quick_sort(right)
237
+ ```<|im_end|>
238
+ <|im_start|>user
239
+ Add Docstring.<|im_end|>
240
+ <|im_start|>assistant
241
+ <|next_start|>```python
242
+ def quick_sort(array):
243
+ """
244
+ This is an implementation of the quick sort algorithm.
245
+ """
246
+ if len(arr) <= 1:
247
+ return arr
248
+ pivot = arr[len(arr) // 2]
249
+ left = [x for x in arr if x < pivot]
250
+ middle = [x for x in arr if x == pivot]
251
+ right = [x for x in arr if x > pivot]
252
+ return quick_sort(left) + middle + quick_sort(right)
253
+ ```<|next_end|><|im_end|>
254
+ ````
255
+
256
+ For models in Locate-and-Change (LC) and Search-and-Replace (SR) formats, the output examples are as follows:
257
+
258
+ Script for LC:
259
+
260
+ ````python
261
+ import torch
262
+ from transformers import AutoTokenizer, AutoModelForCausalLM
263
+ from eval.utils import prepare_input_for_lc
264
+
265
+ tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CursorCore-Yi-1.5B-LC")
266
+ model = AutoModelForCausalLM.from_pretrained(
267
+ "TechxGenus/CursorCore-Yi-1.5B-LC",
268
+ torch_dtype=torch.bfloat16,
269
+ device_map="auto"
270
+ )
271
+ sample = {
272
+ "history": [],
273
+ "current": {
274
+ "type": "code",
275
+ "lang": "python",
276
+ "code": """def quick_sort(array):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)"""
277
+ },
278
+ "user": "Add Docstring."
279
+ }
280
+
281
+ prompt = tokenizer.apply_chat_template(
282
+ prepare_input_for_lc(sample),
283
+ tokenize=False,
284
+ chat_template="assistant-conversation",
285
+ add_generation_prompt=True
286
+ )
287
+
288
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
289
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512, do_sample=False)
290
+ print(tokenizer.decode(outputs[0]))
291
+ ````
292
+
293
+ Output for LC:
294
+
295
+ ````txt
296
+ <|im_start|>system
297
+ You are a helpful programming assistant.<|im_end|>
298
+ <|im_start|>current
299
+ ```python
300
+ 1 def quick_sort(array):
301
+ 2 if len(arr) <= 1:
302
+ 3 return arr
303
+ 4 pivot = arr[len(arr) // 2]
304
+ 5 left = [x for x in arr if x < pivot]
305
+ 6 middle = [x for x in arr if x == pivot]
306
+ 7 right = [x for x in arr if x > pivot]
307
+ 8 return quick_sort(left) + middle + quick_sort(right)
308
+ ```<|im_end|>
309
+ <|im_start|>user
310
+ Add Docstring.<|im_end|>
311
+ <|im_start|>assistant
312
+ <|next_start|>1,1
313
+ ```
314
+ '''This function will sort an array using quick sort algorithm'''
315
+ ```<|next_end|>
316
+ To enhance the readability and maintainability of the code, we should add a docstring to the `quick_sort` function. A docstring provides a clear description of what the function does, which is particularly useful for other developers who might use or modify this code in the future.
317
+
318
+ The docstring will be added immediately after the function definition, explaining that the function uses the quick sort algorithm to sort an array. This will make the code more self-explanatory and easier to understand.
319
+
320
+ Here's the plan:
321
+ 1. Add a docstring at the beginning of the `quick_sort` function.
322
+ 2. Ensure the docstring is clear and concise, describing the purpose of the function.
323
+
324
+ This modification will improve the code's documentation without altering its functionality.<|im_end|>
325
+ ````
326
+
327
+ Script for SR:
328
+
329
+ ````python
330
+ import torch
331
+ from transformers import AutoTokenizer, AutoModelForCausalLM
332
+ from eval.utils import prepare_input_for_sr
333
+
334
+ tokenizer = AutoTokenizer.from_pretrained("TechxGenus/CursorCore-Yi-1.5B-SR")
335
+ model = AutoModelForCausalLM.from_pretrained(
336
+ "TechxGenus/CursorCore-Yi-1.5B-SR",
337
+ torch_dtype=torch.bfloat16,
338
+ device_map="auto"
339
+ )
340
+ sample = {
341
+ "history": [],
342
+ "current": {
343
+ "type": "code",
344
+ "lang": "python",
345
+ "code": """def quick_sort(array):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)"""
346
+ },
347
+ "user": "Add Docstring."
348
+ }
349
+
350
+ prompt = tokenizer.apply_chat_template(
351
+ prepare_input_for_sr(sample),
352
+ tokenize=False,
353
+ chat_template="assistant-conversation",
354
+ add_generation_prompt=True
355
+ )
356
+
357
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
358
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512, do_sample=False)
359
+ print(tokenizer.decode(outputs[0]))
360
+ ````
361
+
362
+ Output for SR:
363
+
364
+ ````txt
365
+ <|im_start|>system
366
+ You are a helpful programming assistant.<|im_end|>
367
+ <|im_start|>current
368
+ ```python
369
+ def quick_sort(array):
370
+ if len(arr) <= 1:
371
+ return arr
372
+ pivot = arr[len(arr) // 2]
373
+ left = [x for x in arr if x < pivot]
374
+ middle = [x for x in arr if x == pivot]
375
+ right = [x for x in arr if x > pivot]
376
+ return quick_sort(left) + middle + quick_sort(right)
377
+ ```<|im_end|>
378
+ <|im_start|>user
379
+ Add Docstring.<|im_end|>
380
+ <|im_start|>assistant
381
+ <|next_start|>```python
382
+ def quick_sort(array):
383
+ <|search_and_replace|>
384
+ def quick_sort(array):
385
+ """
386
+ This function implements quick sort algorithm
387
+ """
388
+ ```<|next_end|><|im_end|>
389
+ ````
390
+
391
+ ### 3) Web Demo
392
+
393
+ We create a web demo for CursorCore. Please visit [CursorWeb](https://github.com/TechxGenus/CursorWeb) for more details.
394
+
395
+ ## Future Work
396
+
397
+ CursorCore is still in a very early stage, and lots of work is needed to achieve a better user experience. For example:
398
+
399
+ - Repository-level editing support
400
+ - Better and faster editing formats
401
+ - Better user interface and presentation
402
+ - ...
403
+
404
+ ## Citation
405
+
406
+ ```bibtex
407
+ @article{jiang2024cursorcore,
408
+ title = {CursorCore: Assist Programming through Aligning Anything},
409
+ author = {Hao Jiang and Qi Liu and Rui Li and Shengyu Ye and Shijin Wang},
410
+ year = {2024},
411
+ journal = {arXiv preprint arXiv: 2410.07002}
412
+ }
413
+ ```
414
+
415
+ ## Contribution
416
+
417
+ Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request.