async_openai/
steps.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::assistants::{ListRunStepsResponse, RunStepObject},
5    Client, RequestOptions,
6};
7
8/// Represents a step in execution of a run.
9pub struct Steps<'c, C: Config> {
10    pub thread_id: String,
11    pub run_id: String,
12    client: &'c Client<C>,
13    pub(crate) request_options: RequestOptions,
14}
15
16impl<'c, C: Config> Steps<'c, C> {
17    pub fn new(client: &'c Client<C>, thread_id: &str, run_id: &str) -> Self {
18        Self {
19            client,
20            thread_id: thread_id.into(),
21            run_id: run_id.into(),
22            request_options: RequestOptions::new(),
23        }
24    }
25
26    /// Retrieves a run step.
27    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
28    pub async fn retrieve(&self, step_id: &str) -> Result<RunStepObject, OpenAIError> {
29        self.client
30            .get(
31                &format!(
32                    "/threads/{}/runs/{}/steps/{step_id}",
33                    self.thread_id, self.run_id
34                ),
35                &self.request_options,
36            )
37            .await
38    }
39
40    /// Returns a list of run steps belonging to a run.
41    #[crate::byot(R = serde::de::DeserializeOwned)]
42    pub async fn list(&self) -> Result<ListRunStepsResponse, OpenAIError> {
43        self.client
44            .get(
45                &format!("/threads/{}/runs/{}/steps", self.thread_id, self.run_id),
46                &self.request_options,
47            )
48            .await
49    }
50}