From 75e94d517825f43efb86d16b00fbde4356943f33 Mon Sep 17 00:00:00 2001 From: johnlk Date: Sat, 13 Jul 2024 13:44:48 -0400 Subject: [PATCH] Revise the prompt for simplicity --- src/gpt.sh | 104 ++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/gpt.sh b/src/gpt.sh index 9e29343..7d9ca87 100755 --- a/src/gpt.sh +++ b/src/gpt.sh @@ -1,68 +1,68 @@ #!/usr/bin/env bash -INITIAL_PROMPT=$( - cat < \ -Score: 80 \ -
\ -Improvements: \ - \r\n\r\n -\`\`\`relevant-coding-language \ -example code here \ -\`\`\` \ +INITIAL_PROMPT=$(cat < +Score: [0-100] + +Improvements: +- [Bullet point 1] +- [Bullet point 2] +- ... + +\`\`\`[language] +[Example code block if score < 90] +\`\`\` + +Note: Include the code block only for scores below 90. EOF ) gpt::prompt_model() { - local -r git_diff="${1}" + local -r git_diff="$1" + local -r api_url="https://api.openai.com/v1/chat/completions" - local -r response=$(curl -sSL \ + local response + response=$(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}]}')" \ - "https://api.openai.com/v1/chat/completions") + -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} + ] + }' + )" \ + "$api_url") - local -r error=$(echo "$response" | jq -r '.error') + local error + error=$(jq -r '.error' <<< "$response") if [[ "$error" != "null" ]]; then - kill -s TERM $TOP_PID utils::log_error "API request to 'api.openai.com' failed: $error" + return 1 fi - local -r body=$(echo "$response" | jq -r '.choices[0].message.content') - - echo "$body" -} + jq -r '.choices[0].message.content' <<< "$response" +} \ No newline at end of file