No project description provided
Project description
PatchWork
An open-source framework for automating development chores using large language models. PatchWork allows you to automate workflows like PR reviews, bug fixing, security patching, and more using a self-hosted CLI agent and your preferred LLMs.
Key Components
- Steps: Reusable atomic actions like create PR, commit changes or call an LLM.
- Prompt Templates: Customizable LLM prompts optimized for a chore like library updates, code generation, issue analysis or vulnerability remediation.
- Patchflows: LLM-assisted automations such as PR reviews, code fixing, documentation etc. built by combining steps and prompts.
Patchflows can be run locally in your CLI and IDE, or as part of your CI/CD pipeline. There are several patchflows available out of the box, and you can always create your own.
Quickstart
Installation
Using Pip
PatchWork is available on PyPI and can be installed using pip:
pip install 'patchwork-cli[all]' --upgrade
The following optional dependency groups are available.
- security: installs semgrep and depscan with
pip install 'patchwork-cli[security]'
and is required for AutoFix and DependencyUpgrade patchflows. - rag: installs chromadb with
pip install 'patchwork-cli[rag]'
and is required for the ResolveIssue patchflow. - notifications: Used by steps sending notifications, e.g. slack messages.
- all: installs everything.
- not specifying any dependency group (
pip install patchwork-cli
) will install a core set of dependencies that are sufficient to run the GenerateDocstring, PRReview and GenerateREADME patchflows.
Using Poetry
If you'd like to build from source using poetry, please see detailed documentation here .
PatchWork CLI
The CLI runs Patchflows, as follows:
patchwork <PatchFlow> <?Arguments>
Where
- Arguments: Allow for overriding default/optional attributes of the Patchflow in the format of
key=value
. Ifkey
does not have any value, it is considered a booleanTrue
flag.
Example
For an AutoFix patchflow which patches vulnerabilities based on a scan using Semgrep:
patchwork AutoFix openai_api_key=<YOUR_OPENAI_API_KEY> github_api_key=<YOUR_GITHUB_TOKEN>
The above command will default to patching code in the current directory, by running Semgrep to identify the vulnerabilities. You can take a look at the default.yml
file for the list of configurations you can set to manage the AutoFix patchflow.
You can replace the OpenAI key with a key from our managed service by signing in at https://app.patched.codes/signin and generating an API key from the integrations tab. You can then call the patchflow with the key as follows:
patchwork AutoFix patched_api_key=<YOUR_PATCHED_API_KEY> github_api_key=<YOUR_GITHUB_TOKEN>
Similarly, to use Google's models you can set the google_api_key
and model
, this is useful if you want to work with large contexts as the gemini-pro-1.5
model supports an input context length of 1 million tokens.
The patchwork-template repository contains the default configuration and prompts for all the patchflows. You can clone that repo and pass it as a flag to the CLI:
patchwork AutoFix --config /path/to/patchwork-configs/patchflows
Patchflows
Patchwork comes with a set of predefined patchflows, and more will be added over time. Below is a sample list of patchflows:
- GenerateDocstring: Generate docstrings for methods in your code.
- AutoFix: Generate and apply fixes to code vulnerabilities in a repository.
- PRReview: On PR creation, extract code diff, summarize changes, and comment on PR.
- GenerateREADME: Create a README markdown file for a given folder, to add documentation to your repository.
- DependencyUpgrade: Update your dependencies from vulnerable to fixed versions.
- ResolveIssue: Identify the files in your repository that need to be updated to resolve an issue (or bug) and create a PR to fix it.
Prompt Templates
Prompt templates are used by patchflows and passed as queries to LLMs. Templates contain prompts with placeholder variables enclosed by {{}} which are replaced by the data from the steps or inputs on every run.
Below is a sample prompt template:
{
"id": "diffreview_summary",
"prompts": [
{
"role": "user",
"content": "Summarize the following code change descriptions in 1 paragraph. {{diffreviews}}"
}
]
}
Each patchflow comes with an optimized default prompt template. But you can specify your own using the prompt_template_file=/path/to/prompt/template/file
option.
Contributing
Contributions for new patchflows and steps, or even to the core framework are welcome. Please look at open issues for details.
- To create a new patchflow, follow these instructions.
- To create a new step, follow these instructions.
We also provide chat assistants to help you create new steps and patchflows easily. Fair warning: they suffer from the same limitations as their underlying model.
- Patchwork Assistant GPT (based on GPT-4)
- Patchwork Assistant on HuggingChat (based on Llama-3)
Roadmap
Short Term
- Expand patchflow library and integration options
- Patchflow debugger and validation module
- Bug fixing and performance improvements
- Refactor code and documentation
Long Term
- Support large-scale code embeddings in patchflows
- Support parallelization and branching
- Fine-tuned models that can be self-hosted
- Open-source GUI
License
Patchwork is licensed under AGPL-3.0 terms. However, custom patchflows and steps can be created and shared using the patchwork template repository which is licensed under Apache-2.0 terms.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file patchwork_cli-0.0.32.tar.gz
.
File metadata
- Download URL: patchwork_cli-0.0.32.tar.gz
- Upload date:
- Size: 100.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7071e2403932acf09f397f31d92755e7526ad7a046cd934faf6bde45c1d40a6 |
|
MD5 | a90e6eef25e4179384f8f662a95c1094 |
|
BLAKE2b-256 | 886c760b1db4d9d9b0e10c077fdc8fb5eddff059cc29dcf1e0efde65a3e5436d |
File details
Details for the file patchwork_cli-0.0.32-py3-none-any.whl
.
File metadata
- Download URL: patchwork_cli-0.0.32-py3-none-any.whl
- Upload date:
- Size: 165.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8461b720f342840ce8a65e84bc0a37b48ad6db38f0fb4522e0c487236d44b74 |
|
MD5 | a6ca44b51d30eaccb009d6db4af1e0c2 |
|
BLAKE2b-256 | 9627309daecb66bab3a73c487238893e726bb8d1154b9f65614feda02a1361a9 |