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

Adopt codemirror-copilot #860

Open
curran opened this issue Oct 1, 2024 · 2 comments
Open

Adopt codemirror-copilot #860

curran opened this issue Oct 1, 2024 · 2 comments
Assignees

Comments

@curran
Copy link
Contributor

curran commented Oct 1, 2024

This would be a nice addition! Copilot-like autocompletions from AI.

https://github.com/asadm/codemirror-copilot

@curran
Copy link
Contributor Author

curran commented Oct 2, 2024

OK this is HUGE! I figured out a way to actually generate decent completions for this.

Example prompt:

<|fim_prefix|>
import { select } from 'd3';

export const main = (container) => {
  const svg = select(container)
    .selectAll('svg')
    .data([null])
    .join('svg')
    .attr('width', container.clientWidth)
    .attr('height', container.clientHeight)
    .style('background', '#F0FFF4');

  const data = [
    { x: 155, y: 382, r: 20, fill: '#D4089D' },
    { x: 340, y: 238, r: 52, fill: '#FF0AAE' },
    { x: 531, y: 59, r: 20, fill: '#00FF88' },
  ];

  svg
    .selectAll('circle')
    .data(data)
    .join('circle')
    .attr('cx', (d) => d.x)
    .attr('cy', (d) => d.y)
    .attr('r', (d) => d.r)
    .attr('fill',     <|fim_suffix|>)
    .attr('opacity', 708 / 1000);
};
<|fim_middle|>

that works well with https://deepinfra.com/Qwen/Qwen2.5-Coder-7B

@curran
Copy link
Contributor Author

curran commented Oct 2, 2024

AND this is how we can include multiple files in the context using this model:

<|file_sep|>library.py
class Book:
    def __init__(self, title, author, isbn, copies):
        self.title = title
        self.author = author
        self.isbn = isbn
        self.copies = copies

    def __str__(self):
        return f"Title: {self.title}, Author: {self.author}, ISBN: {self.isbn}, Copies: {self.copies}"

class Library:
    def __init__(self):
        self.books = []

    def add_book(self, title, author, isbn, copies):
        book = Book(title, author, isbn, copies)
        self.books.append(book)

    def find_book(self, isbn):
        for book in self.books:
            if book.isbn == isbn:
                return book
        return None

    def list_books(self):
        return self.books

<|file_sep|>student.py
class Student:
    def __init__(self, name, id):
        self.name = name
        self.id = id
        self.borrowed_books = []

    def borrow_book(self, book, library):
        if book and book.copies > 0:
            self.borrowed_books.append(book)
            book.copies -= 1
            return True
        return False

    def return_book(self, book, library):
        if book in self.borrowed_books:
            self.borrowed_books.remove(book)
            book.copies += 1
            return True
        return False

<|file_sep|>main.py
<|fim_prefix|>from library import Library
from student import Student

def main():
    # Set up the library with some books
    library = Library()
    library.add_book("The Great Gatsby", "F. Scott Fitzgerald", "1234567890", 3)
    library.add_book("To Kill a Mockingbird", "Harper Lee", "1234567891", 2)
    
    # Set up a student
    student =  <|fim_suffix|>
    
    # Student borrows a book
    book_to_borrow = library.find_book("1234567890")
    if student.borrow_book(book_to_borrow, library):
        print(f"{student.name} has borrowed {book_to_borrow.title}")
    else:
        print("Book not available for borrowing.")
    
    # List all books in the library
    print("Books in the library:")
    for book in library.list_books():
        print(book)

if __name__ == "__main__":
    main()
<|fim_middle|>

If you paste this one into https://deepinfra.com/Qwen/Qwen2.5-Coder-7B , it correctly generates:

Student("John Doe", "12345")

@curran curran self-assigned this Oct 2, 2024
@curran curran moved this to In Progress in VZCode Kanban Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

1 participant