Skip to content

Commit 2551f9d

Browse files
committed
Revert "Add JSON schema for strict message validation"
This reverts commit 5474788.
1 parent 6cb60a9 commit 2551f9d

File tree

2 files changed

+8
-41
lines changed

2 files changed

+8
-41
lines changed

cmd/aicommit/main.go

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"bytes"
5-
"encoding/json"
65
"errors"
76
"fmt"
87
"io"
@@ -137,35 +136,13 @@ func run(inv *serpent.Invocation, opts runOptions) error {
137136
IncludeUsage: true,
138137
},
139138
Messages: msgs,
140-
ResponseFormat: &openai.ChatCompletionResponseFormat{
141-
Type: openai.ChatCompletionResponseFormatTypeJSONSchema,
142-
JSONSchema: &openai.ChatCompletionResponseFormatJSONSchema{
143-
Name: "commit_message",
144-
Schema: json.RawMessage(`{
145-
"type": "object",
146-
"properties": {
147-
"thought_process": {
148-
"type": "string",
149-
"description": "A chain of thought explaining the reasoning behind the commit message"
150-
},
151-
"commit_message": {
152-
"type": "string",
153-
"description": "The final, concise commit message"
154-
}
155-
},
156-
"additionalProperties": false,
157-
"required": ["thought_process", "commit_message"]
158-
}`),
159-
Strict: true,
160-
},
161-
},
162139
})
163140
if err != nil {
164141
return err
165142
}
166143
defer stream.Close()
167144

168-
jsonMsg := &bytes.Buffer{}
145+
msg := &bytes.Buffer{}
169146

170147
// Sky blue color
171148
color := pretty.FgColor(colorProfile.Color("#2FA8FF"))
@@ -185,22 +162,14 @@ func run(inv *serpent.Invocation, opts runOptions) error {
185162
break
186163
}
187164
c := resp.Choices[0].Delta.Content
188-
jsonMsg.WriteString(c)
165+
msg.WriteString(c)
189166
pretty.Fprintf(inv.Stdout, color, "%s", c)
190167
}
191168
inv.Stdout.Write([]byte("\n"))
192169

193-
var parsedMsg struct {
194-
CommitMessage string `json:"commit_message"`
195-
}
196-
err = json.Unmarshal(jsonMsg.Bytes(), &parsedMsg)
197-
if err != nil {
198-
return err
199-
}
200-
201-
parsedMsg.CommitMessage = cleanAIMessage(parsedMsg.CommitMessage)
170+
msg = bytes.NewBufferString(cleanAIMessage(msg.String()))
202171

203-
cmd := exec.Command("git", "commit", "-m", parsedMsg.CommitMessage)
172+
cmd := exec.Command("git", "commit", "-m", msg.String())
204173
if opts.amend {
205174
cmd.Args = append(cmd.Args, "--amend")
206175
}
@@ -304,11 +273,9 @@ func main() {
304273
Description: "The model to use, e.g. gpt-4o or gpt-4o-mini.",
305274
Flag: "model",
306275
FlagShorthand: "m",
307-
// Needed for structured output.
308-
// Should update to gpt-4o once gpt-4o-2024-08-06 is the default.
309-
Default: "gpt-4o-2024-08-06",
310-
Env: "AICOMMIT_MODEL",
311-
Value: serpent.StringOf(&opts.model),
276+
Default: "gpt-4o-2024-08-06",
277+
Env: "AICOMMIT_MODEL",
278+
Value: serpent.StringOf(&opts.model),
312279
},
313280
{
314281
Name: "save-key",

prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func BuildPrompt(
132132
Role: openai.ChatMessageRoleSystem,
133133
Content: strings.Join([]string{
134134
"You are a tool called `aicommit` that generates high quality commit messages for git diffs.",
135-
"Follow these guidelines strictly:",
135+
"Generate only the commit message, without any additional text. Follow these guidelines:",
136136
"1. Limit the subject line to 50 characters.",
137137
"2. Use the imperative mood in the subject line.",
138138
"3. Capitalize the subject line and don't end it with a period.",

0 commit comments

Comments
 (0)