Package com.tnsai.prompt.strategy
Class PromptEnhancer
java.lang.Object
com.tnsai.prompt.strategy.PromptEnhancer
Fluent builder for combining prompt enhancement strategies.
PromptEnhancer allows combining multiple prompting techniques to improve LLM response quality.
Usage
// Simple usage with single strategy
PromptEnhancer enhancer = PromptEnhancer.withStrategy(PromptStrategy.CHAIN_OF_THOUGHT);
EnhancedPrompt prompt = enhancer.enhance("Solve: 2x + 5 = 15");
// Builder with multiple strategies
PromptEnhancer enhancer = PromptEnhancer.builder()
.strategy(PromptStrategy.CHAIN_OF_THOUGHT)
.strategy(PromptStrategy.CONFIDENCE_WEIGHTED)
.role("Expert mathematician")
.objective("Solve algebra problems accurately")
.constraints(List.of("Show all work", "Verify answer"))
.outputFormat(OutputFormat.STRUCTURED)
.build();
EnhancedPrompt prompt = enhancer.enhance("What is 15% of 240?");
// Use with LLM client
ChatResponse response = client.chat(
prompt.getUserMessage(),
Optional.of(prompt.getSystemPrompt()),
Optional.empty(),
Optional.empty()
);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for PromptEnhancer.static final recordExample record for few-shot learning.static enumOutput format options. -
Method Summary
Modifier and TypeMethodDescriptionstatic PromptEnhancer.Builderbuilder()Creates a new builder.Enhances a user message with configured strategies.Gets the configured strategies.booleanReturns true if any strategy requires multiple LLM calls.static PromptEnhancerwithStrategy(PromptStrategy strategy) Creates an enhancer with a single strategy.
-
Method Details
-
withStrategy
Creates an enhancer with a single strategy. -
builder
Creates a new builder. -
enhance
Enhances a user message with configured strategies.- Parameters:
userMessage- The original user message- Returns:
- Enhanced prompt with system instructions
-
getStrategies
Gets the configured strategies. -
requiresMultiPass
public boolean requiresMultiPass()Returns true if any strategy requires multiple LLM calls.
-