{"id":13877915,"url":"https://github.com/drnic/promptcraft","last_synced_at":"2025-04-12T01:43:57.110Z","repository":{"id":239501321,"uuid":"797092990","full_name":"drnic/promptcraft","owner":"drnic","description":"Try new system prompts on your AI conversations. Over and over until you're happy.","archived":false,"fork":false,"pushed_at":"2024-05-21T00:11:38.000Z","size":219,"stargazers_count":37,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-03T13:45:37.578Z","etag":null,"topics":["groq","llm","openai","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drnic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-07T07:23:20.000Z","updated_at":"2025-03-26T10:41:48.000Z","dependencies_parsed_at":"2024-05-21T01:30:39.418Z","dependency_job_id":"70b8ce69-8207-4eca-90fe-c728e85c881c","html_url":"https://github.com/drnic/promptcraft","commit_stats":null,"previous_names":["drnic/promptcraft"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fpromptcraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fpromptcraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fpromptcraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fpromptcraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drnic","download_url":"https://codeload.github.com/drnic/promptcraft/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505932,"owners_count":21115354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["groq","llm","openai","ruby"],"created_at":"2024-08-06T08:01:34.801Z","updated_at":"2025-04-12T01:43:57.090Z","avatar_url":"https://github.com/drnic.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Promptcraft\n\nTry out new system prompts on your existing AI conversations. Over and over until you're happy.\n\nThe `promptcraft` CLI lets you replay a conversation between a user and an AI assistant, but with a new system prompt.\n\nConversations are stored in YAML files that look like:\n\n```yaml\nsystem_prompt: I like to solve maths problems.\n\nmessages:\n- role: \"user\"\n  content: \"What is 2+2?\"\n- role: assistant\n  content: 2 + 2 = 4\n```\n\nLet's replay this single conversation with a new system prompt:\n\n```plain\npromptcraft \\\n    --prompt \"I'm terrible at maths. If I'm asked a maths question, I reply with a question.\" \\\n    --conversation examples/maths/start/already_answered.yml\n```\n\nThe output is the new conversation containing the same user messages, plus the new system prompt and new responses by the AI assistant:\n\n```yaml\n---\nsystem_prompt: |-\n  I'm terrible at maths.\n  If I'm asked a maths question,\n  I reply with a question.\nmessages:\n- role: user\n  content: What is 2+2?\n- role: assistant\n  content: What's the airspeed velocity of an unladen swallow?\n```\n\nThat is, the output looks exactly like the input, but with the new system prompt and new assistant responses.\n\nThe input `--conversation` can contain multiple YAML documents, and the output will contain multiple YAML documents.\n\nFor example, [examples/maths/start/already_answered_multiple.yml](examples/maths/start/already_answered_multiple.yml) contains two conversations:\n\n```yaml\n---\nsystem_prompt: |-\n  I like to solve maths problems.\n\nmessages:\n- role: \"user\"\n  content: \"What is 2+2?\"\n- role: assistant\n  content: 2 + 2 = 4\n---\nsystem_prompt: |-\n  I like to solve maths problems.\n\nmessages:\n- role: \"user\"\n  content: \"What is 6 divided by 2?\"\n- role: assistant\n  content: 6 / 2 = 3\n```\n\nThe CLI will replay each conversation with the new system prompt.\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/already_answered_multiple.yml \\\n    --prompt \"I like cats. Answer any questions using cats.\"\n```\n\nThe output shows each system prompt has been updated and the `assistant`'s response has been re-generated using the new system prompt:\n\n```yaml\n---\nsystem_prompt: I like cats. Answer any questions using cats.\nllm:\n  provider: groq\n  model: llama3-70b-8192\nmessages:\n- role: user\n  content: What is 2+2?\n- role: assistant\n  content: That's an easy one! You know how many paws a typical cat has? That's right,\n    4! And if I were to divide those paws into two groups of two, I'd have... 2+2\n    = 4!\n---\nsystem_prompt: I like cats. Answer any questions using cats.\nllm:\n  provider: groq\n  model: llama3-70b-8192\nmessages:\n- role: user\n  content: What is 6 divided by 2?\n- role: assistant\n  content: That's an easy one! Imagine you have 6 adorable kittens, and you want to\n    divide them evenly between two cat beds. How many kittens would you put in each\n    bed? That's right, 3! So, 6 divided by 2 is 3.\n```\n\nThe 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.\n\nAlternately, you can pass `--conversation` option multiple times to process multiple conversation files.\n\n```plain\nbundle exec be exe/promptcraft \\\n    --conversation examples/maths/start/already_answered.yml \\\n    --conversation examples/maths/start/already_answered_gpt4.yml \\\n    --prompt \"Answer like a pirate. A maths pirate.\"\n```\n\nWhen 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:\n\n```plain\necho \"---\\nWhat is 2+2?\\n---\\nWhat is 6 divided by 2?\" | \\\n  promptcraft --prompt \"I solve maths using pizza metaphors.\"\n```\n\nThe 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:\n\n```yaml\n---\nsystem_prompt: I solve maths using pizza metaphors.\nllm:\n  provider: groq\n  model: llama3-70b-8192\nmessages:\n- role: user\n  content: What is 2+2?\n- role: assistant\n  content: |-\n    You want to know the answer to 2+2? Well, let me slice it up for you!\n\n    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?\n\n    That's right! You have a total of 4 slices of pizza! So, 2+2 is equal to... (drumroll please)... 4!\n---\nsystem_prompt: I solve maths using pizza metaphors.\nllm:\n  provider: groq\n  model: llama3-70b-8192\nmessages:\n- role: user\n  content: What is 6 divided by 2?\n- role: assistant\n  content: |-\n    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?\n\n    That's right! Each friend will get 3 slices of pizza! So, 6 divided by 2 is... 3!\n```\n\nYou'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:\n\n* `--provider groq --model llama3-70b-8192` (using `$GRQ_API_KEY`)\n* `--provider openai --model chatgpt-4-turbo` (using `$OPENAI_API_KEY`)\n* `--provider openrouter --model meta-llama/llama-3-8b-instruct:free` (using `$OPENROUTER_API_KEY`)\n* `--provider ollama --model llama3` (running on `http://localhost:11434`)\n\nOf course, you could pass each plain text user message using the `--conversation` argument too:\n\n```plain\npromptcraft \\\n    --conversation \"What is 2+2?\"\n    --conversation \"What is 6 divided by 2?\" \\\n    --prompt \"I solve maths using pizza metaphors.\"\n```\n\nWhy 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.\n\n```plain\npromptcraft \\\n    --conversation \"What is 2+2?\" \\\n    --conversation \"What is 6 divided by 2?\" \\\n    --prompt \"I am happy person\". \\\n  \u003e tmp/maths-as-happy-person.yml\n\npromptcraft \\\n    --conversation tmp/maths-as-happy-person.yml \\\n    --prompt \"I solve maths using pizza metaphors.\" \\\n\u003e tmp/maths-with-pizza.yml\n\n# perhaps put big prompts in files\necho \"I am an excellent maths tutor.\n\nWhen I'm asked a maths question, I will first\nask a question in return to help the student.\" \u003e tmp/prompt-maths-tutor.txt\n\npromptcraft \\\n    --conversation tmp/maths-with-pizza.yml \\\n    --prompt tmp/prompt-maths-tutor.txt\n```\n\nNow you have the output conversations in separate files, each with the system prompt and LLM used to produce the assistant replies.\n\nCan 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.\n\n```plain\necho \"When you are asked to create a list you put each item in a YAML stream document like:\n\n---\nmessages:\n- role: \"user\"\n  content: ITEM GOES HERE\n\nWith each one separated new line. Say nothing else except producing YAML.\n\" \u003e tmp/prompt-list-20-hellos.txt\n\npromptcraft \\\n  -c \"Generate a list of 20 things a customer might say when they first ring into a hair salon phone service\" \\\n  -p tmp/prompt-list-20-hellos.txt \\\n  --format json \u003e tmp/hair-salon-20-hellos.json\n\ncat tmp/hair-salon-20-hellos.json | jq -r \".messages[1].content\" \\\n  \u003e tmp/hair-salon-20-0000.txt\n```\n\nThe 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.\n\n```plain\npromptcraft \\\n  -p \"I'm a hair salon phone service. I sell haircuts\" \\\n  -c tmp/hair-salon-20-0000.txt \\\n  \u003e tmp/hair-salon-20-replies-0001.yml\n```\n\nThe file `tmp/hair-salon-20-replies-0001.yml` now contains the system prompt and the 20 user messages and the AI assistant replies.\n\nIterate on your system prompt until you're happy with the responses.\n\n## See Also\n\nTools you might want to use in conjunction with `promptcraft`:\n\n* `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.\n\n    For example, to view the output of `promptcraft` and save it to a file at the same time:\n\n    ```plain\n    promptcraft ... | tee output.yml\n    ```\n* [`yq`](https://mikefarah.gitbook.io/yq/) is a lightweight and portable command-line YAML processor. It's useful for extracting and modifying YAML files.\n\n    For example, to extract the 2nd message from a conversation:\n\n    ```plain\n    cat conversation.yml | yq .messages.1.content\n    ```\n\n* [`xq`](https://github.com/sibprogrammer/xq) is a lightweight and flexible command-line XML processor. It's useful for extracting and modifying XML files.\n\n    If the message content contains some XML, e.g. `\u003cusers_json\u003e{...}\u003c/users_json\u003e`, and you want the contents:\n\n    ```plain\n    cat conversation.yml | yq .messages.1.content | xq -x //users_json\n    ```\n\n* [`jq`](https://stedolan.github.io/jq/) is a lightweight and flexible command-line JSON processor. It's useful for extracting and modifying JSON files.\n\n## Installation\n\nRight now, you can either install with:\n\n* Homebrew\n* Or, you need to run the CLI from the source code\n\nWhilst this is a RubyGem, it currently requires some Git branches that are not yet released. The Homebrew recipe takes a big tarball of all source code and dependencies and installs it. The tarball is also available via [Github Releases](https://github.com/drnic/promptcraft/releases).\n\nOnce the Git branches are released, then the `promptcraft` gem will also be installable via RubyGems.\n\nIt requires Ruby 3.3 or later. Mostly because I like the new syntax features.\n\n### Homebrew\n\nThe project is currently distributed by the Homebrew tap [`drnic/ai`](https://github.com/drnic/homebrew-ai).\n\n```plain\nbrew tap drnic/ai\nbrew install promptcraft\n```\n\n### Run from Source\n\n```plain\ngit clone https://github.com/drnic/promptcraft\ncd promptcraft\nbin/setup\nbundle exec exe/promptcraft \\\n    --conversation examples/maths/start/already_answered.yml \\\n    --prompt \"I'm terrible at maths. If I'm asked a maths question, I reply with a question.\" \\\n    --provider groq\n```\n\n### Configuration\n\nThe `promptcraft` CLI defaults to `--provider groq --model llama3-70b-8192` and assumes you have `$GROQ_API_KEY` set in your environment.\n\nYou 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.\n\nYou 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.\n\nYou 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.\n\nIf the conversation file has an `llm` key with `provider` and `model` keys, then those will be used instead of the defaults.\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/already_answered_gpt4.yml \\\n    --prompt \"I always reply with a question\"\n\n---\nsystem_prompt: I always reply with a question.\nllm:\n  provider: openai\n  model: gpt-4-turbo\nmessages:\n- role: user\n  content: What is 2+2?\n- role: assistant\n  content: What do you think the answer is?\n```\n\n## Examples\n\nThe 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.\n\n### Getting started\n\nRun `promptcraft` with no arguments to get a default prompt and an initial assistant message.\n\n```plain\npromptcraft\n```\n\nThe output might be:\n\n```yaml\n---\nsystem_prompt: You are helpful. If you're first, then ask a question. You like brevity.\nmessages:\n- role: assistant\n  content: What do you need help with?\n```\n\nProvide a different provider, such as `openai` (which assumes you have `$OPENAI_API_KEY` set in your environment).\n\n```plain\npromptcraft --provider openai\n```\n\nOr you could provide your own system prompt, and it will generate an initial assistant message.\n\n```plaim\npromptcraft --prompt \"I like to solve maths problems.\"\n```\n\nThe output might be:\n\n```yaml\n---\nsystem_prompt: I like to solve maths problems.\nmessages:\n- role: assistant\n  content: |-\n    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:\n\n    1. Basic algebra (e.g., linear equations, quadratic equations)\n    2. Geometry (e.g., points, lines, triangles, circles)\n    3. Calculus (e.g., limits, derivatives, integrals)\n    4. Number theory (e.g., prime numbers, modular arithmetic)\n    5. Something else (please specify)\n\n    Let me know, and I'll provide you with a problem to solve!\n```\n\n### Providing conversations to rechat\n\nThe 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:\n\n* Pass one or more conversation files using `--conversation` or `-c` option.\n* Each conversation file can contain one or more YAML documents, each separated by `---`.\n* Pass in a stream of YAML documents via STDIN.\n* JSON is valid YAML, if that's ever useful to you.\n\nAn example of the `--conversation` option:\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/basic.yml\n```\n\nYou can also pipe a stream of conversation YAML into `promptcraft` via STDIN\n\n```plain\necho \"---\\nsystem_prompt: I like to solve maths problems.\\nmessages:\\n- role: \\\"user\\\"\\n  content: \\\"What is 2+2?\\\"\" | promptcraft\n```\n\nJSON is valid YAML, so you can also use JSON:\n\n```plain\necho \"{\\\"system_prompt\\\": \\\"I like to solve maths problems.\\\", \\\"messages\\\": [{\\\"role\\\": \\\"user\\\", \\\"content\\\": \\\"What is 2+2?\\\"}]}\" | promptcraft\n```\n\nOr pipe one or more files into `promptcraft`:\n\n```plain\n( cat examples/maths/start/basic.yml ; cat examples/maths/start/already_answered.yml ) | promptcraft\n```\n\nAs long as the input is a stream of YAML documents (separated by `---`), it will be processed.\n\n### Creating conversation files\n\nYou could manually create these YAML files. Sure.\n\nYou could get the scaffold for the file by running `promptcraft` with no arguments, and then copy/paste the output into a new file.\n\nAnother 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:\n\n![chatgpt-vision-to-yaml](docs/images/chatgpt-vision-to-yaml.png)\n\nThat's cool.\n\n### Missing assistant reply\n\nIf 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.\n\nFor example, this basic chat only contains the user's initial message:\n\n```yaml\nsystem_prompt: |-\n  I like to solve maths problems.\n\nmessages:\n- role: \"user\"\n  content: \"What is 2+2?\"\n```\n\nWhen we replay the conversation with the same system prompt (by omitting the `--prompt` option), it will add the missing assistant reply:\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/basic.yml\n```\n\nThe output might be:\n\n```yaml\n---\nsystem_prompt: I like to solve maths problems.\nllm:\n  provider: groq\n  model: llama3-70b-8192\nmessages:\n- role: user\n  content: What is 2+2?\n- role: assistant\n  content: That's an easy one! The answer is... 4!\n```\n\n### Set the temperature\n\nThe `--temperature` option controls the randomness of the assistant's responses. The default for each provider is typically `0.0`. Lower values will produce more deterministic responses, while higher values will produce more creative responses.\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/basic.yml \\\n    --temperature 0.5\n```\n\nThe output YAML for each conversation will store the `temperature` value used in the `llm:` section:\n\n```yaml\n---\nsystem_prompt: I like to solve maths problems.\nllm:\n  provider: groq\n  model: llama3-70b-8192\n  temperature: 0.5\nmessages:\n- role: user\n  content: What is 2+2?\n- role: assistant\n  content: That's an easy one! The answer is... 4!\n```\n\n### Limericks\n\nHere are some previously [generated limericks](examples/maths/start/many_limericks.yml). To regenerate them to start with letter \"E\" on each line:\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/many_limericks.yml \\\n    --prompt \"I am excellent at limericks. I always start each line with the letter E.\"\n```\n\nIt might still include some preamble in each response. To try to encourage the LLM to remove it:\n\n```plain\npromptcraft \\\n    --conversation examples/maths/start/many_limericks.yml \\\n    --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.\"\n```\n\n## Development\n\nAfter 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.\n\nTo 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).\n\n## Releases\n\nTo set new version number:\n\n```plain\ngem install gem-release\ngem bump --version [patch|minor|major]\nbundle install\ngit add Gemfile.lock; git commit --amend --no-edit\ngit push\n```\n\nTo tag and release Rubygem to \u003cRubygems.org\u003e:\n\n```plain\nrake release\n```\n\nTo update Homebrew formula:\n\n```plain\nrake release:build_package\nrake release:upload_package\nrake release:generate_homebrew_formula\n```\n\nNow copy `tmp/promptcraft.rb` formula into \u003chttps://github.com/drnic/homebrew-ai\u003e and push.\n\n```plain\ngit clone https://github.com/drnic/homebrew-ai tmp/homebrew-ai\ncp tmp/promptcraft.rb tmp/homebrew-ai\n( cd tmp/homebrew-ai; git add .; gca -m \"Bump promptcraft\"; git push )\nrm -rf tmp/homebrew-ai\n```\n\n## Contributing\n\nBug 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).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone 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).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrnic%2Fpromptcraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrnic%2Fpromptcraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrnic%2Fpromptcraft/lists"}