dynamo_async_openai/
responses.rs1use crate::{
12 Client,
13 config::Config,
14 error::OpenAIError,
15 types::responses::{CreateResponse, Response, ResponseStream},
16};
17
18pub struct Responses<'c, C: Config> {
22 client: &'c Client<C>,
23}
24
25impl<'c, C: Config> Responses<'c, C> {
26 pub fn new(client: &'c Client<C>) -> Self {
28 Self { client }
29 }
30
31 #[crate::byot(
33 T0 = serde::Serialize,
34 R = serde::de::DeserializeOwned
35 )]
36 pub async fn create(&self, request: CreateResponse) -> Result<Response, OpenAIError> {
37 self.client.post("/responses", request).await
38 }
39
40 #[crate::byot(
44 T0 = serde::Serialize,
45 R = serde::de::DeserializeOwned,
46 stream = "true",
47 where_clause = "R: std::marker::Send + 'static"
48 )]
49 #[allow(unused_mut)]
50 pub async fn create_stream(
51 &self,
52 mut request: CreateResponse,
53 ) -> Result<ResponseStream, OpenAIError> {
54 #[cfg(not(feature = "byot"))]
55 {
56 if matches!(request.stream, Some(false)) {
57 return Err(OpenAIError::InvalidArgument(
58 "When stream is false, use Responses::create".into(),
59 ));
60 }
61 request.stream = Some(true);
62 }
63 Ok(self.client.post_stream("/responses", request).await)
64 }
65}