Skip to content

Commit 477a14b

Browse files
committed
Remove debug message, update title and body generation with streams
1 parent 85dc49a commit 477a14b

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

cmd/pr.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ Requires Git to be installed on the system. If a title is not provided, one will
4242
os.Exit(1)
4343
}
4444

45-
fmt.Println("Generating PR...")
46-
4745
currentBranch, err := git.GetBranch()
4846
if err != nil {
4947
log.Errorf("Error getting current branch: %s", err)
@@ -66,14 +64,20 @@ Requires Git to be installed on the system. If a title is not provided, one will
6664

6765
log.Debugf("Got %d logs", len(strings.Split(logs, "\n")))
6866

67+
fmt.Print("Title: ")
6968
if title == "" {
7069
// generate the title
7170
log.Debug("Generating title...")
72-
title, err = ai.PRTitle(logs, c)
71+
stream, err := ai.PRTitle(logs, c)
7372
if err != nil {
7473
log.Errorf("Error generating title: %s", err)
7574
os.Exit(1)
7675
}
76+
title, err = utils.PrintChatCompletionStream(stream)
77+
if err != nil {
78+
log.Errorf("Error printing chat completion stream: %s", err)
79+
os.Exit(1)
80+
}
7781
}
7882

7983
log.Debugf("Title: %s", title)
@@ -145,14 +149,19 @@ Requires Git to be installed on the system. If a title is not provided, one will
145149
prompt = "Title: " + title + "\n\nGit logs: " + logs + "\n\nGit diff: " + diff
146150
}
147151

148-
body, err := ai.PRBody(prompt, c)
152+
fmt.Print("Body: ")
153+
stream, err := ai.PRBody(prompt, c)
149154
if err != nil {
150155
log.Errorf("Error generating PR body: %s", err)
151156
os.Exit(1)
152157
}
153158

154-
fmt.Println("Title: ", title)
155-
fmt.Println("Body: ", body)
159+
body, err := utils.PrintChatCompletionStream(stream)
160+
if err != nil {
161+
log.Errorf("Error printing chat completion stream: %s", err)
162+
os.Exit(1)
163+
}
164+
156165
fmt.Println("Branch: ", base)
157166

158167
if !push {

pkg/ai/pr.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package ai
33
import (
44
"github.com/chand1012/ottodocs/pkg/config"
55
"github.com/chand1012/ottodocs/pkg/constants"
6+
"github.com/sashabaranov/go-openai"
67
)
78

8-
func PRTitle(gitLog string, conf *config.Config) (string, error) {
9-
return request(constants.PR_TITLE_PROMPT, gitLog, conf)
9+
func PRTitle(gitLog string, conf *config.Config) (*openai.ChatCompletionStream, error) {
10+
return requestStream(constants.PR_TITLE_PROMPT, gitLog, conf)
1011
}
1112

12-
func PRBody(info string, conf *config.Config) (string, error) {
13-
return request(constants.PR_BODY_PROMPT, info, conf)
13+
func PRBody(info string, conf *config.Config) (*openai.ChatCompletionStream, error) {
14+
return requestStream(constants.PR_BODY_PROMPT, info, conf)
1415
}
1516

1617
func CompressDiff(diff string, conf *config.Config) (string, error) {

0 commit comments

Comments
 (0)