openai-interface 0.10.0

A low-level Rust interface for the OpenAI API
Documentation
//! Retrieve an eval run via `GET /evals/{eval_id}/runs/{run_id}`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.

use url::Url;

use crate::{
    errors::OapiError,
    evals::runs::EvalRun,
    rest::get::{Get, GetNoStream},
};

/// Retrieves an eval run by its ID.
#[derive(Debug, Clone)]
pub struct RetrieveEvalRunRequest<'a> {
    /// The ID of the eval, e.g. `eval_...`.
    pub eval_id: &'a str,
    /// The ID of the run to retrieve, e.g. `evalrun_...`.
    pub run_id: &'a str,
}

impl Get for RetrieveEvalRunRequest<'_> {
    /// Builds the URL for the request.
    ///
    /// `base_url` should be like <https://api.openai.com/v1>
    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
        url.path_segments_mut()
            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
            .push("evals")
            .push(self.eval_id)
            .push("runs")
            .push(self.run_id);
        Ok(url.to_string())
    }
}

impl GetNoStream for RetrieveEvalRunRequest<'_> {
    type Response = EvalRun;
}