-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_openai.sh
executable file
·62 lines (50 loc) · 1.97 KB
/
test_openai.sh
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
#!/bin/bash
set -eu
# -----------------------------------------------------------------------
# Test using OpenAL API using curl.
# *THIS IS NOT A SCRIPT TO BE RUN AS-IS*,
# you need to understand it and uncomment each part in turn -- I was too lazy
# to try to process JSONs using script.
#
# Refs:
# https://platform.openai.com/docs/api-reference/messages/listMessages
# v2: https://platform.openai.com/docs/assistants/migration
# docs: https://platform.openai.com/docs/assistants/overview?context=without-streaming
# -----------------------------------------------------------------------
# Fill this with your rel API key and assistant id.
OPENAI_API_KEY='...'
OPENAI_ASSISTANT_ID='...'
# curl https://api.openai.com/v1/threads \
# -H "Content-Type: application/json" \
# -H "Authorization: Bearer $OPENAI_API_KEY" \
# -H "OpenAI-Beta: assistants=v2" \
# -d ''
# Get id from JSON response above
THREAD_ID='thread_...'
# curl https://api.openai.com/v1/threads/${THREAD_ID}/messages \
# -H "Content-Type: application/json" \
# -H "Authorization: Bearer $OPENAI_API_KEY" \
# -H "OpenAI-Beta: assistants=v2" \
# -d '{
# "role": "user",
# "content": "What is 2 + 2, add a cat joke."
# }'
MESSAGE_ID='msg_...'
# curl https://api.openai.com/v1/threads/${THREAD_ID}/runs \
# -H "Authorization: Bearer $OPENAI_API_KEY" \
# -H "Content-Type: application/json" \
# -H "OpenAI-Beta: assistants=v2" \
# -d '{
# "assistant_id": "'${OPENAI_ASSISTANT_ID}'"
# }'
RUN_ID='run_...'
# curl https://api.openai.com/v1/threads/${THREAD_ID}/runs/${RUN_ID} \
# -H "Authorization: Bearer $OPENAI_API_KEY" \
# -H "OpenAI-Beta: assistants=v2"
# The above needs to be repeated until the run has status: completed.
# Then list messages:
# curl https://api.openai.com/v1/threads/${THREAD_ID}/messages?limit=1 \
# -H "Content-Type: application/json" \
# -H "Authorization: Bearer $OPENAI_API_KEY" \
# -H "OpenAI-Beta: assistants=v2"
# The last answer is in 1st item of above.