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

Conversation

johnlk
Copy link
Contributor

@johnlk johnlk commented Aug 14, 2023

No description provided.

@johnlk johnlk self-assigned this Aug 14, 2023
@github-actions
Copy link

Score: 85

Improvements:

  1. Consolidate all prompt message into a single variable.
  2. Add more helpful error checking on the cURL command.
  3. Encapsulate all curl options into variable and call it in curl command.
  4. Keep all magic strings at the top of the file for easy managing i.e API's URLs.
  5. Make use of the fact that local variables are implicitly declared as local -r and thus are readonly. This could improve code readability.
#!/usr/bin/env bash

API_URL="https://api.openai.com/v1/chat/completions"
CONTENT_TYPE="Content-Type: application/json"
AUTHORIZATION="Authorization: Bearer $OPEN_AI_API_KEY"
HOME_DIR="/root"

INITIAL_PROMPT=$(cat <<EOF
...

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

    local CURL_OPTIONS=(
        -sSL
        -H "$CONTENT_TYPE"
        -H "$AUTHORIZATION"
        -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}]}')"
    )

    local body=$(curl "${CURL_OPTIONS[@]}" "$API_URL")

    ...

}
...

main()
...

@johnlk johnlk merged commit a0a553c into main Aug 14, 2023
1 check passed
@johnlk johnlk deleted the john/reset-to-original-prompt branch August 14, 2023 21:30
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.

None yet

1 participant