rust_chatgpt/v1/
edits.rs

1use crate::error::ChatGptError;
2use crate::v1::{convert_from_value, trim_value, ChatGptRequest};
3use serde::{Deserialize, Serialize};
4use serde_json::{json, Value};
5
6#[derive(Debug, Deserialize, Serialize, Clone)]
7pub struct ChatGptResponseEdits {
8    value: Value,
9}
10
11#[derive(Debug, Deserialize, Serialize, Clone)]
12pub struct ChatGptRequestEdits {
13    model: String,
14    input: String,
15    instruction: String,
16    n: Option<isize>,
17    temperature: Option<f32>,
18    top_p: Option<f32>,
19}
20
21impl ChatGptRequest for ChatGptRequestEdits {
22    fn from_value(value: Value) -> Result<Self, ChatGptError>
23    where
24        Self: Sized,
25    {
26        convert_from_value(value)
27    }
28
29    fn to_value(&self) -> Value {
30        trim_value(json!(self)).unwrap()
31    }
32}
33
34impl ChatGptRequestEdits {
35    pub fn new(model: &str, instruction: &str, input: &str) -> Self {
36        Self {
37            model: model.to_string(),
38            input: input.to_string(),
39            instruction: instruction.to_string(),
40            n: None,
41            temperature: None,
42            top_p: None,
43        }
44    }
45}