async_openai/
steps.rs

1use serde::Serialize;
2
3use crate::{
4    config::Config,
5    error::OpenAIError,
6    types::{ListRunStepsResponse, RunStepObject},
7    Client,
8};
9
10/// Represents a step in execution of a run.
11pub struct Steps<'c, C: Config> {
12    pub thread_id: String,
13    pub run_id: String,
14    client: &'c Client<C>,
15}
16
17impl<'c, C: Config> Steps<'c, C> {
18    pub fn new(client: &'c Client<C>, thread_id: &str, run_id: &str) -> Self {
19        Self {
20            client,
21            thread_id: thread_id.into(),
22            run_id: run_id.into(),
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(&format!(
31                "/threads/{}/runs/{}/steps/{step_id}",
32                self.thread_id, self.run_id
33            ))
34            .await
35    }
36
37    /// Returns a list of run steps belonging to a run.
38    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
39    pub async fn list<Q>(&self, query: &Q) -> Result<ListRunStepsResponse, OpenAIError>
40    where
41        Q: Serialize + ?Sized,
42    {
43        self.client
44            .get_with_query(
45                &format!("/threads/{}/runs/{}/steps", self.thread_id, self.run_id),
46                &query,
47            )
48            .await
49    }
50}