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

feat: testing differents prompts #25

Closed
wants to merge 1 commit into from
Closed

feat: testing differents prompts #25

wants to merge 1 commit into from

Conversation

emanuel-braz
Copy link
Owner

No description provided.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Comments:

  1. In the analyzeCode function, the variable allReviews is used to store the generated reviews. However, the variable name is not very descriptive. Consider using a more meaningful name that reflects the purpose of the variable.

  2. In the isJSON function, the parameter name obj is not very descriptive. Consider using a more meaningful name that reflects the purpose of the parameter.

  3. In the generateMessages function, the variable contentSystemMessage is being modified based on the values of overridePrompt and appendPrompt. However, the logic for appending the prompt is not correct. The current implementation adds an extra newline before the appended prompt. Consider modifying the logic to correctly append the prompt without an extra newline.

  4. In the generateMessages function, the comment at the end of the function mentions "instructionJsonFormat", but this variable is not used anywhere in the function. Consider removing this comment if it is not necessary.

@@ -57,47 +57,56 @@ async function getDiff(owner, repo, pull_number) {
57  }
58  
59  async function analyzeCode(parsedDiff, prDetails) {
60 -    const comments = []; //Array<{ body: string; path: string; line: number }>
60 +    const allReviews = []; //Array<{ body: string; path: string; line: number }>
61  
62      for (const file of parsedDiff) {
63          if (file.to === "/dev/null") continue; // Ignore deleted files
64          for (const chunk of file.chunks) {
65              
66 -            const messages = createMessages(file, chunk, prDetails);
66 +            const messages = generateMessages(file, chunk, prDetails);
67              const aiResponse = await getAIResponse(messages);
68              if (aiResponse) {
69 -                const newComments = createComment(file, chunk, aiResponse);
70 -                if (newComments) {
71 -                    comments.push(...newComments);
69 +                if (!isJSON(aiResponse)) {
70 +                    logger.log(`AI response is not in JSON format: ${aiResponse}`);
71 +                    createCommentOnPr(aiResponse, prDetails.owner, prDetails.repo, prDetails.pull_number, file.to);
72 +                } else {
73 +                    logger.log(`AI response is in JSON format: ${aiResponse}`);
74 +                    const reviews = generateReviewsFromJsonArray(file, chunk, aiResponse);
75 +                    if (reviews) {
76 +                        allReviews.push(...reviews);
77 +                    }
78                  }
79              }
80          }
81      }
76 -    return comments;
82 +    return allReviews;
83  }
84  
79 -function createMessages(file, chunk, prDetails) {
80 -    const instructionJsonFormat = `- Always provide the response in following JSON format:  [{"lineNumber":  <line_number>, "reviewComment": "<review comment>"}]`;
85 +function isJSON(obj) {
86 +    try {
87 +        JSON.parse(obj);
88 +        return true;
89 +    } catch (e) {
90 +        return false;
91 +    }
92 +}
93 +
94 +function generateMessages(file, chunk, prDetails) {
95  
82 -    var contentSystemMessage = `You are a senior software engineer and your task is to review pull requests for possible bugs or bad development practices. Follow the instructions below:
83 -- You will provide suggestions only if there are issues or bugs in the code, otherwise return an empty array.
84 -- Do not give positive comments or compliments.
85 -- Don't suggest removing empty line
86 -- Never suggest adding newline at end of file.
87 -- Never suggest to remove trailing or leading whitespace.
88 -- Never suggest to remove the spaces.
89 -- Don't suggest adding comment to code.
90 -- If no issues are found, return an empty array.
91 -- Do use the given pull request title and description only for the overall context and only comment the code.`;
96 +    var contentSystemMessage = `Your task is to review pull requests. Instructions:
97 +    - Provide the response in following JSON format:  [{"lineNumber":  <line_number>, "reviewComment": "<review comment>"}]
98 +    - Do not give positive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant