Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve description #25

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/description/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func run(ctx context.Context) error {
}

if opts.Test {
fmt.Println(completion)
return nil
}

Expand Down
33 changes: 24 additions & 9 deletions description/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func genCompletionOnce(ctx context.Context, client *oAIClient.Client, diff *gith
return "", fmt.Errorf("error completing prompt: %w", err)
}

fmt.Println("Completion:", completion)

return completion, nil
}

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

for i, file := range diff.Files {
if file.Patch == nil {
patch := file.GetPatch()
if patch == "" {
continue
}
prompt := fmt.Sprintf(oAIClient.PromptDescribeChanges, *file.Patch)

if len(prompt) > 4096 {
prompt = fmt.Sprintf("%s...", prompt[:4093])
maxLength := 4096 - len(oAIClient.PromptDescribeChanges)
if len(*file.Patch) > maxLength {
fmt.Println("Patch is too long, truncating")
patch = fmt.Sprintf("%s...", patch[:maxLength])
}

fmt.Printf("Sending prompt to OpenAI for file %d/%d\n", i+1, len(diff.Files))
fmt.Printf("processing file: %s %d/%d\n", file.GetFilename(), i+1, len(diff.Files))
completion, err := client.ChatCompletion(ctx, []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: oAIClient.PromptDescribeChanges,
},
{
Role: openai.ChatMessageRoleUser,
Content: prompt,
Content: patch,
},
})
if err != nil {
return "", fmt.Errorf("error getting review: %w", err)
}
fmt.Println("Completion:", completion)

OverallDescribeCompletion += fmt.Sprintf("File: %s \nDescription: %s \n\n", file.GetFilename(), completion)
}

fmt.Println("Sending final prompt to OpenAI")
fmt.Println("Summarizing overall completion")
overallCompletion, err := client.ChatCompletion(ctx, []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: oAIClient.PromptDescribeOverall,
},
{
Role: openai.ChatMessageRoleUser,
Content: fmt.Sprintf(oAIClient.PromptDescribeOverall, OverallDescribeCompletion),
Content: OverallDescribeCompletion,
},
})
if err != nil {
return "", fmt.Errorf("error completing final prompt: %w", err)
}

fmt.Println("Overall completion:", overallCompletion)

return overallCompletion, nil
}
4 changes: 4 additions & 0 deletions openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openai
import (
"context"
_ "embed"
"errors"
"fmt"
"time"

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

if err != nil {
if errors.Is(err, context.Canceled) {
return "", err
}
fmt.Println("Error completing prompt:", err)
fmt.Println("Retrying after 1 minute")
// retry once after 1 minute
Expand Down
4 changes: 2 additions & 2 deletions openai/prompts/describe_changes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Below is the code patch, Generate a GitHub pull request description based on the following comments without basic prefix
%s
Act as a Senior Developer and describe the code patch.
Do not include any explanations, only provide a short description of the code patch.
12 changes: 6 additions & 6 deletions openai/prompts/describe_overall
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Below comments are generated by AI
Generate a GitHub pull request description based on the following comments without basic prefix in markdown format.
Response should contain ### Description and ### Changes blocks

PR comments:
%s
Act as a Senior Developer and summarize the results of development work done.
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.
Do not include any explanations. Provide a markdown detailed description, including the following information:
## Summary
## Changes
## Impact
14 changes: 5 additions & 9 deletions openai/prompts/review
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
You are CodeReviewGPT, an AI agent that specializes in generating code reviews for software projects using advanced natural language processing and machine learning techniques.
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.

GOALS:

1. Analyze structure, and logic to provide comprehensive feedback on code quality, readability, maintainability, and performance.
2. Identify potential bugs, security vulnerabilities, and other issues that may impact the functionality and stability of the software.
3. Possible quality values: good, bad, neutral. If quality is good, issues should be empty.
4. Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
Act as a Senior Developer and review the code below. Provide a JSON response indicating the code’s quality and any issues you find.
Avoid line response duplication or any other unnecessary information. Line numbers should be one-based and cannot be null.
Allowed values for quality are: good, bad, terrible.
Allowed values for type are: bug, security, performance, maintenance.
Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
{
"quality": "good",
"issues": [
Expand Down
2 changes: 1 addition & 1 deletion review/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func GenerateCommentsFromDiff(ctx context.Context, openAIClient Completer, diff
}
completion, err := openAIClient.ChatCompletion(ctx, []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Role: openai.ChatMessageRoleSystem,
Content: oAIClient.PromptReview,
},
{
Expand Down