Skip to content

Commit 178d921

Browse files
committed
Refactor PromptPexOptions and related logic by changing pointer fields to values; update ApplyEffortConfiguration and tests for consistency
1 parent 0615664 commit 178d921

9 files changed

Lines changed: 37 additions & 42 deletions

File tree

cmd/generate/effort.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ func ApplyEffortConfiguration(options *PromptPexOptions, effort string) {
5050
}
5151

5252
// Apply configuration settings only if not already set
53-
if config.TestsPerRule != nil && options.TestsPerRule == nil {
54-
options.TestsPerRule = config.TestsPerRule
53+
if config.TestsPerRule != nil && options.TestsPerRule == 0 {
54+
options.TestsPerRule = *config.TestsPerRule
5555
}
56-
if config.RunsPerTest != nil && options.RunsPerTest == nil {
57-
options.RunsPerTest = config.RunsPerTest
56+
if config.RunsPerTest != nil && options.RunsPerTest == 0 {
57+
options.RunsPerTest = *config.RunsPerTest
5858
}
59-
if config.MaxRules != nil && options.MaxRules == nil {
60-
options.MaxRules = config.MaxRules
59+
if config.MaxRules != nil && options.MaxRules == 0 {
60+
options.MaxRules = *config.MaxRules
6161
}
62-
if config.MaxRulesPerTestGeneration != nil && options.MaxRulesPerTestGen == nil {
63-
options.MaxRulesPerTestGen = config.MaxRulesPerTestGeneration
62+
if config.MaxRulesPerTestGeneration != nil && options.MaxRulesPerTestGen == 0 {
63+
options.MaxRulesPerTestGen = *config.MaxRulesPerTestGeneration
6464
}
6565
}

cmd/generate/generate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ func ParseFlags(cmd *cobra.Command, options *PromptPexOptions) error {
112112
flags := cmd.Flags()
113113
// Parse effort first so it can set defaults
114114
if effort, _ := flags.GetString("effort"); effort != "" {
115-
options.Effort = &effort
115+
options.Effort = effort
116116
}
117117

118118
// Apply effort configuration
119-
if options.Effort != nil {
120-
ApplyEffortConfiguration(options, *options.Effort)
119+
if options.Effort != "" {
120+
ApplyEffortConfiguration(options, options.Effort)
121121
}
122122

123123
if groundtruthModel, _ := flags.GetString("groundtruth-model"); groundtruthModel != "" {

cmd/generate/generate_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@ func TestParseFlags(t *testing.T) {
6363
name: "default options preserve initial state",
6464
args: []string{},
6565
validate: func(t *testing.T, opts *PromptPexOptions) {
66-
require.Equal(t, 3, *opts.TestsPerRule)
67-
require.Equal(t, 2, *opts.RunsPerTest)
66+
require.Equal(t, 3, opts.TestsPerRule)
67+
require.Equal(t, 2, opts.RunsPerTest)
6868
},
6969
},
7070
{
7171
name: "effort flag is set",
7272
args: []string{"--effort", "medium"},
7373
validate: func(t *testing.T, opts *PromptPexOptions) {
74-
require.NotNil(t, opts.Effort)
75-
require.Equal(t, "medium", *opts.Effort)
74+
require.Equal(t, "medium", opts.Effort)
7675
},
7776
},
7877
{

cmd/generate/options.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package generate
22

3-
import "github.com/github/gh-models/pkg/util"
4-
53
// GetDefaultOptions returns default options for PromptPex
64
func GetDefaultOptions() *PromptPexOptions {
75
return &PromptPexOptions{
8-
TestsPerRule: util.Ptr(3),
9-
RunsPerTest: util.Ptr(2),
10-
MaxRulesPerTestGen: util.Ptr(3),
11-
Verbose: util.Ptr(false),
6+
TestsPerRule: 3,
7+
RunsPerTest: 2,
8+
MaxRulesPerTestGen: 3,
9+
Verbose: false,
1210
Models: &PromptPexModelAliases{
1311
Rules: "openai/gpt-4o",
1412
Tests: "openai/gpt-4o",

cmd/generate/options_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package generate
33
import (
44
"reflect"
55
"testing"
6-
7-
"github.com/github/gh-models/pkg/util"
86
)
97

108
func TestGetDefaultOptions(t *testing.T) {
@@ -16,9 +14,9 @@ func TestGetDefaultOptions(t *testing.T) {
1614
actual interface{}
1715
expected interface{}
1816
}{
19-
{"TestsPerRule", defaults.TestsPerRule, util.Ptr(3)},
20-
{"RunsPerTest", defaults.RunsPerTest, util.Ptr(2)},
21-
{"MaxRulesPerTestGen", defaults.MaxRulesPerTestGen, util.Ptr(3)},
17+
{"TestsPerRule", defaults.TestsPerRule, 3},
18+
{"RunsPerTest", defaults.RunsPerTest, 2},
19+
{"MaxRulesPerTestGen", defaults.MaxRulesPerTestGen, 3},
2220
}
2321

2422
for _, tt := range tests {

cmd/generate/pipeline.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ Inverse Output Rules:`, strings.Join(context.Rules, "\n"))
234234

235235
// generateTests generates test cases for the prompt
236236
func (h *generateCommandHandler) generateTests(context *PromptPexContext) error {
237-
h.WriteStartBox("Tests", fmt.Sprintf("%d rules x %d tests per rule", len(context.Rules)+len(context.InverseRules), *h.options.TestsPerRule))
237+
h.WriteStartBox("Tests", fmt.Sprintf("%d rules x %d tests per rule", len(context.Rules)+len(context.InverseRules), h.options.TestsPerRule))
238238
if len(context.Tests) == 0 {
239239
testsPerRule := 3
240-
if h.options.TestsPerRule != nil {
241-
testsPerRule = *h.options.TestsPerRule
240+
if h.options.TestsPerRule != 0 {
241+
testsPerRule = h.options.TestsPerRule
242242
}
243243

244244
allRules := append(context.Rules, context.InverseRules...)

cmd/generate/render.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (h *generateCommandHandler) WriteEndListBox(items []string, maxItems int) {
105105

106106
// logLLMPayload logs the LLM request and response if verbose mode is enabled
107107
func (h *generateCommandHandler) LogLLMResponse(response string) {
108-
if h.options.Verbose != nil && *h.options.Verbose {
108+
if h.options.Verbose {
109109
h.WriteStartBox("🏁", "")
110110
h.cfg.WriteToOut(response)
111111
if !strings.HasSuffix(response, "\n") {
@@ -116,7 +116,7 @@ func (h *generateCommandHandler) LogLLMResponse(response string) {
116116
}
117117

118118
func (h *generateCommandHandler) LogLLMRequest(step string, options azuremodels.ChatCompletionOptions) {
119-
if h.options.Verbose != nil && *h.options.Verbose {
119+
if h.options.Verbose {
120120
h.WriteStartBox(fmt.Sprintf("💬 %s", step), options.Model)
121121
for _, msg := range options.Messages {
122122
content := ""

cmd/generate/types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ type PromptPexOptions struct {
2222
// Core options
2323
Instructions *PromptPexPrompts `yaml:"instructions,omitempty" json:"instructions,omitempty"`
2424
Models *PromptPexModelAliases `yaml:"models,omitempty" json:"models,omitempty"`
25-
TestsPerRule *int `yaml:"testsPerRule,omitempty" json:"testsPerRule,omitempty"`
26-
RunsPerTest *int `yaml:"runsPerTest,omitempty" json:"runsPerTest,omitempty"`
27-
MaxRules *int `yaml:"maxRules,omitempty" json:"maxRules,omitempty"`
28-
MaxRulesPerTestGen *int `yaml:"maxRulesPerTestGeneration,omitempty" json:"maxRulesPerTestGeneration,omitempty"`
25+
TestsPerRule int `yaml:"testsPerRule,omitempty" json:"testsPerRule,omitempty"`
26+
RunsPerTest int `yaml:"runsPerTest,omitempty" json:"runsPerTest,omitempty"`
27+
MaxRules int `yaml:"maxRules,omitempty" json:"maxRules,omitempty"`
28+
MaxRulesPerTestGen int `yaml:"maxRulesPerTestGeneration,omitempty" json:"maxRulesPerTestGeneration,omitempty"`
2929

3030
// CLI-specific options
31-
Effort *string `yaml:"effort,omitempty" json:"effort,omitempty"`
32-
Prompt *string `yaml:"prompt,omitempty" json:"prompt,omitempty"`
31+
Effort string `yaml:"effort,omitempty" json:"effort,omitempty"`
32+
Prompt string `yaml:"prompt,omitempty" json:"prompt,omitempty"`
3333

3434
// Loader options
35-
Verbose *bool `yaml:"verbose,omitempty" json:"verbose,omitempty"`
35+
Verbose bool `yaml:"verbose,omitempty" json:"verbose,omitempty"`
3636
}
3737

3838
// PromptPexContext represents the main context for PromptPex operations

pkg/prompt/prompt.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type File struct {
1616
Name string `yaml:"name"`
1717
Description string `yaml:"description"`
1818
Model string `yaml:"model"`
19-
ModelParameters ModelParameters `yaml:"modelParameters"`
19+
ModelParameters ModelParameters `yaml:"modelParameters,omitempty"`
2020
ResponseFormat *string `yaml:"responseFormat,omitempty"`
2121
JsonSchema *JsonSchema `yaml:"jsonSchema,omitempty"`
2222
Messages []Message `yaml:"messages"`
@@ -27,9 +27,9 @@ type File struct {
2727

2828
// ModelParameters represents model configuration parameters
2929
type ModelParameters struct {
30-
MaxTokens *int `yaml:"maxTokens"`
31-
Temperature *float64 `yaml:"temperature"`
32-
TopP *float64 `yaml:"topP"`
30+
MaxTokens *int `yaml:"maxTokens,omitempty"`
31+
Temperature *float64 `yaml:"temperature,omitempty"`
32+
TopP *float64 `yaml:"topP,omitempty"`
3333
}
3434

3535
// Message represents a conversation message

0 commit comments

Comments
 (0)