A friend suggested we try do this after seeing stack-overflow-import (<a href="https://github.com/drathier/stack-overflow-import" rel="nofollow">https://github.com/drathier/stack-overflow-import</a>), which queries stackoverflow for some matching result and loads it. For small functions, it's surprisingly effective. You still need Copilot access to use this, unfortunately.<p>Some other examples:<p><pre><code> >>> from copilot import rock_paper_scissors
>>> rock_paper_scissors('Rock', 'Scissors')
'Player 1 wins'
>>> from copilot import get_current_git_commit
>>> get_current_git_commit()
b'29c7e9b138a9247c598b613ca378d103de878e2a\n'
>>> from copilot import answer_to_everything
>>> answer_to_everything(1)
42
</code></pre>
Practically, it works through two separate copilot calls. The first one asks copilot to predict the arguments a function would take, then the second one asks it to predict the body of the function. The returned code is then parsed, both to ensure that it is actual valid Python (it almost always is, although it sometimes spits out Python 2 or cuts off due to length limits), and to remove any extra statements that are not part of the function (sometimes it likes to include an `if __name__ == "__main__"` for example).<p>The function is then wrapped in an error handler that will attempt to include a module if the snippet references an undefined variable. Copilot tends to use the correct libraries, but forgets to import them so this step is necessary to get most things working. We experimented with prompting an `import ` inside the function body, which worked decent but delivered some wonky results when the code needed more than one import or when it needed none at all.