Class: RuboCop::Cop::Prompt::TemperatureRange
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Prompt::TemperatureRange
- Defined in:
- lib/rubocop/cop/prompt/temperature_range.rb
Overview
Checks that temperature values are appropriate for the task type.
This cop identifies code in classes, modules, or methods with “prompt” in their names and ensures that when temperature > 0.7, it’s not being used for precision tasks. High temperature values (> 0.7) should be avoided for tasks requiring accuracy, consistency, or factual correctness.
Constant Summary collapse
- MSG =
"High temperature (%.1f > 0.7) should not be used for precision tasks. " \ "Consider using temperature <= 0.7 for tasks requiring accuracy."
- TEMPERATURE_THRESHOLD =
Temperature threshold above which we check for precision tasks
0.7
- PRECISION_KEYWORDS =
Keywords that indicate precision/accuracy tasks
[ # Analysis and accuracy "accurate", "accuracy", "precise", "precision", "exact", "exactly", "analyze", "analysis", "calculate", "computation", "compute", "measure", "measurement", "count", "sum", "total", # Factual and data tasks "fact", "factual", "data", "information", "correct", "verify", "validate", "check", "review", "audit", "inspect", # Classification and categorization "classify", "classification", "categorize", "category", "sort", "organize", "structure", "parse", "extract", # Technical and code tasks "code", "programming", "syntax", "debug", "error", "fix", "technical", "documentation", "specification", "format" ].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubocop/cop/prompt/temperature_range.rb', line 69 def on_send(node) return unless in_prompt_context?(node) return unless chat_method?(node) temperature_value = extract_temperature(node) return unless temperature_value && temperature_value > TEMPERATURE_THRESHOLD = (node) return unless && precision_task?() add_offense( node, message: format(MSG, temperature_value) ) end |