|
| 1 | +# Contributing to PromptCache |
| 2 | + |
| 3 | +Thank you for your interest in contributing to PromptCache! This guide will help you get started. |
| 4 | + |
| 5 | +## Code of Conduct |
| 6 | + |
| 7 | +- Be respectful and inclusive |
| 8 | +- Focus on constructive feedback |
| 9 | +- Help others learn and grow |
| 10 | + |
| 11 | +## How to Contribute |
| 12 | + |
| 13 | +### Reporting Bugs |
| 14 | + |
| 15 | +Before creating a bug report: |
| 16 | +1. Check existing issues to avoid duplicates |
| 17 | +2. Use the latest version to verify the bug still exists |
| 18 | + |
| 19 | +Include in your bug report: |
| 20 | +- Clear description of the issue |
| 21 | +- Steps to reproduce |
| 22 | +- Expected vs actual behavior |
| 23 | +- Environment details (OS, Go version, provider used) |
| 24 | +- Relevant logs or error messages |
| 25 | + |
| 26 | +### Suggesting Features |
| 27 | + |
| 28 | +Feature requests are welcome! Please: |
| 29 | +1. Check existing issues/roadmap first |
| 30 | +2. Clearly describe the use case |
| 31 | +3. Explain why it benefits the project |
| 32 | +4. Be open to discussion and feedback |
| 33 | + |
| 34 | +### Pull Requests |
| 35 | + |
| 36 | +#### Before You Start |
| 37 | + |
| 38 | +1. **Fork and clone** the repository |
| 39 | +2. **Create a branch** from `main`: |
| 40 | + ```bash |
| 41 | + git checkout -b feature/your-feature-name |
| 42 | + ``` |
| 43 | + |
| 44 | +#### Development Setup |
| 45 | + |
| 46 | +```bash |
| 47 | +# Install dependencies |
| 48 | +go mod download |
| 49 | + |
| 50 | +# Run tests |
| 51 | +make test |
| 52 | + |
| 53 | +# Run with your changes |
| 54 | +make run |
| 55 | +``` |
| 56 | + |
| 57 | +#### Making Changes |
| 58 | + |
| 59 | +1. **Write clear, idiomatic Go code** |
| 60 | + - Follow Go conventions and best practices |
| 61 | + - Keep functions small and focused |
| 62 | + - Use meaningful variable names |
| 63 | + |
| 64 | +2. **Add tests for new features** |
| 65 | + ```bash |
| 66 | + # Run tests |
| 67 | + go test ./... |
| 68 | + |
| 69 | + # Run specific package tests |
| 70 | + go test ./internal/semantic/ |
| 71 | + |
| 72 | + # Run with coverage |
| 73 | + go test -cover ./... |
| 74 | + ``` |
| 75 | + |
| 76 | +3. **Update documentation** |
| 77 | + - Update README.md if needed |
| 78 | + - Add/update code comments |
| 79 | + - Update docs/ if user-facing changes |
| 80 | + |
| 81 | +4. **Run benchmarks** (for performance-related changes) |
| 82 | + ```bash |
| 83 | + make benchmark |
| 84 | + ``` |
| 85 | + |
| 86 | +#### Code Style |
| 87 | + |
| 88 | +- Use `gofmt` to format your code |
| 89 | +- Run `go vet` to catch common issues |
| 90 | +- Keep lines under 120 characters when reasonable |
| 91 | +- Write clear commit messages |
| 92 | + |
| 93 | +#### Commit Messages |
| 94 | + |
| 95 | +Follow conventional commits format: |
| 96 | + |
| 97 | +``` |
| 98 | +type(scope): brief description |
| 99 | +
|
| 100 | +Longer explanation if needed. |
| 101 | +
|
| 102 | +Fixes #123 |
| 103 | +``` |
| 104 | + |
| 105 | +Types: |
| 106 | +- `feat`: New feature |
| 107 | +- `fix`: Bug fix |
| 108 | +- `docs`: Documentation changes |
| 109 | +- `test`: Test additions/changes |
| 110 | +- `refactor`: Code refactoring |
| 111 | +- `perf`: Performance improvements |
| 112 | +- `chore`: Maintenance tasks |
| 113 | + |
| 114 | +Examples: |
| 115 | +``` |
| 116 | +feat(semantic): add support for Gemini provider |
| 117 | +fix(cache): resolve race condition in concurrent access |
| 118 | +docs(api): update provider configuration examples |
| 119 | +test(semantic): add benchmark for FindSimilar |
| 120 | +``` |
| 121 | + |
| 122 | +#### Submitting Your PR |
| 123 | + |
| 124 | +1. **Push your branch** to your fork |
| 125 | +2. **Create a pull request** against `main` |
| 126 | +3. **Fill out the PR template** completely |
| 127 | +4. **Link related issues** using "Fixes #123" or "Relates to #456" |
| 128 | + |
| 129 | +Your PR should: |
| 130 | +- Pass all tests |
| 131 | +- Include tests for new functionality |
| 132 | +- Update relevant documentation |
| 133 | +- Have a clear description of changes |
| 134 | +- Address reviewer feedback promptly |
| 135 | + |
| 136 | +## Development Guidelines |
| 137 | + |
| 138 | +### Project Structure |
| 139 | + |
| 140 | +``` |
| 141 | +prompt-cache/ |
| 142 | +├── cmd/api/ # Main application entry point |
| 143 | +├── internal/ |
| 144 | +│ ├── cache/ # Cache logic |
| 145 | +│ ├── semantic/ # Semantic similarity & providers |
| 146 | +│ └── storage/ # Storage backends |
| 147 | +├── docs/ # Documentation |
| 148 | +└── scripts/ # Utility scripts |
| 149 | +``` |
| 150 | + |
| 151 | +### Adding a New Provider |
| 152 | + |
| 153 | +To add a new embedding/LLM provider: |
| 154 | + |
| 155 | +1. **Create provider file** in `internal/semantic/`: |
| 156 | + ```go |
| 157 | + // newprovider_provider.go |
| 158 | + package semantic |
| 159 | + |
| 160 | + type NewProviderProvider struct { |
| 161 | + apiKey string |
| 162 | + } |
| 163 | + |
| 164 | + func (p *NewProviderProvider) Embed(text string) ([]float64, error) { |
| 165 | + // Implementation |
| 166 | + } |
| 167 | + |
| 168 | + func (p *NewProviderProvider) CheckSimilarity(prompt1, prompt2 string) (bool, error) { |
| 169 | + // Implementation |
| 170 | + } |
| 171 | + ``` |
| 172 | + |
| 173 | +2. **Update provider factory** in `semantic.go`: |
| 174 | + ```go |
| 175 | + case "newprovider": |
| 176 | + return &NewProviderProvider{apiKey: apiKey}, nil |
| 177 | + ``` |
| 178 | + |
| 179 | +3. **Add tests** in `provider_test.go` |
| 180 | + |
| 181 | +4. **Update documentation**: |
| 182 | + - docs/providers.md |
| 183 | + - README.md |
| 184 | + - docker-compose.yml |
| 185 | + |
| 186 | +### Testing Guidelines |
| 187 | + |
| 188 | +- Write unit tests for all new functions |
| 189 | +- Use table-driven tests for multiple scenarios |
| 190 | +- Mock external API calls in tests |
| 191 | +- Aim for >80% code coverage |
| 192 | +- Test edge cases and error conditions |
| 193 | + |
| 194 | +Example test structure: |
| 195 | +```go |
| 196 | +func TestNewFeature(t *testing.T) { |
| 197 | + tests := []struct { |
| 198 | + name string |
| 199 | + input string |
| 200 | + want string |
| 201 | + wantErr bool |
| 202 | + }{ |
| 203 | + {"valid input", "test", "expected", false}, |
| 204 | + {"invalid input", "", "", true}, |
| 205 | + } |
| 206 | + |
| 207 | + for _, tt := range tests { |
| 208 | + t.Run(tt.name, func(t *testing.T) { |
| 209 | + got, err := NewFeature(tt.input) |
| 210 | + if (err != nil) != tt.wantErr { |
| 211 | + t.Errorf("NewFeature() error = %v, wantErr %v", err, tt.wantErr) |
| 212 | + return |
| 213 | + } |
| 214 | + if got != tt.want { |
| 215 | + t.Errorf("NewFeature() = %v, want %v", got, tt.want) |
| 216 | + } |
| 217 | + }) |
| 218 | + } |
| 219 | +} |
| 220 | +``` |
| 221 | + |
| 222 | +### Performance Considerations |
| 223 | + |
| 224 | +- Benchmark performance-critical code |
| 225 | +- Avoid unnecessary allocations |
| 226 | +- Use proper concurrency patterns |
| 227 | +- Consider cache implications |
| 228 | +- Profile before optimizing |
| 229 | + |
| 230 | +## Documentation |
| 231 | + |
| 232 | +### Updating Docs |
| 233 | + |
| 234 | +Documentation lives in `docs/` directory: |
| 235 | + |
| 236 | +```bash |
| 237 | +# Test docs locally |
| 238 | +cd docs |
| 239 | +bundle install |
| 240 | +bundle exec jekyll serve |
| 241 | + |
| 242 | +# Visit http://localhost:4000/prompt-cache |
| 243 | +``` |
| 244 | + |
| 245 | +### Documentation Style |
| 246 | + |
| 247 | +- Use clear, concise language |
| 248 | +- Include code examples |
| 249 | +- Add comments for complex logic |
| 250 | +- Keep README.md up to date |
| 251 | +- Update CHANGELOG.md for releases |
| 252 | + |
| 253 | +## Release Process |
| 254 | + |
| 255 | +Maintainers handle releases, but contributors should: |
| 256 | + |
| 257 | +1. Update CHANGELOG.md with changes |
| 258 | +2. Update version numbers if applicable |
| 259 | +3. Ensure all tests pass |
| 260 | +4. Update documentation |
| 261 | + |
| 262 | +## Getting Help |
| 263 | + |
| 264 | +- **Questions?** Open a discussion or issue |
| 265 | +- **Stuck?** Ask for help in your PR |
| 266 | +- **Ideas?** We love to hear them! |
| 267 | + |
| 268 | +## License |
| 269 | + |
| 270 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
| 271 | + |
| 272 | +## Thank You! |
| 273 | + |
| 274 | +Every contribution helps make PromptCache better. We appreciate your time and effort! 🚀 |
0 commit comments