use std::borrow::Cow;
use hyper::{Body, Request};
use serde::Serialize;
use crate::endpoints::request::Endpoint;
#[derive(Debug, Clone, Serialize)]
pub struct Edit<'a> {
pub input: Cow<'a, str>,
pub instruction: Cow<'a, str>,
pub temperature: f32,
pub top_p: f32,
}
impl Default for Edit<'_> {
fn default() -> Self {
Self {
input: Cow::Borrowed(""),
instruction: Cow::Borrowed(""),
temperature: 0.,
top_p: 0.
}
}
}
impl Endpoint for Edit<'_> {
const ENDPOINT: &'static str = "https://api.openai.com/v1/engines/{}/edits";
fn request(&self, auth_token: &str, engine_id: Option<&str>) -> Request<Body> {
let endpoint = Self::ENDPOINT.replace("{}", engine_id.unwrap());
let serialized = serde_json::to_string(&self)
.expect("Failed to serialize Edit");
trace!("endpoint={}, serialized={}", endpoint, serialized);
super::request::post!(endpoint, auth_token, serialized)
}
}