Skip to content

Conversation

@Ardbiu
Copy link

@Ardbiu Ardbiu commented Oct 29, 2025

This PR introduces majority_k — a lightweight helper that wraps an existing DSPy predictor, runs it k times with identical inputs, and returns the majority result using the existing majority() function.

This helper reduces repetitive boilerplate when sampling multiple completions via the same predictor.

Details
• Supports both callable predictors and existing prediction/completion objects
• Does not modify core prediction logic
• For callable predictors, wraps and returns a callable
• For non-callable inputs, directly forwards to majority()

Tests
Added tests in tests/predict/test_majority_k.py:

  1. callable predictor → called k times
  2. passing existing completions → forwarded directly
  3. kwargs forwarded correctly

Implements feature requested in Issue #8988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant