Define prompt templates and reuse them
What would you like to be added?
I want to be able to define prompt template files (with placeholders) and be able to submit the prompt multiple times without having to re-write it.
Why is this needed?
For repetitive tasks like making a CRUD apis for multiple resources I can write a CRUD once then create a template prompt with example code and rules and reuse it again for all of the other resources.
Additional context
inside the .gemini/prompts folder we create a prompt file nest-crud.yaml which will look like this:
id: nest-crud
name: Generate a Nestjs CRUD api
variables:
- name: resource
description: Name of the resource (e.g Product, User)
template: |
Referencing @samples/sample.module.ts and @samples/sample.controller.ts and @samples/sample.service.ts, create a CRUD API for {{resource}} using NestJS. Ensure to define the necessary modules, controllers, and services to handle the CRUD operations effectively.
Ensure that the API follows NestJS best practices, including proper use of decorators, dependency injection, and error handling. Additionally, implement validation for incoming requests using class-validator and class-transformer packages to ensure data integrity and security.
Then in gemini cli I can select this predefined prompt and only fill the resource placeholder.
Note: I needed this feature for my use case, so I’ve gone ahead and implemented it.
I’d love to get your feedback and, if it aligns with the goals of the Gemini CLI, I’m happy to make any adjustments needed to get this merged into the main CLI.
You can check out a demo here:
https://github.com/user-attachments/assets/594094d1-97eb-4fac-b260-e1ebf6ca27ff
This is neat! Can't promise if we are at a place to take a PR for this, but if not a lot of effort, would be cool to take a look at it.
@keithballinger should I open a pr or wait for approval?
That's a great idea!
Found possible duplicate issues:
- #5023: (0.9083571434020996)
You can now use custom slash commands https://cloud.google.com/blog/topics/developers-practitioners/gemini-cli-custom-slash-commands