dynamo_async_openai/
steps.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use serde::Serialize;
12
13use crate::{
14    Client,
15    config::Config,
16    error::OpenAIError,
17    types::{ListRunStepsResponse, RunStepObject},
18};
19
20/// Represents a step in execution of a run.
21pub struct Steps<'c, C: Config> {
22    pub thread_id: String,
23    pub run_id: String,
24    client: &'c Client<C>,
25}
26
27impl<'c, C: Config> Steps<'c, C> {
28    pub fn new(client: &'c Client<C>, thread_id: &str, run_id: &str) -> Self {
29        Self {
30            client,
31            thread_id: thread_id.into(),
32            run_id: run_id.into(),
33        }
34    }
35
36    /// Retrieves a run step.
37    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
38    pub async fn retrieve(&self, step_id: &str) -> Result<RunStepObject, OpenAIError> {
39        self.client
40            .get(&format!(
41                "/threads/{}/runs/{}/steps/{step_id}",
42                self.thread_id, self.run_id
43            ))
44            .await
45    }
46
47    /// Returns a list of run steps belonging to a run.
48    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
49    pub async fn list<Q>(&self, query: &Q) -> Result<ListRunStepsResponse, OpenAIError>
50    where
51        Q: Serialize + ?Sized,
52    {
53        self.client
54            .get_with_query(
55                &format!("/threads/{}/runs/{}/steps", self.thread_id, self.run_id),
56                &query,
57            )
58            .await
59    }
60}