Skip to content

Commit e91df2e

Browse files
authored
Merge pull request #25 from ravilushqa/improve_description
improve description
2 parents bbdcc3a + bd477a3 commit e91df2e

File tree

7 files changed

+42
-28
lines changed

7 files changed

+42
-28
lines changed

cmd/description/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func run(ctx context.Context) error {
7272
}
7373

7474
if opts.Test {
75-
fmt.Println(completion)
7675
return nil
7776
}
7877

description/description.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func genCompletionOnce(ctx context.Context, client *oAIClient.Client, diff *gith
5959
return "", fmt.Errorf("error completing prompt: %w", err)
6060
}
6161

62+
fmt.Println("Completion:", completion)
63+
6264
return completion, nil
6365
}
6466

@@ -67,38 +69,51 @@ func genCompletionPerFile(ctx context.Context, client *oAIClient.Client, diff *g
6769
OverallDescribeCompletion := fmt.Sprintf("Pull request title: %s, body: %s\n\n", pr.GetTitle(), pr.GetBody())
6870

6971
for i, file := range diff.Files {
70-
if file.Patch == nil {
72+
patch := file.GetPatch()
73+
if patch == "" {
7174
continue
7275
}
73-
prompt := fmt.Sprintf(oAIClient.PromptDescribeChanges, *file.Patch)
74-
75-
if len(prompt) > 4096 {
76-
prompt = fmt.Sprintf("%s...", prompt[:4093])
76+
maxLength := 4096 - len(oAIClient.PromptDescribeChanges)
77+
if len(*file.Patch) > maxLength {
78+
fmt.Println("Patch is too long, truncating")
79+
patch = fmt.Sprintf("%s...", patch[:maxLength])
7780
}
7881

79-
fmt.Printf("Sending prompt to OpenAI for file %d/%d\n", i+1, len(diff.Files))
82+
fmt.Printf("processing file: %s %d/%d\n", file.GetFilename(), i+1, len(diff.Files))
8083
completion, err := client.ChatCompletion(ctx, []openai.ChatCompletionMessage{
84+
{
85+
Role: openai.ChatMessageRoleSystem,
86+
Content: oAIClient.PromptDescribeChanges,
87+
},
8188
{
8289
Role: openai.ChatMessageRoleUser,
83-
Content: prompt,
90+
Content: patch,
8491
},
8592
})
8693
if err != nil {
8794
return "", fmt.Errorf("error getting review: %w", err)
8895
}
96+
fmt.Println("Completion:", completion)
97+
8998
OverallDescribeCompletion += fmt.Sprintf("File: %s \nDescription: %s \n\n", file.GetFilename(), completion)
9099
}
91100

92-
fmt.Println("Sending final prompt to OpenAI")
101+
fmt.Println("Summarizing overall completion")
93102
overallCompletion, err := client.ChatCompletion(ctx, []openai.ChatCompletionMessage{
103+
{
104+
Role: openai.ChatMessageRoleSystem,
105+
Content: oAIClient.PromptDescribeOverall,
106+
},
94107
{
95108
Role: openai.ChatMessageRoleUser,
96-
Content: fmt.Sprintf(oAIClient.PromptDescribeOverall, OverallDescribeCompletion),
109+
Content: OverallDescribeCompletion,
97110
},
98111
})
99112
if err != nil {
100113
return "", fmt.Errorf("error completing final prompt: %w", err)
101114
}
102115

116+
fmt.Println("Overall completion:", overallCompletion)
117+
103118
return overallCompletion, nil
104119
}

openai/openai.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package openai
33
import (
44
"context"
55
_ "embed"
6+
"errors"
67
"fmt"
78
"time"
89

@@ -39,6 +40,9 @@ func (o *Client) ChatCompletion(ctx context.Context, messages []openai.ChatCompl
3940
)
4041

4142
if err != nil {
43+
if errors.Is(err, context.Canceled) {
44+
return "", err
45+
}
4246
fmt.Println("Error completing prompt:", err)
4347
fmt.Println("Retrying after 1 minute")
4448
// retry once after 1 minute

openai/prompts/describe_changes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Below is the code patch, Generate a GitHub pull request description based on the following comments without basic prefix
2-
%s
1+
Act as a Senior Developer and describe the code patch.
2+
Do not include any explanations, only provide a short description of the code patch.

openai/prompts/describe_overall

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Below comments are generated by AI
2-
Generate a GitHub pull request description based on the following comments without basic prefix in markdown format.
3-
Response should contain ### Description and ### Changes blocks
4-
5-
PR comments:
6-
%s
1+
Act as a Senior Developer and summarize the results of development work done.
2+
Changes must be formatted as a markdown nested list. The root items are the file names in code format and bold, and the child items are the changes made to the file.
3+
Do not include any explanations. Provide a markdown detailed description, including the following information:
4+
## Summary
5+
## Changes
6+
## Impact

openai/prompts/review

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
You are CodeReviewGPT, an AI agent that specializes in generating code reviews for software projects using advanced natural language processing and machine learning techniques.
2-
Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.
3-
4-
GOALS:
5-
6-
1. Analyze structure, and logic to provide comprehensive feedback on code quality, readability, maintainability, and performance.
7-
2. Identify potential bugs, security vulnerabilities, and other issues that may impact the functionality and stability of the software.
8-
3. Possible quality values: good, bad, neutral. If quality is good, issues should be empty.
9-
4. Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
1+
Act as a Senior Developer and review the code below. Provide a JSON response indicating the code’s quality and any issues you find.
2+
Avoid line response duplication or any other unnecessary information. Line numbers should be one-based and cannot be null.
3+
Allowed values for quality are: good, bad, terrible.
4+
Allowed values for type are: bug, security, performance, maintenance.
5+
Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
106
{
117
"quality": "good",
128
"issues": [

review/review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func GenerateCommentsFromDiff(ctx context.Context, openAIClient Completer, diff
5454
}
5555
completion, err := openAIClient.ChatCompletion(ctx, []openai.ChatCompletionMessage{
5656
{
57-
Role: openai.ChatMessageRoleUser,
57+
Role: openai.ChatMessageRoleSystem,
5858
Content: oAIClient.PromptReview,
5959
},
6060
{

0 commit comments

Comments
 (0)