Skip to content

Commit f051bcb

Browse files
committed
Add new models, summarize commit messages
1 parent d975a5b commit f051bcb

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

cmd/commit.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/chand1012/ottodocs/pkg/ai"
1313
"github.com/chand1012/ottodocs/pkg/calc"
1414
"github.com/chand1012/ottodocs/pkg/config"
15+
"github.com/chand1012/ottodocs/pkg/constants"
1516
"github.com/chand1012/ottodocs/pkg/git"
1617
"github.com/chand1012/ottodocs/pkg/utils"
1718
l "github.com/charmbracelet/log"
@@ -158,16 +159,17 @@ var commitCmd = &cobra.Command{
158159
}
159160

160161
if len(msg) > 75 {
161-
// truncate to the first period or the first newline
162-
newMsg := msg
163-
if strings.Contains(msg, "\n") {
164-
newMsg = strings.Split(msg, "\n")[0]
165-
} else if strings.Contains(msg, ".") {
166-
newMsg = strings.Split(msg, ".")[0]
162+
// summarize the message
163+
stream, err := ai.SimpleStreamRequest(constants.SUMMARIZE_PROMPT+msg, conf)
164+
if err != nil {
165+
log.Errorf("Error summarizing commit message: %s", err)
166+
os.Exit(1)
167167
}
168-
if len(newMsg) != len(msg) {
169-
utils.PrintColoredTextLn("Truncated commit message: "+newMsg, conf.OttoColor)
170-
msg = newMsg
168+
utils.PrintColoredText("Summarized Commit Msg: ", conf.OttoColor)
169+
msg, err = utils.PrintChatCompletionStream(stream)
170+
if err != nil {
171+
log.Errorf("Error printing chat completion stream: %s", err)
172+
os.Exit(1)
171173
}
172174
}
173175

cmd/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15-
var VALID_MODELS = []string{"gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301"}
15+
var VALID_MODELS = []string{"gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0613"}
1616

1717
// configCmd represents the config command
1818
var configCmd = &cobra.Command{
@@ -21,7 +21,7 @@ var configCmd = &cobra.Command{
2121
Long: `Configures ottodocs. Allows user to specify OpenAI API Key, GitHub Token, and the model with a single command.
2222
2323
Default model is gpt-3.5-turbo.
24-
Valid models are: gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301
24+
Valid models are: gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301, gpt-3.5-turbo-16k, gpt-3.5-turbo-0613
2525
See here for more information on the Models available: https://platform.openai.com/docs/models/model-endpoint-compatibility
2626
2727
GitHub Tokens need access to the repo scope.
@@ -103,4 +103,4 @@ func init() {
103103
configCmd.Flags().StringVarP(&userColor, "userColor", "u", "", "User color for configuration")
104104
// set otto color
105105
configCmd.Flags().StringVarP(&ottoColor, "ottoColor", "o", "", "Otto color for configuration")
106-
}
106+
}

pkg/calc/tokens.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func EstimateTokens(inputs ...string) int {
3636
}
3737

3838
func GetMaxTokens(model string) int {
39+
if strings.Contains(model, "16k") {
40+
return 16384
41+
}
3942
if strings.Contains(model, "32k") {
4043
return 32768
4144
}

pkg/constants/prompts.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ var COMMAND_QUESTION_PROMPT string = `You are a helpful assistant who answers qu
3030
- If there is no way to answer the question, you should say so.
3131
- The answer must be AT LEAST one sentence long.`
3232

33-
var GIT_DIFF_PROMPT_STD string = `You are a helpful assistant who writes git commit messages. You will be given a Git diff and you should use it to create a commit message. The commit message should be no longer than 75 characters long and should describe the changes in the diff. The changes should be in the present tense and should be concise. Do not include the file names in the commit message.`
33+
var GIT_DIFF_PROMPT_STD string = `You are a helpful assistant who writes git commit messages. You will be given a Git diff and you should use it to create a commit message. The commit message should be no longer than 75 characters long and should describe the changes in the diff. The changes should be in the present tense and should be concise. Do not include the file names in the commit message. The commit message should not exceed 75 characters.`
3434

35-
var GIT_DIFF_PROMPT_CONVENTIONAL string = `You are a helpful assistant who writes git commit messages. You will be given a Git diff and you should use it to create a commit message. The commit message should be no longer than 75 characters long and should describe the changes in the diff. Do not include the file names in the commit message. The commit message should follow the conventional commit format.`
35+
var GIT_DIFF_PROMPT_CONVENTIONAL string = `You are a helpful assistant who writes git commit messages. You will be given a Git diff and you should use it to create a commit message. The commit message should be no longer than 75 characters long and should describe the changes in the diff. Do not include the file names in the commit message. The commit message should not exceed 75 characters. The commit message should follow the conventional commit format.`
3636

3737
var PR_TITLE_PROMPT string = "You are a helpful assistant who writes pull request titles. You will be given information related to the pull request and you should use it to create a pull request title. The title should be no longer than 75 characters long and should describe the changes in the pull request. Do not include the file names in the title."
3838

@@ -50,3 +50,4 @@ var RELEASE_PROMPT string = `You are a helpful assistant who creates GitHub rele
5050
5151
Commit log:
5252
`
53+
var SUMMARIZE_PROMPT string = "You are a helpful assistant who summarizes text. Summarize the following into a single line with at most 75 characters:\n"

0 commit comments

Comments
 (0)