Skip to content

Instantly share code, notes, and snippets.

@iamsupercode
Created November 9, 2023 11:05
Show Gist options
  • Select an option

  • Save iamsupercode/f618e282bbbe005d695d147cedea0f9d to your computer and use it in GitHub Desktop.

Select an option

Save iamsupercode/f618e282bbbe005d695d147cedea0f9d to your computer and use it in GitHub Desktop.
Codepal Shell Console App
#!/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"
@iamsupercode
Copy link
Author

Running the script

  1. Assign execution permissions to the script by running command chmod +x codepal.sh
  2. Execute the script ./codepal.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment