Skip to content

Commit 84f2e9e

Browse files
authored
Merge pull request #1 from Intility/feature/templates
feat(templates): add support for custom templates in CWC
2 parents 94b9f9e + 00457f7 commit 84f2e9e

File tree

9 files changed

+632
-29
lines changed

9 files changed

+632
-29
lines changed

.cwc/templates.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
templates:
2+
- name: default
3+
description: The default template to use if not otherwise specified.
4+
systemMessage: |
5+
You are {{ .Variables.personality }}.
6+
Using the following context you will try to help the user as best as you can.
7+
8+
Context:
9+
{{ .Context }}
10+
11+
Please keep in mind your personality when responding to the user.
12+
variables:
13+
- name: personality
14+
description: The personality of the assistant. e.g. "a helpful assistant"
15+
defaultValue: "a helpful assistant"
16+
17+
- name: cc
18+
description: A template for conventional commits.
19+
defaultPrompt: "Given these changes please help me author a conventional commit message."
20+
systemMessage: |
21+
You are an expert coder and technical writer.
22+
Using the following diff you will be able to create a conventional commit message.
23+
24+
Diff:
25+
```diff
26+
{{ .Context }}
27+
```
28+
29+
Instructions:
30+
31+
* Unless otherwise specified, please respond with only the commit message.
32+
* Do not guess any type of issues references or otherwise that are not present in the diff.
33+
* Keep the line length to 50 in the title and 72 in the body.
34+
* Do not format the output with ``` blocks or other markdown features,
35+
only return the message title and body in plain text.
36+
37+
My job depends on your ability to follow these instructions, you can do this!

README.md

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,112 @@ PROMPT="please write me a conventional commit for these changes"
108108
git diff HEAD | cwc $PROMPT | git commit -e --file -
109109
```
110110

111+
## Template Features
112+
113+
### Overview
114+
115+
Chat With Code (CWC) introduces the flexibility of custom templates to enhance the conversational coding experience.
116+
Templates are pre-defined system messages and prompts that tailor interactions with your codebase.
117+
A template envelops default prompts, system messages and variables, allowing for a personalized and context-aware dialogue.
118+
119+
### Template Schema
120+
121+
Each template follows a specific YAML schema defined in `templates.yaml`.
122+
Here's an outline of the schema for a CWC template:
123+
124+
```yaml
125+
templates:
126+
- name: template_name
127+
description: A brief description of the template's purpose
128+
defaultPrompt: An optional default prompt to use if none is provided
129+
systemMessage: |
130+
The system message that details the instructions and context for the chat session.
131+
This message supports placeholders for {{ .Context }} which is the gathered file context,
132+
as well as custom variables `{{ .Variables.variableName }}` fed into the session with cli args.
133+
variables:
134+
- name: variableName
135+
description: Description of the variable
136+
defaultValue: Default value for the variable
137+
```
138+
139+
### Placement
140+
141+
Templates may be placed within the repository or under the user's configuration directory, adhering to the XDG Base Directory Specification:
142+
143+
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:
144+
145+
```
146+
.
147+
├── .cwc
148+
│ └── templates.yaml
149+
...
150+
```
151+
152+
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:
153+
154+
```
155+
$XDG_CONFIG_HOME/cwc/templates.yaml
156+
```
157+
158+
If `$XDG_CONFIG_HOME` is not set, it defaults to `~/.config`.
159+
160+
### Example Usage
161+
162+
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.
163+
164+
#### Selecting a Template
165+
166+
To begin a chat session using a specific template, use the `-t` flag followed by the template name:
167+
168+
```sh
169+
cwc -t my_template
170+
```
171+
172+
This command will start a conversation with the system message and default prompt defined in the template named `my_template`.
173+
174+
#### Passing Variables to a Template
175+
176+
You can pass variables to a template using the `-v` flag followed by a key-value pair:
177+
178+
```sh
179+
cwc -t my_template -v personality="a helpful assistant",name="Juno"
180+
```
181+
182+
Here, the `my_template` template is used. The `personality` variable is set to "a helpful coding assistant", and
183+
the `name` variable is set to "Juno". These variables will be fed into the template's system message where placeholders are specified.
184+
185+
The template supporting these variables might look like this:
186+
187+
```yaml
188+
name: my_template
189+
description: A custom template with modifiable personality and name
190+
systemMessage: |
191+
You are {{ .Variables.personality }} named {{ .Variables.name }}.
192+
Using the following context you will be able to help the user.
193+
194+
Context:
195+
{{ .Context }}
196+
197+
Please keep in mind your personality when responding to the user.
198+
If the user asks for your name, you should respond with {{ .Variables.name }}.
199+
variables:
200+
- name: personality
201+
description: The personality of the assistant. e.g. "a helpful assistant"
202+
defaultValue: a helpful assistant
203+
- name: name
204+
description: The name of the assistant. e.g. "Juno"
205+
defaultValue: Juno
206+
```
207+
208+
> Notice that the `personality` and `name` variables have default values, which will be used if no value is provided in the `-v` flag.
209+
111210
## Roadmap
112211
113-
> Note: these items may or may not be implemented in the future.
212+
These items may or may not be implemented in the future.
114213
115214
- [ ] tests
116215
- [ ] support both azure and openai credentials
117216
- [ ] customizable tools
118-
- [ ] system message / prompt templates with `-t` flag
119217
120218
## Contributing
121219

0 commit comments

Comments
 (0)