Skip to content

Commit

Permalink
refactor: Enhance prompt, abstract const
Browse files Browse the repository at this point in the history
Update model, instruct wasn't working
  • Loading branch information
kmesiab committed Jan 17, 2024
1 parent b927110 commit e7b13ad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
DefaultFilePerms = 0o644
DefaultOpenAIModel = "gpt-3.5-turbo-instruct"
DefaultOpenAIModel = "gpt-3.5-turbo"
)

type argT struct {
Expand Down Expand Up @@ -59,6 +59,7 @@ func main() {
parsedDiffFiles,
argv.CompletionModel,
mergedArgs.ApiKey,
Prompt,
&OpenAICompletionService{},
)
if err != nil {
Expand Down Expand Up @@ -113,15 +114,15 @@ func saveReviews(reviews []ReviewedDiff) {
}
}

func getCodeReviews(diffs []*gh.GitDiff, model, apiKey string, svc CompletionServiceInterface) ([]ReviewedDiff, error) {
func getCodeReviews(diffs []*gh.GitDiff, model, apiKey, prompt string, svc CompletionServiceInterface) ([]ReviewedDiff, error) {
reviewChan := make(chan ReviewedDiff)
var reviews []ReviewedDiff

for _, diff := range diffs {
go func(d *gh.GitDiff) {
fmt.Printf("🤖 Getting code review for %s\n", path.Base(d.FilePathNew))

review, err := svc.GetCompletion(d.DiffContents, model, apiKey)
review, err := svc.GetCompletion(d.DiffContents, model, apiKey, prompt)

rDiff := ReviewedDiff{
Error: err,
Expand Down
26 changes: 2 additions & 24 deletions openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,12 @@ import (
)

type CompletionServiceInterface interface {
GetCompletion(diff, model, apiKey string) (string, error)
GetCompletion(diff, model, apiKey, prompt string) (string, error)
}

type OpenAICompletionService struct{}

func (s *OpenAICompletionService) GetCompletion(diff, gptModel, apiKey string) (string, error) {
prompt := `You are an experienced software developer conducting a code review on a Git diff. Your expertise spans
various programming languages and development best practices. Please review the attached Git diff with the
following considerations in mind:
1. **Technical Accuracy**: Identify any bugs, coding errors, or security vulnerabilities.
2. **Best Practices**: Evaluate adherence to language-specific best practices, including code style and patterns.
3. **Performance and Scalability**: Highlight any performance issues and assess the code's scalability.
4. **Readability and Clarity**: Assess the code's readability, including its structure and commenting.
5. **Maintainability**: Consider the ease of future modifications and support.
6. **Testability**: Evaluate the test coverage and quality of tests.
7. **Contextual Fit**: Judge how the changes fit within the broader project scope and goals.
Provide actionable feedback, suggesting improvements and alternatives where applicable. Include code samples in code
blocks. Your review should be empathetic and constructive, focusing on helping the author improve the code.
Format your review in markdown, ensuring readability with line wrapping before 60 characters.
In your review, consider the impact of your feedback on team dynamics and the development process. Aim for a
balance between technical rigor and fostering a positive and collaborative team environment.
Output the review in markdown format
### Git Diff:` + "```\n%s\n```"
func (s *OpenAICompletionService) GetCompletion(diff, gptModel, apiKey, prompt string) (string, error) {

fullPrompt := fmt.Sprintf(prompt, diff)

Expand Down
23 changes: 23 additions & 0 deletions prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

const Prompt = `You are an experienced principle software engineer conducting a code review on a Git diff. Your expertise spans
various programming languages, as well as industry, and development best practices. Please review the attached Git diff with the
following considerations in mind:
1. **Technical Accuracy**: Identify any bugs, coding errors, or security vulnerabilities and provide suggested code fixes.
2. **Best Practices**: Evaluate adherence to language-specific best practices, including code style and patterns.
4. **Readability and Clarity**: Assess the code's readability, including its structure and commenting.
5. **Maintainability**: Consider the ease of future modifications and support.
6. **Testability**: Evaluate the test coverage and quality of tests.
3. **Performance and Scalability**: Highlight any performance issues and assess the code's scalability.
Provide actionable feedback, suggesting improvements and alternative solutions where applicable. Include code samples in code
blocks. Your review should be empathetic and constructive, focusing on helping the author improve the code.
Format your review in markdown, ensuring readability with line wrapping before 60 characters.
In your review, consider the impact of your feedback on team dynamics and the development process. Aim for a
balance between technical rigor and fostering a positive and collaborative team environment.
Output the review in markdown format
### Git Diff:` + "```\n%s\n```"

0 comments on commit e7b13ad

Please sign in to comment.