Package: llm-code
llm-codeAn OpenAI LLM based CLI coding assistant.llm-codeis inspired bySimon Wilson'sllmpackage. It takes a similar approach of developing
a simple tool to create an LLM based assistant that helps write code.Installationpipxinstallllm-codeConfigurationllm-coderequires an OpenAI API key. You can get one fromOpenAI.You can set the key in a few different ways, depending on your preference:Set theOPENAI_API_KEYenvironment variable.exportOPENAI_API_KEY=sk-...Use an env file in ~/.llm_code/envmkdir-p~/.llm_codeecho"OPENAI_API_KEY=sk-...">~/.llm_code/envUsagellm-codeis meant to be simple to use. The default prompts should be good enough. There are two broad modes:Generage some code from scratch.llm-code"write a function that takes a list of numbers and returns the sum of the numbers in python. Add type hints."Give in some input files and ask for changes.llm-code-imy_file.py"add docstrings to all python functions."llm-code--helpUsage: llm-code [OPTIONS] [INSTRUCTIONS]...

  Coding assistant using OpenAI's chat models.

  Requires OPENAI_API_KEY as an environment variable. Alternately, you can set
  it in ~/.llm_code/env.

Options:
  -i, --inputs TEXT  Glob of input files. Use repeatedly for multiple files.
  -cb, --clipboard   Copy code to clipboard.
  -nc, --no-cache    Don't use cache.
  -4, --gpt-4        Use GPT-4.
  --version          Show version.
  --help             Show this message and exit.Changing OpenAI parametersAny of the OpenAI parameters can be changed using environment variables. GPT-4 is one exception: you can also set it using-4for convenience.exportMAX_TOKENS=2000exportTEMPERATURE=0.5exportMODEL=gpt-4orllm-code-4...CachingA common usage pattern is to examine the output of a model and either accept it, or continue to play around with the prompts. When "accepting" the output, a common thing is to append it to a file, or copy it to the clipboard (usingpbcopyon a mac, for example.). To facilitate this workflow of inspection and acceptance,llm-codecaches the output of the model in a local sqlite database. This allows you to replay the same query without having to hit the OpenAI API.llm-code'write a function that takes a list of numbers and returns the sum of the numbers in python. Add type hints.'Following this, assuming you like the output:llm-code'write a function that takes a list of numbers and returns the sum of the numbers in python. Add type hints.'>sum.pyDatabaseBorrowing simonw's excellent idea of logging things to a local sqlite, as demonstrated inllm,llm-codealso logs all queries to a local sqlite database. This is useful for a few reasons:It allows you to replay the same query without having to hit the OpenAI API.It allows you to see what queries you've made in the past with responses, and number of tokens used.ExamplesSimple hello world.llm-codewritehelloworldinrustfnmain(){println!("Hello, world!");}Sum of two numbers with type hints.llm-code"write a function that takes a list of numbers and returns the sum of the numbers in python. Add type hints."fromtypingimportListdefsum_numbers(numbers:List[int])->int:returnsum(numbers)Lets assume that we stuck the output of the previous call inout.py. We can now say:llm-code-iout.py"add appropriate docstrings"fromtypingimportListdefsum_numbers(numbers:List[int])->int:"""Return the sum of the given list of numbers."""returnsum(numbers)Or we could write some unit tests.llm-code-iout.py"write a complete unit test file using pytest.importpytestfromtypingimportListfrommy_moduleimportsum_numbersdeftest_sum_numbers():assertsum_numbers([1,2,3])==6assertsum_numbers([-1,0,1])==0assertsum_numbers([])==0TODOAdd a simple cache to replay the same query.Add logging to a local sqllite db.Add an--execoption to execute the generated code.Add a--statsoption to output token counts.Addpyperclipintegration to copy to clipboard.