Skip to content

Commit

Permalink
Merge pull request #1 from Intility/feature/templates
Browse files Browse the repository at this point in the history
feat(templates): add support for custom templates in CWC
  • Loading branch information
emilkje authored Mar 16, 2024
2 parents 94b9f9e + 00457f7 commit 84f2e9e
Show file tree
Hide file tree
Showing 9 changed files with 632 additions and 29 deletions.
37 changes: 37 additions & 0 deletions .cwc/templates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
templates:
- name: default
description: The default template to use if not otherwise specified.
systemMessage: |
You are {{ .Variables.personality }}.
Using the following context you will try to help the user as best as you can.
Context:
{{ .Context }}
Please keep in mind your personality when responding to the user.
variables:
- name: personality
description: The personality of the assistant. e.g. "a helpful assistant"
defaultValue: "a helpful assistant"

- name: cc
description: A template for conventional commits.
defaultPrompt: "Given these changes please help me author a conventional commit message."
systemMessage: |
You are an expert coder and technical writer.
Using the following diff you will be able to create a conventional commit message.
Diff:
```diff
{{ .Context }}
```
Instructions:
* Unless otherwise specified, please respond with only the commit message.
* Do not guess any type of issues references or otherwise that are not present in the diff.
* Keep the line length to 50 in the title and 72 in the body.
* Do not format the output with ``` blocks or other markdown features,
only return the message title and body in plain text.
My job depends on your ability to follow these instructions, you can do this!
102 changes: 100 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,112 @@ PROMPT="please write me a conventional commit for these changes"
git diff HEAD | cwc $PROMPT | git commit -e --file -
```

## Template Features

### Overview

Chat With Code (CWC) introduces the flexibility of custom templates to enhance the conversational coding experience.
Templates are pre-defined system messages and prompts that tailor interactions with your codebase.
A template envelops default prompts, system messages and variables, allowing for a personalized and context-aware dialogue.

### Template Schema

Each template follows a specific YAML schema defined in `templates.yaml`.
Here's an outline of the schema for a CWC template:
```yaml
templates:
- name: template_name
description: A brief description of the template's purpose
defaultPrompt: An optional default prompt to use if none is provided
systemMessage: |
The system message that details the instructions and context for the chat session.
This message supports placeholders for {{ .Context }} which is the gathered file context,
as well as custom variables `{{ .Variables.variableName }}` fed into the session with cli args.
variables:
- name: variableName
description: Description of the variable
defaultValue: Default value for the variable
```
### Placement
Templates may be placed within the repository or under the user's configuration directory, adhering to the XDG Base Directory Specification:
1. **In the Repository Directory**: To include the templates specifically for a repository, place a `templates.yaml` inside the `.cwc` directory at the root of your repository:
```
.
├── .cwc
│ └── templates.yaml
...
```
2. **In the User XDG CWC Config Directory**: For global user templates, place the `templates.yaml` within the XDG configuration directory for CWC, which is typically `~/.config/cwc/` on Unix-like systems:
```
$XDG_CONFIG_HOME/cwc/templates.yaml
```
If `$XDG_CONFIG_HOME` is not set, it defaults to `~/.config`.
### Example Usage
You can specify a template using the `-t` flag and pass variables with the `-v` flag in the terminal. These flags allow you to customize the chat session based on the selected template and provided variables.
#### Selecting a Template
To begin a chat session using a specific template, use the `-t` flag followed by the template name:
```sh
cwc -t my_template
```
This command will start a conversation with the system message and default prompt defined in the template named `my_template`.
#### Passing Variables to a Template
You can pass variables to a template using the `-v` flag followed by a key-value pair:
```sh
cwc -t my_template -v personality="a helpful assistant",name="Juno"
```
Here, the `my_template` template is used. The `personality` variable is set to "a helpful coding assistant", and
the `name` variable is set to "Juno". These variables will be fed into the template's system message where placeholders are specified.
The template supporting these variables might look like this:
```yaml
name: my_template
description: A custom template with modifiable personality and name
systemMessage: |
You are {{ .Variables.personality }} named {{ .Variables.name }}.
Using the following context you will be able to help the user.

Context:
{{ .Context }}

Please keep in mind your personality when responding to the user.
If the user asks for your name, you should respond with {{ .Variables.name }}.
variables:
- name: personality
description: The personality of the assistant. e.g. "a helpful assistant"
defaultValue: a helpful assistant
- name: name
description: The name of the assistant. e.g. "Juno"
defaultValue: Juno
```
> Notice that the `personality` and `name` variables have default values, which will be used if no value is provided in the `-v` flag.
## Roadmap
> Note: these items may or may not be implemented in the future.
These items may or may not be implemented in the future.
- [ ] tests
- [ ] support both azure and openai credentials
- [ ] customizable tools
- [ ] system message / prompt templates with `-t` flag
## Contributing
Expand Down
Loading

0 comments on commit 84f2e9e

Please sign in to comment.