-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenai_thread_run
More file actions
executable file
·58 lines (51 loc) · 1.31 KB
/
openai_thread_run
File metadata and controls
executable file
·58 lines (51 loc) · 1.31 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
# Ensure required environment variables are set
for var in OPENAI_THREAD_ID OPENAI_API_KEY OPENAI_ASSISTANT_ID; do
if [ -z "${!var}" ]; then
echo "Error: $var is not set."
exit 1
fi
done
# Set the endpoint URL
URL="https://api.openai.com/v1/threads/$OPENAI_THREAD_ID/runs"
# Define function_tool JSON using jq
function_tool=$(jq -n '{
name: "execute_command",
description: "Execute a command in a UNIX shell",
strict: true,
parameters: {
type: "object",
properties: {
cmd: {
type: "string",
description: "The command to run"
}
},
required: ["cmd"],
additionalProperties: false
}
}')
# Create full JSON payload using jq
json_payload=$(jq -n \
--arg assistant_id "$OPENAI_ASSISTANT_ID" \
'{
assistant_id: $assistant_id,
tools: [
{type: "file_search"},
{type: "code_interpreter"}
]
}')
# Perform the POST request with the correctly formatted JSON
response=$(curl -s "$URL" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v2" \
-d "$json_payload")
# Check for errors in response
if echo "$response" | grep -q '"error"'; then
echo "Error retrieving thread: $response"
exit 1
fi
# Output the response
echo "Thread retrieved successfully:"
echo "$response"