From 8b0638a3eb4b708f20bcbb0aeefb4bfee48ffa2f Mon Sep 17 00:00:00 2001 From: kevin_mesiab Date: Wed, 17 Jan 2024 09:35:45 -0800 Subject: [PATCH] refactor: Enhance prompt, abstract const Update model, instruct wasn't working --- main.go | 7 ++++--- openai.go | 26 ++------------------------ prompt.go | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 prompt.go diff --git a/main.go b/main.go index 08557f1..191f86b 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( const ( DefaultFilePerms = 0o644 - DefaultOpenAIModel = "gpt-3.5-turbo-instruct" + DefaultOpenAIModel = "gpt-3.5-turbo" ) type argT struct { @@ -59,6 +59,7 @@ func main() { parsedDiffFiles, argv.CompletionModel, mergedArgs.ApiKey, + Prompt, &OpenAICompletionService{}, ) if err != nil { @@ -113,7 +114,7 @@ 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 @@ -121,7 +122,7 @@ func getCodeReviews(diffs []*gh.GitDiff, model, apiKey string, svc CompletionSer 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, diff --git a/openai.go b/openai.go index 9304646..166e598 100644 --- a/openai.go +++ b/openai.go @@ -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) diff --git a/prompt.go b/prompt.go new file mode 100644 index 0000000..ea1060e --- /dev/null +++ b/prompt.go @@ -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```"