async_openai_alt/
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    pub async fn retrieve(&self, step_id: &str) -> Result<RunStepObject, OpenAIError> {
28        self.client
29            .get(&format!(
30                "/threads/{}/runs/{}/steps/{step_id}",
31                self.thread_id, self.run_id
32            ))
33            .await
34    }
35
36    /// Returns a list of run steps belonging to a run.
37    pub async fn list<Q>(&self, query: &Q) -> Result<ListRunStepsResponse, OpenAIError>
38    where
39        Q: Serialize + ?Sized,
40    {
41        self.client
42            .get_with_query(
43                &format!("/threads/{}/runs/{}/steps", self.thread_id, self.run_id),
44                query,
45            )
46            .await
47    }
48}