-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_run_steps.py
67 lines (57 loc) · 2.01 KB
/
test_run_steps.py
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
import openai
import openai_responses
from openai_responses import OpenAIMock
from openai_responses.helpers.builders.messages import build_message
from openai_responses.helpers.builders.run_steps import build_run_step
@openai_responses.mock()
def test_list_run_steps(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
assistant = client.beta.assistants.create(
instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
name="Math Tutor",
tools=[{"type": "code_interpreter"}],
model="gpt-4-turbo",
)
thread = client.beta.threads.create()
run = client.beta.threads.runs.create(
thread.id,
assistant_id=assistant.id,
)
# NOTE: need to manually construct assistant message and run step
assistant_message = build_message(
{
"assistant_id": assistant.id,
"content": [
{
"type": "text",
"text": {
"annotations": [],
"value": "Hello! Feel free to ask me any questions.",
},
}
],
"role": "assistant",
"run_id": run.id,
"status": "completed",
"thread_id": thread.id,
}
)
run_step = build_run_step(
{
"assistant_id": assistant.id,
"thread_id": thread.id,
"run_id": run.id,
"status": "in_progress",
"type": "message_creation",
"step_details": {
"type": "message_creation",
"message_creation": {
"message_id": assistant_message.id,
},
},
}
)
openai_mock.state.beta.threads.messages.put(assistant_message)
openai_mock.state.beta.threads.runs.steps.put(run_step)
steps = client.beta.threads.runs.steps.list(run.id, thread_id=thread.id)
assert len(steps.data) == 1