Skip to main content

floopy/resources/
feedback.rs

1use std::sync::Arc;
2
3use reqwest::Method;
4
5use crate::constants::ENDPOINT_FEEDBACK;
6use crate::error::Result;
7use crate::http::HttpTransport;
8use crate::options::RequestOptions;
9use crate::types::{FeedbackSubmitParams, FeedbackSubmitResponse};
10
11use super::require;
12
13/// Submits feedback for a completed request or session.
14pub struct Feedback {
15    t: Arc<HttpTransport>,
16}
17
18impl Feedback {
19    pub(crate) fn new(t: Arc<HttpTransport>) -> Self {
20        Self { t }
21    }
22
23    /// Submit feedback. `session_id` is usually the chat completion id.
24    ///
25    /// # Errors
26    /// Returns an [`Error`](crate::Error) on a non-2xx response or transport
27    /// failure.
28    pub async fn submit(
29        &self,
30        params: FeedbackSubmitParams,
31        req: impl Into<Option<RequestOptions>>,
32    ) -> Result<FeedbackSubmitResponse> {
33        let body =
34            serde_json::to_value(&params).map_err(|e| crate::Error::Decode(e.to_string()))?;
35        let (data, _) = self
36            .t
37            .request(
38                Method::POST,
39                ENDPOINT_FEEDBACK,
40                Some(&body),
41                &[],
42                req.into().as_ref(),
43            )
44            .await?;
45        require(data)
46    }
47}