-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathgenerate-workflow
More file actions
executable file
·58 lines (48 loc) · 1.28 KB
/
generate-workflow
File metadata and controls
executable file
·58 lines (48 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /bin/bash
usage="Usage: $0 <input-prompt-json> <output-typescript-file>"
input_prompt_json=$1
output_typescript_file=$2
api_url=https://api.anthropic.com/v1/messages
api_key=$ANTHROPIC_API_KEY
if [ -z "$api_key" ]; then
echo "Please set the ANTHROPIC_API_KEY environment variable"
exit 1
fi
model_id=claude-sonnet-4-20250514
anthropic_version=2023-06-01
set -f # Disable globbing, there's a * in the input prompt
system_prompt=$(jq -R -s '{"text": .}' claude-endpoint-creation-prompt.md | jq .text)
input_prompt=$(jq @json $input_prompt_json)
api_body=$(
cat <<EOF
{
"model": "$model_id",
"system": $system_prompt,
"max_tokens": 8192,
"temperature": 0,
"messages": [
{
"role": "user",
"content": $input_prompt
}
]
}
EOF
)
response=$(
curl -s -X POST \
-H "x-api-key: $api_key" \
-H "Content-Type: application/json" \
-H "anthropic-version: $anthropic_version" \
-d "$api_body" \
$api_url
)
if [ -z "$(echo $response | jq -r .content[0].text)" ]; then
echo "Error: API call failed" >&2
echo $response | jq . >&2
exit 1
fi
response_text=$(echo $response | jq -r .content[0].text)
# Drop the first and last lines, which are the ```typescript delimiters
echo "$response_text" | tail -n +2 | head -n -1 > $output_typescript_file
set +f