promptcraft 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +492 -0
- data/Rakefile +8 -0
- data/docs/images/chatgpt-vision-to-yaml.png +0 -0
- data/examples/maths/start/already_answered.yml +8 -0
- data/examples/maths/start/already_answered_gpt4.yml +11 -0
- data/examples/maths/start/already_answered_multiple.yml +18 -0
- data/examples/maths/start/already_answered_multiple_providers.yml +30 -0
- data/examples/maths/start/another_question.yml +11 -0
- data/examples/maths/start/basic.yml +9 -0
- data/examples/maths/start/many_limericks.yml +51 -0
- data/examples/maths/start/prompt.yml +3 -0
- data/examples/maths/start/system_only.yml +5 -0
- data/exe/promptcraft +7 -0
- data/lib/promptcraft/cli/run_command.rb +177 -0
- data/lib/promptcraft/cli.rb +3 -0
- data/lib/promptcraft/command/llm_chat_command.rb +22 -0
- data/lib/promptcraft/command/rechat_conversation_command.rb +37 -0
- data/lib/promptcraft/command.rb +4 -0
- data/lib/promptcraft/conversation.rb +105 -0
- data/lib/promptcraft/helpers.rb +25 -0
- data/lib/promptcraft/llm.rb +55 -0
- data/lib/promptcraft/version.rb +5 -0
- data/lib/promptcraft.rb +11 -0
- data/sig/promptcraft.rbs +4 -0
- metadata +216 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ccfea1d708de15e5bc3e3d8b2bf179813014ba45f84d4a2b950fcb91109c1698
|
4
|
+
data.tar.gz: 36acdfa7e390788b0cc62a3f88bd6259cbc8cab0140d8d1b0c68b9eb197f9839
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23b0f0febcf5574f183b6f35a0452c75ba4f4be43e1edb35dfa96c0b957d0d9db42e4bf9a7edaf212d080e5e41b91a959d81d5a56e8addca7819a85552bc43ba
|
7
|
+
data.tar.gz: be1c072618fe888cae89f2e1ef2a5e781b9ce65c3bc38b7359d507487ee95d114a7c76286920fba2cc170adfc7a19f2099581668dde80518e213ac5c83672282
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at drnicwilliams@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Dr Nic Williams
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,492 @@
|
|
1
|
+
# Promptcraft
|
2
|
+
|
3
|
+
Try out new system prompts on your existing AI conversations. Over and over until you're happy.
|
4
|
+
|
5
|
+
The `promptcraft` CLI let's you replay a conversation between a user and an AI assistant, but with a new system prompt.
|
6
|
+
|
7
|
+
Conversations are stored in YAML files that look like:
|
8
|
+
|
9
|
+
```yaml
|
10
|
+
system_prompt: I like to solve maths problems.
|
11
|
+
|
12
|
+
messages:
|
13
|
+
- role: "user"
|
14
|
+
content: "What is 2+2?"
|
15
|
+
- role: assistant
|
16
|
+
content: 2 + 2 = 4
|
17
|
+
```
|
18
|
+
|
19
|
+
Let's replay this single conversation with a new system prompt:
|
20
|
+
|
21
|
+
```plain
|
22
|
+
bundle exec exe/promptcraft \
|
23
|
+
--prompt "I'm terrible at maths. If I'm asked a maths question, I reply with a question." \
|
24
|
+
--conversation examples/maths/start/already_answered.yml
|
25
|
+
```
|
26
|
+
|
27
|
+
The output is the new conversation containing the same user messages, plus the new system prompt and new responses by the AI assistant:
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
---
|
31
|
+
system_prompt: |-
|
32
|
+
I'm terrible at maths.
|
33
|
+
If I'm asked a maths question,
|
34
|
+
I reply with a question.
|
35
|
+
messages:
|
36
|
+
- role: user
|
37
|
+
content: What is 2+2?
|
38
|
+
- role: assistant
|
39
|
+
content: What's the airspeed velocity of an unladen swallow?
|
40
|
+
```
|
41
|
+
|
42
|
+
That is, the output looks exactly like the input, but with the new system prompt and new assistant responses.
|
43
|
+
|
44
|
+
The input `--conversation` can contain multiple YAML documents, and the output will contain multiple YAML documents.
|
45
|
+
|
46
|
+
For example, [examples/maths/start/already_answered_multiple.yml](examples/maths/start/already_answered_multiple.yml) contains two conversations:
|
47
|
+
|
48
|
+
```yaml
|
49
|
+
---
|
50
|
+
system_prompt: |-
|
51
|
+
I like to solve maths problems.
|
52
|
+
|
53
|
+
messages:
|
54
|
+
- role: "user"
|
55
|
+
content: "What is 2+2?"
|
56
|
+
- role: assistant
|
57
|
+
content: 2 + 2 = 4
|
58
|
+
---
|
59
|
+
system_prompt: |-
|
60
|
+
I like to solve maths problems.
|
61
|
+
|
62
|
+
messages:
|
63
|
+
- role: "user"
|
64
|
+
content: "What is 6 divided by 2?"
|
65
|
+
- role: assistant
|
66
|
+
content: 6 / 2 = 3
|
67
|
+
```
|
68
|
+
|
69
|
+
The CLI will replay each conversation with the new system prompt.
|
70
|
+
|
71
|
+
```plain
|
72
|
+
bundle exec exe/promptcraft \
|
73
|
+
--conversation examples/maths/start/already_answered_multiple.yml \
|
74
|
+
--prompt "I like cats. Answer any questions using cats."
|
75
|
+
```
|
76
|
+
|
77
|
+
The output shows each system prompt has been updated and the `assistant`'s response has been re-generated using the new system prompt:
|
78
|
+
|
79
|
+
```yaml
|
80
|
+
---
|
81
|
+
system_prompt: I like cats. Answer any questions using cats.
|
82
|
+
llm:
|
83
|
+
provider: groq
|
84
|
+
model: llama3-70b-8192
|
85
|
+
messages:
|
86
|
+
- role: user
|
87
|
+
content: What is 2+2?
|
88
|
+
- role: assistant
|
89
|
+
content: That's an easy one! You know how many paws a typical cat has? That's right,
|
90
|
+
4! And if I were to divide those paws into two groups of two, I'd have... 2+2
|
91
|
+
= 4!
|
92
|
+
---
|
93
|
+
system_prompt: I like cats. Answer any questions using cats.
|
94
|
+
llm:
|
95
|
+
provider: groq
|
96
|
+
model: llama3-70b-8192
|
97
|
+
messages:
|
98
|
+
- role: user
|
99
|
+
content: What is 6 divided by 2?
|
100
|
+
- role: assistant
|
101
|
+
content: That's an easy one! Imagine you have 6 adorable kittens, and you want to
|
102
|
+
divide them evenly between two cat beds. How many kittens would you put in each
|
103
|
+
bed? That's right, 3! So, 6 divided by 2 is 3.
|
104
|
+
```
|
105
|
+
|
106
|
+
The example [examples/maths/start/already_answered_multiple_providers.yml](examples/maths/start/already_answered_multiple_providers.yml) contains a conversation with the same messages, but different provider/models.
|
107
|
+
|
108
|
+
Alternately, you can pass `--conversation` option multiple times to process multiple conversation files.
|
109
|
+
|
110
|
+
```plain
|
111
|
+
bundle exec be exe/promptcraft \
|
112
|
+
--conversation examples/maths/start/already_answered.yml \
|
113
|
+
--conversation examples/maths/start/already_answered_gpt4.yml \
|
114
|
+
--prompt "Answer like a pirate. A maths pirate."
|
115
|
+
```
|
116
|
+
|
117
|
+
When you're getting started, you don't even need to know the conversation file format. Just pass in a series of user messages separated by `---` and a system prompt:
|
118
|
+
|
119
|
+
```plain
|
120
|
+
echo "---\nWhat is 2+2?\n---\nWhat is 6 divided by 2?" | \
|
121
|
+
bundle exec exe/promptcraft --prompt "I solve maths using pizza metaphors."
|
122
|
+
```
|
123
|
+
|
124
|
+
The output will be our conversation YAML format, with the system prompt, the incoming user messages as separate conversations, and the assistant replies within each conversation:
|
125
|
+
|
126
|
+
```yaml
|
127
|
+
---
|
128
|
+
system_prompt: I solve maths using pizza metaphors.
|
129
|
+
llm:
|
130
|
+
provider: groq
|
131
|
+
model: llama3-70b-8192
|
132
|
+
messages:
|
133
|
+
- role: user
|
134
|
+
content: What is 2+2?
|
135
|
+
- role: assistant
|
136
|
+
content: |-
|
137
|
+
You want to know the answer to 2+2? Well, let me slice it up for you!
|
138
|
+
|
139
|
+
Imagine you have 2 slices of pizza, and your friend has 2 slices of pizza. If you combine your slices, how many slices do you have now?
|
140
|
+
|
141
|
+
That's right! You have a total of 4 slices of pizza! So, 2+2 is equal to... (drumroll please)... 4!
|
142
|
+
---
|
143
|
+
system_prompt: I solve maths using pizza metaphors.
|
144
|
+
llm:
|
145
|
+
provider: groq
|
146
|
+
model: llama3-70b-8192
|
147
|
+
messages:
|
148
|
+
- role: user
|
149
|
+
content: What is 6 divided by 2?
|
150
|
+
- role: assistant
|
151
|
+
content: |-
|
152
|
+
Think of it like this: Imagine you have 6 slices of pizza and you want to share them equally among 2 of your friends. How many slices will each friend get?
|
153
|
+
|
154
|
+
That's right! Each friend will get 3 slices of pizza! So, 6 divided by 2 is... 3!
|
155
|
+
```
|
156
|
+
|
157
|
+
You'll notice, the LLM used (which defaults to Groq's `llama3-70b-8192` because its fast and cheap) is included in the output. See below for selecting a different LLM, such as:
|
158
|
+
|
159
|
+
* `--provider groq --model llama3-70b-8192` (using `$GRQ_API_KEY`)
|
160
|
+
* `--provider openai --model chatgpt-4-turbo` (using `$OPENAI_API_KEY`)
|
161
|
+
* `--provider openrouter --model meta-llama/llama-3-8b-instruct:free` (using `$OPENROUTER_API_KEY`)
|
162
|
+
* `--provider ollama --model llama3` (running on `http://localhost:11434`)
|
163
|
+
|
164
|
+
Of course, you could pass each plain text user message using the `--conversation` argument too:
|
165
|
+
|
166
|
+
```plain
|
167
|
+
bundle exec exe/promptcraft \
|
168
|
+
--conversation "What is 2+2?"
|
169
|
+
--conversation "What is 6 divided by 2?" \
|
170
|
+
--prompt "I solve maths using pizza metaphors."
|
171
|
+
```
|
172
|
+
|
173
|
+
Why does it output YAML? (or JSON if you pass `--json` flag) So that you can save it to a file; and then replay (or rechat) this new set of conversations in a minute with a new system prompt.
|
174
|
+
|
175
|
+
```plain
|
176
|
+
bundle exec exe/promptcraft \
|
177
|
+
--conversation "What is 2+2?" \
|
178
|
+
--conversation "What is 6 divided by 2?" \
|
179
|
+
--prompt "I am happy person". \
|
180
|
+
> tmp/maths-as-happy-person.yml
|
181
|
+
|
182
|
+
bundle exec exe/promptcraft \
|
183
|
+
--conversation tmp/maths-as-happy-person.yml \
|
184
|
+
--prompt "I solve maths using pizza metaphors." \
|
185
|
+
> tmp/maths-with-pizza.yml
|
186
|
+
|
187
|
+
# perhaps put big prompts in files
|
188
|
+
echo "I am an excellent maths tutor.
|
189
|
+
|
190
|
+
When I'm asked a maths question, I will first
|
191
|
+
ask a question in return to help the student." > tmp/prompt-maths-tutor.txt
|
192
|
+
|
193
|
+
bundle exec exe/promptcraft \
|
194
|
+
--conversation tmp/maths-with-pizza.yml \
|
195
|
+
--prompt tmp/prompt-maths-tutor.txt
|
196
|
+
```
|
197
|
+
|
198
|
+
Now you have the output conversations in separate files, each with the system prompt and LLM used to produce the assistant replies.
|
199
|
+
|
200
|
+
Can you use AI to produce lots of sample user messages and then see what how your system prompt would respond? Yes indeed. Now you're getting it.
|
201
|
+
|
202
|
+
```plain
|
203
|
+
echo "When you are asked to create a list you put each item in a YAML stream document like:
|
204
|
+
|
205
|
+
---
|
206
|
+
messages:
|
207
|
+
- role: "user"
|
208
|
+
content: ITEM GOES HERE
|
209
|
+
|
210
|
+
With each one separated new line. Say nothing else except producing YAML.
|
211
|
+
" > tmp/prompt-list-20-hellos.txt
|
212
|
+
|
213
|
+
bundle exec exe/promptcraft \
|
214
|
+
-c "Generate a list of 20 things a customer might say when they first ring into a hair salon phone service" \
|
215
|
+
-p tmp/prompt-list-20-hellos.txt \
|
216
|
+
--format json > tmp/hair-salon-20-hellos.json
|
217
|
+
|
218
|
+
cat tmp/hair-salon-20-hellos.json | jq -r ".messages[1].content" \
|
219
|
+
> tmp/hair-salon-20-0000.txt
|
220
|
+
```
|
221
|
+
|
222
|
+
The file `tmp/hair-salon-20-0000.txt` now contains 20 user messages that you can use to initiate a conversation with your AI assistant system prompt.
|
223
|
+
|
224
|
+
```plain
|
225
|
+
bundle exec exe/promptcraft \
|
226
|
+
-p "I'm a hair salon phone service. I sell haircuts" \
|
227
|
+
-c tmp/hair-salon-20-0000.txt \
|
228
|
+
> tmp/hair-salon-20-replies-0001.yml
|
229
|
+
```
|
230
|
+
|
231
|
+
The file `tmp/hair-salon-20-replies-0001.yml` now contains the system prompt and the 20 user messages and the AI assistant replies.
|
232
|
+
|
233
|
+
Iterate on your system prompt until you're happy with the responses.
|
234
|
+
|
235
|
+
## See Also
|
236
|
+
|
237
|
+
Tools you might want to use in conjunction with `promptcraft`:
|
238
|
+
|
239
|
+
* `tee` takes stdout from one command and writes it to a file and also to stdout. It's useful for saving the output of a command to a file and then piping it to another command.
|
240
|
+
|
241
|
+
For example, to view the output of `promptcraft` and save it to a file at the same time:
|
242
|
+
|
243
|
+
```plain
|
244
|
+
promptcraft ... | tee output.yml
|
245
|
+
```
|
246
|
+
* [`yq`](https://mikefarah.gitbook.io/yq/) is a lightweight and portable command-line YAML processor. It's useful for extracting and modifying YAML files.
|
247
|
+
|
248
|
+
For example, to extract the 2nd message from a conversation:
|
249
|
+
|
250
|
+
```plain
|
251
|
+
cat conversation.yml | yq .messages.1.content
|
252
|
+
```
|
253
|
+
|
254
|
+
* [`xq`](https://github.com/sibprogrammer/xq) is a lightweight and flexible command-line XML processor. It's useful for extracting and modifying XML files.
|
255
|
+
|
256
|
+
If the message content contains some XML, e.g. `<users_json>{...}</users_json>`, and you want the contents:
|
257
|
+
|
258
|
+
```plain
|
259
|
+
cat conversation.yml | yq .messages.1.content | xq -x //users_json
|
260
|
+
```
|
261
|
+
|
262
|
+
* [`jq`](https://stedolan.github.io/jq/) is a lightweight and flexible command-line JSON processor. It's useful for extracting and modifying JSON files.
|
263
|
+
|
264
|
+
## Installation
|
265
|
+
|
266
|
+
Right now, you need to run the CLI from the source code.
|
267
|
+
|
268
|
+
```plain
|
269
|
+
git clone https://github.com/drnic/promptcraft
|
270
|
+
cd promptcraft
|
271
|
+
bin/setup
|
272
|
+
bundle exec exe/promptcraft \
|
273
|
+
--conversation examples/maths/start/already_answered.yml \
|
274
|
+
--prompt "I'm terrible at maths. If I'm asked a maths question, I reply with a question." \
|
275
|
+
--provider groq
|
276
|
+
```
|
277
|
+
|
278
|
+
It defaults to `--provider groq --model llama3-70b-8192` and assumes you have `$GROQ_API_KEY` set in your environment.
|
279
|
+
|
280
|
+
You can also use [OpenAI](https://openai.com/) with `--provider openai`, which defaults to `--model gpt-3.5-turbo`. It assumes you have `$OPENAI_API_KEY` set in your environment.
|
281
|
+
|
282
|
+
You can use [OpenRouter](https://openrouter.ai/) with `--provider openrouter`, which defaults to `--model meta-llama/llama-3-8b-instruct:free`. It assumes you have `$OPENROUTER_API_KEY` set in your environment.
|
283
|
+
|
284
|
+
You can also use [Ollama](https://ollama.com/) locally with `--provider ollama`, which defaults to `--model llama3`. It assumes your Ollama app is running on the default port.
|
285
|
+
|
286
|
+
If the conversation file has an `llm` key with `provider` and `model` keys, then those will be used instead of the defaults.
|
287
|
+
|
288
|
+
```plain
|
289
|
+
bundle exec exe/promptcraft \
|
290
|
+
--conversation examples/maths/start/already_answered_gpt4.yml \
|
291
|
+
--prompt "I always reply with a question"
|
292
|
+
|
293
|
+
---
|
294
|
+
system_prompt: I always reply with a question.
|
295
|
+
llm:
|
296
|
+
provider: openai
|
297
|
+
model: gpt-4-turbo
|
298
|
+
messages:
|
299
|
+
- role: user
|
300
|
+
content: What is 2+2?
|
301
|
+
- role: assistant
|
302
|
+
content: What do you think the answer is?
|
303
|
+
```
|
304
|
+
|
305
|
+
## Examples
|
306
|
+
|
307
|
+
The following example commands assume you have `$GROQ_API_KEY` and will use Groq and the `llama3-70b-8192` model as the default provider and model. You can pass `--provider openai` or `--provider ollama` to use those providers instead, and their default models.
|
308
|
+
|
309
|
+
### Getting started
|
310
|
+
|
311
|
+
Run `promptcraft` with no arguments to get a default prompt and an initial assistant message.
|
312
|
+
|
313
|
+
```plain
|
314
|
+
bundle exec exe/promptcraft
|
315
|
+
```
|
316
|
+
|
317
|
+
The output might be:
|
318
|
+
|
319
|
+
```yaml
|
320
|
+
---
|
321
|
+
system_prompt: You are helpful. If you're first, then ask a question. You like brevity.
|
322
|
+
messages:
|
323
|
+
- role: assistant
|
324
|
+
content: What do you need help with?
|
325
|
+
```
|
326
|
+
|
327
|
+
Provide a different provider, such as `openai` (which assumes you have `$OPENAI_API_KEY` set in your environment).
|
328
|
+
|
329
|
+
```plain
|
330
|
+
bundle exec exe/promptcraft --provider openai
|
331
|
+
```
|
332
|
+
|
333
|
+
Or you could provide your own system prompt, and it will generate an initial assistant message.
|
334
|
+
|
335
|
+
```plaim
|
336
|
+
bundle exec exe/promptcraft --prompt "I like to solve maths problems."
|
337
|
+
```
|
338
|
+
|
339
|
+
The output might be:
|
340
|
+
|
341
|
+
```yaml
|
342
|
+
---
|
343
|
+
system_prompt: I like to solve maths problems.
|
344
|
+
messages:
|
345
|
+
- role: assistant
|
346
|
+
content: |-
|
347
|
+
A math enthusiast! I'd be happy to provide you with some math problems to solve. What level of math are you interested in? Do you want:
|
348
|
+
|
349
|
+
1. Basic algebra (e.g., linear equations, quadratic equations)
|
350
|
+
2. Geometry (e.g., points, lines, triangles, circles)
|
351
|
+
3. Calculus (e.g., limits, derivatives, integrals)
|
352
|
+
4. Number theory (e.g., prime numbers, modular arithmetic)
|
353
|
+
5. Something else (please specify)
|
354
|
+
|
355
|
+
Let me know, and I'll provide you with a problem to solve!
|
356
|
+
```
|
357
|
+
|
358
|
+
### Providing conversations to rechat
|
359
|
+
|
360
|
+
The primary point of `promptcraft` is to replay conversations with a new system prompt. So we need to pass them in. We have a few ways:
|
361
|
+
|
362
|
+
* Pass one or more conversation files using `--conversation` or `-c` option.
|
363
|
+
* Each conversation file can contain one or more YAML documents, each separated by `---`.
|
364
|
+
* Pass in a stream of YAML documents via STDIN.
|
365
|
+
* JSON is valid YAML, if that's ever useful to you.
|
366
|
+
|
367
|
+
An example of the `--conversation` option:
|
368
|
+
|
369
|
+
```plain
|
370
|
+
bundle exec exe/promptcraft \
|
371
|
+
--conversation examples/maths/start/basic.yml
|
372
|
+
```
|
373
|
+
|
374
|
+
You can also pipe a stream of conversation YAML into `promptcraft` via STDIN
|
375
|
+
|
376
|
+
```plain
|
377
|
+
echo "---\nsystem_prompt: I like to solve maths problems.\nmessages:\n- role: \"user\"\n content: \"What is 2+2?\"" | bundle exec exe/promptcraft
|
378
|
+
```
|
379
|
+
|
380
|
+
JSON is valid YAML, so you can also use JSON:
|
381
|
+
|
382
|
+
```plain
|
383
|
+
echo "{\"system_prompt\": \"I like to solve maths problems.\", \"messages\": [{\"role\": \"user\", \"content\": \"What is 2+2?\"}]}" | bundle exec exe/promptcraft
|
384
|
+
```
|
385
|
+
|
386
|
+
Or pipe one or more files into `promptcraft`:
|
387
|
+
|
388
|
+
```plain
|
389
|
+
( cat examples/maths/start/basic.yml ; cat examples/maths/start/already_answered.yml ) | bundle exec exe/promptcraft
|
390
|
+
```
|
391
|
+
|
392
|
+
As long as the input is a stream of YAML documents (separated by `---`), it will be processed.
|
393
|
+
|
394
|
+
### Creating conversation files
|
395
|
+
|
396
|
+
You could manually create these YAML files. Sure.
|
397
|
+
|
398
|
+
You could get the scaffold for the file by running `promptcraft` with no arguments, and then copy/paste the output into a new file.
|
399
|
+
|
400
|
+
Another idea is to use the Groq or ChatGPT playgrounds. Have a conversation with the AI, and then copy a screenshot into ChatGPT and ask it to convert it to YAML:
|
401
|
+
|
402
|
+
![chatgpt-vision-to-yaml](docs/images/chatgpt-vision-to-yaml.png)
|
403
|
+
|
404
|
+
That's cool.
|
405
|
+
|
406
|
+
### Missing assistant reply
|
407
|
+
|
408
|
+
If you create a conversation and the last message is from the user, then the assistant's reply is missing. The final assistant message will always be generated and added to the conversation.
|
409
|
+
|
410
|
+
For example, this basic chat only contains the user's initial message:
|
411
|
+
|
412
|
+
```yaml
|
413
|
+
system_prompt: |-
|
414
|
+
I like to solve maths problems.
|
415
|
+
|
416
|
+
messages:
|
417
|
+
- role: "user"
|
418
|
+
content: "What is 2+2?"
|
419
|
+
```
|
420
|
+
|
421
|
+
When we replay the conversation with the same system prompt (by omitting the `--prompt` option), it will add the missing assistant reply:
|
422
|
+
|
423
|
+
```plain
|
424
|
+
bundle exec exe/promptcraft \
|
425
|
+
--conversation examples/maths/start/basic.yml
|
426
|
+
```
|
427
|
+
|
428
|
+
The output might be:
|
429
|
+
|
430
|
+
```yaml
|
431
|
+
---
|
432
|
+
system_prompt: I like to solve maths problems.
|
433
|
+
llm:
|
434
|
+
provider: groq
|
435
|
+
model: llama3-70b-8192
|
436
|
+
messages:
|
437
|
+
- role: user
|
438
|
+
content: What is 2+2?
|
439
|
+
- role: assistant
|
440
|
+
content: That's an easy one! The answer is... 4!
|
441
|
+
```
|
442
|
+
|
443
|
+
### Limericks
|
444
|
+
|
445
|
+
Here are some previously [generated limericks](examples/maths/start/many_limericks.yml). To regenerate them to start with letter "E" on each line:
|
446
|
+
|
447
|
+
```plain
|
448
|
+
bundle exec exe/promptcraft \
|
449
|
+
--conversation examples/maths/start/many_limericks.yml \
|
450
|
+
--prompt "I am excellent at limericks. I always start each line with the letter E."
|
451
|
+
```
|
452
|
+
|
453
|
+
It might still include some preamble in each response. To try to encourage the LLM to remove it:
|
454
|
+
|
455
|
+
```plain
|
456
|
+
bundle exec exe/promptcraft \
|
457
|
+
--conversation examples/maths/start/many_limericks.yml \
|
458
|
+
--prompt "I am excellent at limericks. I always start each line with the letter E. This is very important. Only return the limerick without any other comments."
|
459
|
+
```
|
460
|
+
|
461
|
+
## Development
|
462
|
+
|
463
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
464
|
+
|
465
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
466
|
+
|
467
|
+
## Releases
|
468
|
+
|
469
|
+
To set new version number:
|
470
|
+
|
471
|
+
```plain
|
472
|
+
gem bump --version [patch|minor|major]
|
473
|
+
```
|
474
|
+
|
475
|
+
To tag and release:
|
476
|
+
|
477
|
+
```plain
|
478
|
+
rake release
|
479
|
+
```
|
480
|
+
|
481
|
+
## Contributing
|
482
|
+
|
483
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/drnic/promptcraft. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/drnic/promptcraft/blob/develop/CODE_OF_CONDUCT.md).
|
484
|
+
|
485
|
+
## License
|
486
|
+
|
487
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
488
|
+
|
489
|
+
## Code of Conduct
|
490
|
+
|
491
|
+
Everyone interacting in the Promptcraft project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/drnic/promptcraft/blob/develop/CODE_OF_CONDUCT.md).
|
492
|
+
|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
system_prompt: |-
|
3
|
+
I like to solve maths problems.
|
4
|
+
|
5
|
+
messages:
|
6
|
+
- role: "user"
|
7
|
+
content: "What is 2+2?"
|
8
|
+
- role: assistant
|
9
|
+
content: 2 + 2 = 4
|
10
|
+
---
|
11
|
+
system_prompt: |-
|
12
|
+
I like to solve maths problems.
|
13
|
+
|
14
|
+
messages:
|
15
|
+
- role: "user"
|
16
|
+
content: "What is 6 divided by 2?"
|
17
|
+
- role: assistant
|
18
|
+
content: 6 / 2 = 3
|