Created
November 9, 2023 11:05
-
-
Save iamsupercode/f618e282bbbe005d695d147cedea0f9d to your computer and use it in GitHub Desktop.
Codepal Shell Console App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Prompt the user for the API key, language, and description | |
| read -p "Enter your CodePal.ai API key: " API_KEY | |
| read -p "Enter the programming language: " language | |
| read -p "Enter the code description: " description | |
| # Set the API endpoint | |
| API_ENDPOINT="https://api.codepal.ai/v1/code-generator/query" | |
| # Set the output file name | |
| OUTPUT_FILE="generated_code.txt" | |
| # Make the API request and store the response | |
| response=$(curl --location "$API_ENDPOINT" \ | |
| --header "Authorization: Bearer $API_KEY" \ | |
| --form "language=\"$language\"" \ | |
| --form "instructions=\"$description\"") | |
| # Extract the value of 'result' using awk | |
| result=$(echo "$response" | awk -F'"result":"' '{print $2}' | awk -F'"}' '{print $1}') | |
| # Save the 'result' value to the output file | |
| echo "$result" > "$OUTPUT_FILE" | |
| echo "Generated code saved to $OUTPUT_FILE" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running the script