-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenai_thread_get
More file actions
executable file
·35 lines (28 loc) · 881 Bytes
/
openai_thread_get
File metadata and controls
executable file
·35 lines (28 loc) · 881 Bytes
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
#!/bin/bash
# Ensure OPENAI_THREAD_ID and OPENAI_API_KEY environment variables are set
if [ -z "$OPENAI_THREAD_ID" ]; then
echo "Error: OPENAI_THREAD_ID is not set."
exit 1
fi
if [ -z "$OPENAI_API_KEY" ]; then
echo "Error: OPENAI_API_KEY is not set."
exit 1
fi
limit="${1:-10}"
order="${2:-desc}"
# Set the endpoint URL
URL="https://api.openai.com/v1/threads/$OPENAI_THREAD_ID/messages?limit=$limit&order=$order"
#echo $URL
# Perform the GET request
response=$(curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
"$URL")
# Check if the response contains an error
if echo "$response" | grep -q '"error"'; then
echo "Error retrieving thread: $response"
exit 1
fi
# Output the response
echo "Thread retrieved successfully:"
echo "$response"