You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,12 +51,30 @@ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
51
51
to add `OPENAI_API_KEY="My API Key"` to your `.env` file
52
52
so that your API Key is not stored in source control.
53
53
54
+
### Polling Helpers
55
+
56
+
When interacting with the API some actions such as starting a Run may take time to complete. The SDK includes
57
+
helper functions which will poll the status until it reaches a terminal state and then return the resulting object.
58
+
If an API method results in an action which could benefit from polling there will be a corresponding version of the
59
+
method ending in '\_and_poll'.
60
+
61
+
For instance to create a Run and poll until it reaches a terminal state you can run:
62
+
63
+
```python
64
+
run = client.beta.threads.runs.create_and_poll(
65
+
thread_id=thread.id,
66
+
assistant_id=assistant.id,
67
+
)
68
+
```
69
+
70
+
More information on the lifecycle of a Run can be found in the [Run Lifecycle Documentation](https://platform.openai.com/docs/assistants/how-it-works/run-lifecycle)
71
+
54
72
### Streaming Helpers
55
73
56
74
The SDK also includes helpers to process streams and handle the incoming events.
57
75
58
76
```python
59
-
with client.beta.threads.runs.create_and_stream(
77
+
with client.beta.threads.runs.stream(
60
78
thread_id=thread.id,
61
79
assistant_id=assistant.id,
62
80
instructions="Please address the user as Jane Doe. The user has a premium account.",
0 commit comments