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

Restore original unparameterized prompt #30

Merged
merged 1 commit into from
Aug 14, 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
8 changes: 7 additions & 1 deletion .github/workflows/robin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Robin AI Reviewer

on: [pull_request]
on:
pull_request:
branches: [main]
types:
- opened
- reopened
- ready_for_review

jobs:
build:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ name: Robin AI Reviewer

on:
pull_request:
types: [ready_for_review]
branches: [main]
types:
- opened
- reopened
- ready_for_review

jobs:
build:
Expand Down
10 changes: 0 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ inputs:
description: 'URL to the API of your Github Server, only necessary for Github Enterprise customers'
required: false
default: 'https://api.github.com'
coding_principles:
description: 'The main points of feedback and code principles to maintain'
required: false
default: 'readability, maintainability, single responsibility principle, DRY principle'
ignored_principles:
description: 'Feedback to ignore or omit'
required: false
default: 'code comments, heredoc comments, unused imports'
files_to_ignore:
description: 'Whitespace separated list of files to ignore'
required: false
Expand All @@ -35,8 +27,6 @@ runs:
- --open_ai_api_key=${{ inputs.OPEN_AI_API_KEY }}
- --gpt_model_name=${{ inputs.gpt_model_name }}
- --github_api_url=${{ inputs.github_api_url }}
- --coding_principles=${{ inputs.coding_principles }}
- --ignored_principles=${{ inputs.ignored_principles }}
- --files_to_ignore=${{ inputs.files_to_ignore }}
branding:
icon: 'tag'
Expand Down
27 changes: 15 additions & 12 deletions src/gpt.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
#!/usr/bin/env bash

gpt::prompt_model() {
local -r git_diff="$1"
local -r initial_prompt=$(cat <<EOF
coding_principles: $2\n\
ignored_principles: $3\n\
INITIAL_PROMPT=$(cat <<EOF
I'm going to assign you a role. Your role is being a pull request code reviewer on our engineering team. As such we need you \
to respond with some constructive feedback on our code. Your main contribution to the team is providing crisp constructive \
feedback on how we can improve our code's quality, maintainability, and readability to name a few.\n\
The code will come as a git diff. If a file is deleted, do not give feedback on it.\n\
The code will come as a git diff. If a file is deleted, do not give feedback on it. If the file is a configuration file, a \
Readme file, package.json, or any other file that seems less like code and more like libraries or configuration, you may \
ignore it. If all files in the git diff are configs or other non-code files, you may respond with “nothing to grade” and \
ignore the remaining instructions.\n\
You will first give feedback in the form of a score between 0-100. The number will estimate how likely the code change will \
be accepted. Assume the CTO is really stingy and only accepts high level production code, so they reject most initial code \
changes. Do not give a justification for your 0-100 score.\n\
Second, you will respond with a short list of improvements. Possible code improvements include but are certainly not limited \
to: coding_principles. You are not to give feedback on commenting with heredocs or ignored_principles. Our \
to: better variable naming, simplifying functions, handling edge cases better, performance optimizations, deleting unused \
code, single responsibility principle, DRY principle, etc. You are not to give feedback on commenting with heredocs. Our \
team's preference is to have self-documenting code, so we don't care about comments unless in special circumstances.\n\
Finally, your last piece of feedback should include a code block. Important: If you assigned an score of >= 90, you should \
not produce a code block, just repond "N/A". For scores < 90, the code block can either be a complete re-write of the code \
being scrutinized or a subset of it, but you should illustrate your feedback with a code example. Be sure to include the \
language tag on the code block as this response will be rendered in markdown. Do not explain the code block!\n\
Finally, your last piece of feedback should include a code block. If you assigned an score of >= 90, skip this step. You should \
only give a code block for scores < 90. The code block can either be a complete re-write of the code being scrutinized or a \
subset of it, but you should illustrate your feedback with a code example. Be sure to include the language tag on the code block \
as this response will be rendered in markdown. Do not explain the code block!\n\
The code block should be the last part of all your responses.
EOF
)

gpt::prompt_model() {
local -r git_diff="$1"

local -r body=$(curl -sSL \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPEN_AI_API_KEY" \
-d "$(jq -n --arg model "$GPT_MODEL" --arg prompt "$initial_prompt" --arg git_diff "$git_diff" '{model: $model, messages: [{role: "user", content: $prompt}, {role: "user", content: $git_diff}]}')" \
-d "$(jq -n --arg model "$GPT_MODEL" --arg prompt "$INITIAL_PROMPT" --arg git_diff "$git_diff" '{model: $model, messages: [{role: "user", content: $prompt}, {role: "user", content: $git_diff}]}')" \
"https://api.openai.com/v1/chat/completions")

local -r error=$(echo "$body" | jq -r '.error')
Expand Down
4 changes: 2 additions & 2 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source "$HOME_DIR/src/gpt.sh"
##? Auto-reviews a Pull Request
##?
##? Usage:
##? main.sh --github_token=<token> --open_ai_api_key=<token> --gpt_model_name=<name> --github_api_url=<url> --coding_principles=<text> --ignored_principles=<text> --files_to_ignore=<files>
##? main.sh --github_token=<token> --open_ai_api_key=<token> --gpt_model_name=<name> --github_api_url=<url> --files_to_ignore=<files>
main() {
eval "$(/root/bin/docpars -h "$(grep "^##?" "$HOME_DIR/src/main.sh" | cut -c 5-)" : "$@")"

Expand All @@ -26,7 +26,7 @@ main() {
exit
fi

local -r gpt_response=$(gpt::prompt_model "$commit_diff" "$coding_principles" "$ignored_principles" )
local -r gpt_response=$(gpt::prompt_model "$commit_diff")

if [ -z "$gpt_response" ]; then
echoerr "GPT's response was NULL. Double check your API key and billing details."
Expand Down