Last active
August 19, 2025 18:27
-
-
Save craigphicks/ef5270481aa5e7a2731e1fdf0f495631 to your computer and use it in GitHub Desktop.
Send API requests for code completion via a vscodium/vscode task interface
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 | |
# Accept input as arguments instead of stdin | |
input="$*" | |
if [ -z "$input" ]; then | |
echo "Usage: $0 'code to complete'" >&2 | |
exit 1 | |
fi | |
# input=$(cat) | |
# if [ -z "$input" ]; then | |
# echo "Usage: echo 'code to complete' | $0" >&2 | |
# exit 1 | |
# fi | |
echo "sending: $input" | |
ANTHROPIC_API_KEY=$(cat ~/.anthropic-key) | |
# Build the entire JSON payload with jq for proper escaping | |
payload=$(jq -n \ | |
--arg content "Complete this code and return only the completed code: $input" \ | |
'{ | |
"model": "claude-3-5-sonnet-20241022", | |
"max_tokens": 300, | |
"messages": [{"role": "user", "content": $content}] | |
}') | |
curl -s -X POST https://api.anthropic.com/v1/messages \ | |
-H "x-api-key: $ANTHROPIC_API_KEY" \ | |
-H "anthropic-version: 2023-06-01" \ | |
-H "content-type: application/json" \ | |
-d "$payload" | jq -r '.content[0].text' |
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
// Place your key bindings in this file to override the defaults | |
[ | |
{ | |
"key": "ctrl+alt+c", | |
"command": "workbench.action.tasks.runTask", | |
"args": "complete" | |
} | |
] |
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 | |
set -x | |
AKF=~/.anthropic-key | |
if [ ! -f $AKF ]; then | |
read -sp "Enter your Anthropic token: " token && (echo $token > $AKF && chmod 600 $AKF) | |
fi |
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
{ | |
// See https://go.microsoft.com/fwlink/?LinkId=733558 | |
// for the documentation about the tasks.json format | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "test-echo-hello", | |
"type": "shell", | |
"command": "bash", | |
"args": ["-c", "echo hello"], | |
"group": "build", | |
"presentation": { | |
"reveal": "always", | |
"focus": true, | |
//"panel": "new", | |
"showReuseMessage": false, | |
"clear": false | |
} | |
}, | |
{ | |
"label": "complete", | |
"type": "shell", | |
"command": "/workspace/claude-complete.sh", | |
"args": ["${input:codeInput}"], | |
"group": "build", | |
"presentation": { | |
"reveal": "always", | |
"focus": true, | |
//"panel": "new" | |
} | |
} | |
], | |
"inputs": [ | |
{ | |
"id": "codeInput", | |
"type": "promptString", | |
"description": "Paste code to complete:" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment