-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathgenerate-workflow
More file actions
executable file
·102 lines (90 loc) · 2.53 KB
/
generate-workflow
File metadata and controls
executable file
·102 lines (90 loc) · 2.53 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /bin/bash
usage="Usage: $0 <input-prompt-json> <output-typescript-file>"
input_prompt_json=$1
output_typescript_file=$2
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)
# Select LLM provider based on available API keys.
# Anthropic (Claude) is preferred when both keys are set.
# MiniMax is used as a fallback via its OpenAI-compatible API.
if [ -n "$ANTHROPIC_API_KEY" ]; then
provider="anthropic"
api_key="$ANTHROPIC_API_KEY"
api_url="https://api.anthropic.com/v1/messages"
model_id="claude-sonnet-4-20250514"
anthropic_version="2023-06-01"
elif [ -n "$MINIMAX_API_KEY" ]; then
provider="minimax"
api_key="$MINIMAX_API_KEY"
api_url="https://api.minimax.io/v1/chat/completions"
model_id="MiniMax-M2.7"
else
echo "Please set the ANTHROPIC_API_KEY or MINIMAX_API_KEY environment variable" >&2
exit 1
fi
if [ "$provider" = "minimax" ]; then
# MiniMax uses the OpenAI-compatible API format.
# temperature must be in (0.0, 1.0] for MiniMax; 0.01 gives near-deterministic output.
api_body=$(
cat <<EOF
{
"model": "$model_id",
"messages": [
{"role": "system", "content": $system_prompt},
{"role": "user", "content": $input_prompt}
],
"max_tokens": 8192,
"temperature": 0.01
}
EOF
)
response=$(
curl -s -X POST \
-H "Authorization: Bearer $api_key" \
-H "Content-Type: application/json" \
-d "$api_body" \
"$api_url"
)
response_text=$(echo "$response" | jq -r '.choices[0].message.content // empty')
else
# Anthropic API format
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"
)
response_text=$(echo "$response" | jq -r '.content[0].text // empty')
fi
if [ -z "$response_text" ]; then
echo "Error: API call failed" >&2
echo "$response" | jq . >&2
exit 1
fi
# Strip code-block delimiters if the model wrapped the output in ``` fences.
first_line=$(echo "$response_text" | head -n 1)
if [[ "$first_line" == '```'* ]]; then
echo "$response_text" | tail -n +2 | head -n -1 > "$output_typescript_file"
else
echo "$response_text" > "$output_typescript_file"
fi
set +f