Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

use identifiers for --ask mode question keys

Jonathan Bergf94778a7fe66
diff --git a/cmd/decide.go b/cmd/decide.go
index 37ba126d2..95bd06cd2 100644
--- a/cmd/decide.go
+++ b/cmd/decide.go
@@ -41,12 +41,12 @@ func runDecision(cmd *cobra.Command, opts runOptions, interactive bool) error {
return decide(cmd, opts, input, opts.Questions)
}
-// yesNoQuestions asks each text as a yes/no question keyed by the text itself.
+// yesNoQuestions asks each text as a yes/no question.
func yesNoQuestions(texts ...string) *api.SystemOneQuestions {
questions := &api.SystemOneQuestions{}
- for _, text := range texts {
+ for i, text := range texts {
instructions, _ := json.Marshal(text)
- questions.Set(text, api.SystemOneQuestion{Type: "noul", Instructions: instructions})
+ questions.Set(fmt.Sprintf("q%d", i+1), api.SystemOneQuestion{Type: "noul", Instructions: instructions})
}
return questions
}
@@ -95,7 +95,7 @@ func (f questionFlag) Set(value string) error {
return nil
}
-// askedQuestions returns the --ask questions keyed by their text: yes/no, or
+// askedQuestions returns the --ask questions: yes/no, or
// answered with a --choice label or on a --level scale.
func askedQuestions(cmd *cobra.Command) *api.SystemOneQuestions {
questions := &api.SystemOneQuestions{}
@@ -103,7 +103,7 @@ func askedQuestions(cmd *cobra.Command) *api.SystemOneQuestions {
if flag == nil {
return questions
}
- for _, q := range *flag.Value.(questionFlag).asked {
+ for i, q := range *flag.Value.(questionFlag).asked {
question := api.SystemOneQuestion{Type: "noul"}
question.Instructions, _ = json.Marshal(q.text)
switch {
@@ -114,7 +114,7 @@ func askedQuestions(cmd *cobra.Command) *api.SystemOneQuestions {
question.Type = "score"
question.Criteria, _ = json.Marshal(q.levels)
}
- questions.Set(q.text, question)
+ questions.Set(fmt.Sprintf("q%d", i+1), question)
}
return questions
}
@@ -165,10 +165,12 @@ func decide(cmd *cobra.Command, opts runOptions, input api.Message, questions *a
}
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
- for name := range questions.All() {
+ for name, q := range questions.All() {
+ var text string
+ _ = json.Unmarshal(q.Instructions, &text)
raw, ok := resp.Answers.Get(name)
if !ok {
- return fmt.Errorf("no answer to %q", name)
+ return fmt.Errorf("no answer to %q", text)
}
var a struct {
Type string `json:"type"`
@@ -179,7 +181,7 @@ func decide(cmd *cobra.Command, opts runOptions, input api.Message, questions *a
Probabilities map[string]float64 `json:"probabilities"`
}
if err := json.Unmarshal(raw, &a); err != nil {
- return fmt.Errorf("answer to %q: %w", name, err)
+ return fmt.Errorf("answer to %q: %w", text, err)
}
var answer, measure string
switch a.Type {
@@ -204,10 +206,10 @@ func decide(cmd *cobra.Command, opts runOptions, input api.Message, questions *a
}
measure = fmt.Sprintf("%.0f%%\t%.1f / %d", a.Probabilities[level]*100, a.Score, len(a.Legend)-1)
default:
- return fmt.Errorf("answer to %q has unknown type %q", name, a.Type)
+ return fmt.Errorf("answer to %q has unknown type %q", text, a.Type)
}
if questions.Len() > 1 {
- fmt.Fprintf(tw, "%s\t", name)
+ fmt.Fprintf(tw, "%s\t", text)
}
fmt.Fprintf(tw, "%s\t%s\n", answer, measure)
}
diff --git a/cmd/decide_test.go b/cmd/decide_test.go
index 938a142e7..81f0a5432 100644
--- a/cmd/decide_test.go
+++ b/cmd/decide_test.go
@@ -61,7 +61,7 @@ func runDecide(t *testing.T, stdin string, handler http.HandlerFunc, args ...str
}
func TestRunDecisionModel(t *testing.T) {
- const refund = `{"Is a refund being requested?":{"type":"noul","instructions":"Is a refund being requested?"}}`
+ const refund = `{"q1":{"type":"noul","instructions":"Is a refund being requested?"}}`
for _, tt := range []struct {
name, stdin string
args []string
@@ -75,14 +75,14 @@ func TestRunDecisionModel(t *testing.T) {
stdin: "I was charged twice\n",
args: []string{"--ask", "Is a refund being requested?"},
questions: refund,
- answers: `{"Is a refund being requested?":{"type":"noul","noul":0.97}}`,
+ answers: `{"q1":{"type":"noul","noul":0.97}}`,
want: "yes 97%\n",
},
{
name: "state as an argument",
args: []string{"I was charged twice", "--ask", "Is a refund being requested?"},
questions: refund,
- answers: `{"Is a refund being requested?":{"type":"noul","noul":0.2}}`,
+ answers: `{"q1":{"type":"noul","noul":0.2}}`,
want: "no 80%\n",
},
{
@@ -90,31 +90,31 @@ func TestRunDecisionModel(t *testing.T) {
args: []string{"--ask", "Is a refund being requested?", `{"ticket": "I was charged twice"}`},
state: `{"ticket":"I was charged twice"}`,
questions: refund,
- answers: `{"Is a refund being requested?":{"type":"noul","noul":0.97}}`,
+ answers: `{"q1":{"type":"noul","noul":0.97}}`,
want: "yes 97%\n",
},
{
name: "labels",
stdin: "I was charged twice",
args: []string{"--ask", "Which team should handle this?", "--choice", "billing=Payments and refunds", "--choice", "technical"},
- questions: `{"Which team should handle this?":{"type":"choice","instructions":"Which team should handle this?","criteria":{"billing":"Payments and refunds","technical":null}}}`,
- answers: `{"Which team should handle this?":{"type":"choice","choice":"billing","probabilities":{"billing":0.91,"technical":0.09},"confidence":0.6}}`,
+ questions: `{"q1":{"type":"choice","instructions":"Which team should handle this?","criteria":{"billing":"Payments and refunds","technical":null}}}`,
+ answers: `{"q1":{"type":"choice","choice":"billing","probabilities":{"billing":0.91,"technical":0.09},"confidence":0.6}}`,
want: "billing 91%\n",
},
{
name: "levels",
stdin: "I was charged twice",
args: []string{"--ask", "How urgent is this?", "--level", "Routine", "--level", "Soon", "--level", "Immediate"},
- questions: `{"How urgent is this?":{"type":"score","instructions":"How urgent is this?","criteria":["Routine","Soon","Immediate"]}}`,
- answers: `{"How urgent is this?":{"type":"score","score":1.83,"legend":{"0":"Routine","1":"Soon","2":"Immediate"},"probabilities":{"0":0.04,"1":0.09,"2":0.87},"confidence":0.7}}`,
+ questions: `{"q1":{"type":"score","instructions":"How urgent is this?","criteria":["Routine","Soon","Immediate"]}}`,
+ answers: `{"q1":{"type":"score","score":1.83,"legend":{"0":"Routine","1":"Soon","2":"Immediate"},"probabilities":{"0":0.04,"1":0.09,"2":0.87},"confidence":0.7}}`,
want: "Immediate 87% 1.8 / 2\n",
},
{
name: "most likely level, not the nearest",
stdin: "I was charged twice",
args: []string{"--ask", "How urgent is this?", "--level", "Routine", "--level", "Soon", "--level", "Immediate"},
- questions: `{"How urgent is this?":{"type":"score","instructions":"How urgent is this?","criteria":["Routine","Soon","Immediate"]}}`,
- answers: `{"How urgent is this?":{"type":"score","score":1.1,"legend":{"0":"Routine","1":"Soon","2":"Immediate"},"probabilities":{"0":0.45,"1":0,"2":0.55}}}`,
+ questions: `{"q1":{"type":"score","instructions":"How urgent is this?","criteria":["Routine","Soon","Immediate"]}}`,
+ answers: `{"q1":{"type":"score","score":1.1,"legend":{"0":"Routine","1":"Soon","2":"Immediate"},"probabilities":{"0":0.45,"1":0,"2":0.55}}}`,
want: "Immediate 55% 1.1 / 2\n",
},
{
@@ -125,8 +125,8 @@ func TestRunDecisionModel(t *testing.T) {
"--ask", "Which team?", "--choice", "billing", "--choice", "technical",
"--ask", "How urgent?", "--level", "routine", "--level", "soon", "--level", "immediate",
},
- questions: `{"Is a refund being requested?":{"type":"noul","instructions":"Is a refund being requested?"},"Which team?":{"type":"choice","instructions":"Which team?","criteria":{"billing":null,"technical":null}},"How urgent?":{"type":"score","instructions":"How urgent?","criteria":["routine","soon","immediate"]}}`,
- answers: `{"How urgent?":{"type":"score","score":1.2,"legend":{"0":"routine","1":"soon","2":"immediate"},"probabilities":{"0":0.1,"1":0.6,"2":0.3}},"Which team?":{"type":"choice","choice":"billing","probabilities":{"billing":0.91,"technical":0.09}},"Is a refund being requested?":{"type":"noul","noul":0.97}}`,
+ questions: `{"q1":{"type":"noul","instructions":"Is a refund being requested?"},"q2":{"type":"choice","instructions":"Which team?","criteria":{"billing":null,"technical":null}},"q3":{"type":"score","instructions":"How urgent?","criteria":["routine","soon","immediate"]}}`,
+ answers: `{"q3":{"type":"score","score":1.2,"legend":{"0":"routine","1":"soon","2":"immediate"},"probabilities":{"0":0.1,"1":0.6,"2":0.3}},"q2":{"type":"choice","choice":"billing","probabilities":{"billing":0.91,"technical":0.09}},"q1":{"type":"noul","noul":0.97}}`,
want: "Is a refund being requested? yes 97%\nWhich team? billing 91%\nHow urgent? soon 60% 1.2 / 2\n",
},
} {
@@ -158,7 +158,7 @@ func TestRunDecisionModel(t *testing.T) {
})
}
- const response = `{"model":"nimble","answers":{"Is this urgent?":{"type":"noul","noul":0.9}},"usage":{"input_tokens":12,"output_tokens":1}}`
+ const response = `{"model":"nimble","answers":{"q1":{"type":"noul","noul":0.9}},"usage":{"input_tokens":12,"output_tokens":1}}`
out, err := runDecide(t, "", func(w http.ResponseWriter, r *http.Request) {
_, _ = io.WriteString(w, response)
}, "nimble", "hello", "--ask", "Is this urgent?", "--format", "json")