Skip to content

Commit

Permalink
Revert "Add JSON schema for strict message validation"
Browse files Browse the repository at this point in the history
This reverts commit 5474788.
  • Loading branch information
ammario committed Sep 13, 2024
1 parent 6cb60a9 commit 2551f9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
47 changes: 7 additions & 40 deletions cmd/aicommit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -137,35 +136,13 @@ func run(inv *serpent.Invocation, opts runOptions) error {
IncludeUsage: true,
},
Messages: msgs,
ResponseFormat: &openai.ChatCompletionResponseFormat{
Type: openai.ChatCompletionResponseFormatTypeJSONSchema,
JSONSchema: &openai.ChatCompletionResponseFormatJSONSchema{
Name: "commit_message",
Schema: json.RawMessage(`{
"type": "object",
"properties": {
"thought_process": {
"type": "string",
"description": "A chain of thought explaining the reasoning behind the commit message"
},
"commit_message": {
"type": "string",
"description": "The final, concise commit message"
}
},
"additionalProperties": false,
"required": ["thought_process", "commit_message"]
}`),
Strict: true,
},
},
})
if err != nil {
return err
}
defer stream.Close()

jsonMsg := &bytes.Buffer{}
msg := &bytes.Buffer{}

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

var parsedMsg struct {
CommitMessage string `json:"commit_message"`
}
err = json.Unmarshal(jsonMsg.Bytes(), &parsedMsg)
if err != nil {
return err
}

parsedMsg.CommitMessage = cleanAIMessage(parsedMsg.CommitMessage)
msg = bytes.NewBufferString(cleanAIMessage(msg.String()))

cmd := exec.Command("git", "commit", "-m", parsedMsg.CommitMessage)
cmd := exec.Command("git", "commit", "-m", msg.String())
if opts.amend {
cmd.Args = append(cmd.Args, "--amend")
}
Expand Down Expand Up @@ -304,11 +273,9 @@ func main() {
Description: "The model to use, e.g. gpt-4o or gpt-4o-mini.",
Flag: "model",
FlagShorthand: "m",
// Needed for structured output.
// Should update to gpt-4o once gpt-4o-2024-08-06 is the default.
Default: "gpt-4o-2024-08-06",
Env: "AICOMMIT_MODEL",
Value: serpent.StringOf(&opts.model),
Default: "gpt-4o-2024-08-06",
Env: "AICOMMIT_MODEL",
Value: serpent.StringOf(&opts.model),
},
{
Name: "save-key",
Expand Down
2 changes: 1 addition & 1 deletion prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func BuildPrompt(
Role: openai.ChatMessageRoleSystem,
Content: strings.Join([]string{
"You are a tool called `aicommit` that generates high quality commit messages for git diffs.",
"Follow these guidelines strictly:",
"Generate only the commit message, without any additional text. Follow these guidelines:",
"1. Limit the subject line to 50 characters.",
"2. Use the imperative mood in the subject line.",
"3. Capitalize the subject line and don't end it with a period.",
Expand Down

0 comments on commit 2551f9d

Please sign in to comment.