Package: lockhart
LockhartTable of ContentsInstallationLicenseInstallationpipinstalllockhart## or with pipxpipxinstalllockhartInstructionsYou will need an openai key, you can obtain one from theirwebsite. Once you have it then set
yourOPENAI_API_KEYenvironment variable.exportOPENAI_API_KEY='sk-***'Lockhart it currently very crude, it works out of the clipboard. Copy a
function to your clipboard, runlockhart docstringthen paste the docstring
in.lockhart tuilockharttuihttps://user-images.githubusercontent.com/22648375/217840817-04626da4-8558-4fc4-8b05-ff0e57a2a28b.mp4keysC - Create new codee - edit return value from history itemE - open an empty edit templateo - open the current prompt from historyj - next item from historyk - prev item from historyq - quitd - toggle dark modeb - toggle sidebar of preset promptsG - open an empty prompt for writing a git commitEditing promptsCurrently the tui runs the users configured$EDITORin a subprocess, waits for the editor to close, and if the file was changed then it runs the prompt.  If the file was not changed then it does not run the prompt.## mac/linuxexportEDITOR=vim## windowssetEDITOR=notepadclosing vim:xwithout a change to the content will not trigger a file change and the prompt will not run.  If you want to use the prompt as-is without edit close vim with:wq.CLIlockhart prompt runYou can also run stored prompts from the command line without the tui.## pipe text into your promptecho'write a python3.10 hello world function'|lockhartpromptruncode-create## use the --text flaglockhartpromptruncode-create--text'write a python3.10 hello world function'## directly edit your prompt with the editorlockhartpromptruncode-create--editThe cli also handles text being piped into a prompt run.  You can still--editit, or pipe the results somewhere.  Many of the commit messages in this repo were created using this.## pre-populate your commit messagegitdiff--staged|lockhartpromptruncommit|gitcommit-evF-## write a changelog entry for your current prghprdiff|lockhartpromptrunchangelog--edit## write a changelog entry for your current staged changesgitdiff--staged|lockhartpromptrunchangelog--editlisting promptsThe cli can list all of the prompts configured in~/.config/lockhart/lockhart.tomlusing the cli.lockhartpromptlistlockhart historyThe cli can output your entire history as json.lockharthistorylistOriginal features that need re-implementedThese shouldn't be too bad to get re-implemented, but I think we need a pre-processor to be able to get this working.Docstring Examplesdefadd(a,b):"""Add two numbers together.Args:a (int): The first number to add.b (int): The second number to add.Returns:int: The sum of the two numbers.Example:add(2, 3) -> 5"""returna+bWithout even type hinting the argumentslockhartcan see that this function is using pandas.defget_summary_data(df):"""This function takes a dataframe as an argument and returns a summary of the data grouped by column A.Args:df (DataFrame): The dataframe to be summarized.Returns:DataFrame: A summary of the data grouped by column A, containing the sum of columns C and D.Example:df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9], 'D': [10, 11, 12]})get_summary_data(df)"""df.groupby("A")[["C","D"]].sum()Here is an example from the fastapi docs. It writes a correct docstring to
describe the function, but misses out that its a fastapi route without more
context than just the function.@app.put("/items/{item_id}")defupdate_item(item_id:int,item:Item):"""Update an item in the database.This function takes an item_id and an item object as parameters and updates the item in the database.Args:item_id (int): The id of the item to be updated.item (Item): The item object to be updated.Returns:dict: A dictionary containing the item_id and the updated item.Example:results = update_item(1, {'name': 'Foo', 'price': 10.99})"""results={"item_id":item_id,"item":item}returnresultsExamples Refactordefadd(a,b):returna+b# refactor the following code to compute the ratio of the two numbersdefratio(a,b):returna/b# Beforedefget_summary_data(df):df.groupby("A")[["C","D"]].sum()# refactor the following code to also return the averages# Afterdefget_summary_data(df):df.groupby("A")[["C","D"]].agg(["sum","mean"])Runlockhart refactor, then set the prompt torefactor the following code to accept a parameter item_name. It did a great job at adding it to the
arguments list, type hinting it to a string, but again missed that this is a
fastapi route and we wanted to also update the decorator.```python# before@app.put("/items/{item_id}")defupdate_item(item_id:int,item:Item):results={"item_id":item_id,"item":item}returnresults# refactor the following code to accept a parameter item_name# after@app.put("/items/{item_id}")defupdate_item(item_id:int,item_name:str,item:Item):results={"item_id":item_id,"item_name":item_name,"item":item}returnresultsLicenselockhartis distributed under the terms of theMITlicense.