rust_chatgpt/v1/
audio.rs

1use crate::error::ChatGptError;
2use crate::v1::{convert_form, convert_from_value, trim_value, ChatGptRequest};
3use reqwest::multipart::Form;
4use serde::{Deserialize, Serialize};
5use serde_json::{json, Value};
6
7#[derive(Debug, Deserialize, Serialize, Clone)]
8pub struct ChatGptResponseAudioTranscriptions {
9    pub(crate) value: Value,
10}
11
12#[derive(Debug, Deserialize, Serialize, Clone)]
13pub struct ChatGptRequestAudioTranscriptions {
14    file: String,
15    model: String,
16    prompt: Option<String>,
17    response_format: Option<String>,
18    temperature: Option<f32>,
19    language: Option<String>,
20}
21
22impl From<ChatGptRequestAudioTranscriptions> for Form {
23    fn from(val: ChatGptRequestAudioTranscriptions) -> Self {
24        convert_form(val.to_value(), vec!["file".to_string()])
25    }
26}
27
28impl ChatGptRequest for ChatGptRequestAudioTranscriptions {
29    fn from_value(value: Value) -> Result<Self, ChatGptError>
30    where
31        Self: Sized,
32    {
33        convert_from_value(value)
34    }
35
36    fn to_value(&self) -> Value {
37        trim_value(json!(self)).unwrap()
38    }
39}
40
41impl ChatGptRequestAudioTranscriptions {
42    pub fn new(model: &str, file: &str) -> Self {
43        Self {
44            model: model.to_string(),
45            prompt: None,
46            response_format: None,
47            temperature: None,
48            file: file.to_string(),
49            language: None,
50        }
51    }
52}
53
54#[derive(Debug, Deserialize, Serialize, Clone)]
55pub struct ChatGptResponseAudioTranslations {
56    pub(crate) value: Value,
57}
58
59#[derive(Debug, Deserialize, Serialize, Clone)]
60pub struct ChatGptRequestAudioTranslations {
61    file: String,
62    model: String,
63    prompt: Option<String>,
64    response_format: Option<String>,
65    temperature: Option<f32>,
66}
67
68impl From<ChatGptRequestAudioTranslations> for Form {
69    fn from(val: ChatGptRequestAudioTranslations) -> Self {
70        convert_form(val.to_value(), vec!["file".to_string()])
71    }
72}
73
74impl ChatGptRequest for ChatGptRequestAudioTranslations {
75    fn from_value(value: Value) -> Result<Self, ChatGptError>
76    where
77        Self: Sized,
78    {
79        convert_from_value(value)
80    }
81
82    fn to_value(&self) -> Value {
83        trim_value(json!(self)).unwrap()
84    }
85}
86
87impl ChatGptRequestAudioTranslations {
88    pub fn new(model: &str, file: &str) -> Self {
89        Self {
90            model: model.to_string(),
91            prompt: None,
92            response_format: None,
93            temperature: None,
94            file: file.to_string(),
95        }
96    }
97}