Last active
March 7, 2024 19:37
-
-
Save algal/274a0151c27cc65d15ca9fb869e974ff to your computer and use it in GitHub Desktop.
Calls Anthropic's claude-3-opus, passing in the command-line argument as the prompt.
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
#!/usr/bin/env bash | |
if [ "$#" -eq 0 ]; then | |
echo "Usage: $(basename "$0") promt_to_send_to_claude" | |
echo "" | |
echo " Requirements: ANTHROPIC_API, defined; jq and curl, installed; bash, version 3 or higher." | |
exit 1 | |
fi | |
function claude() { | |
local json_request | |
json_request=$(jq -n \ | |
--arg content "$*" \ | |
'{ | |
"model": "claude-3-opus-20240229", | |
"max_tokens": 1024, | |
"messages": [ | |
{ "role": "user", "content": $content } | |
] | |
}') | |
# echo $json_request # uncomment to debug | |
local json_response | |
json_response=$(curl --silent \ | |
--request POST \ | |
--url https://api.anthropic.com/v1/messages \ | |
--header "x-api-key: $ANTHROPIC_API_KEY" \ | |
--header "anthropic-version: 2023-06-01" \ | |
--header 'content-type: application/json' \ | |
--data "$json_request") | |
#echo $json_response # uncomment to debug | |
echo "$json_response" | jq --raw-output .content[0].text | |
} | |
claude "$*" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment