gpt_batch_scribe/
gpt_message.rs

1crate::ix!();
2
3/// Individual message details in the request body.
4#[derive(Debug, Serialize, Deserialize)]
5pub struct GptMessage {
6    /// Role of the participant (system/user).
7    #[serde(with = "message_role")]
8    role: GptMessageRole,
9    /// Content of the message.
10    content: ChatCompletionRequestUserMessageContent,
11}
12
13impl GptMessage {
14
15    pub fn system_message(msg: &str) -> Self {
16        Self {
17            role:    GptMessageRole::System,
18            content: ChatCompletionRequestUserMessageContent::Text(msg.to_string()),
19        }
20    }
21
22    pub fn user_message(msg: &str) -> Self {
23        Self {
24            role:    GptMessageRole::User,
25            content: ChatCompletionRequestUserMessageContent::Text(msg.to_string()),
26        }
27    }
28
29    pub fn user_message_with_image(msg: &str, image_b64: &str) -> Self {
30
31        Self {
32            role:    GptMessageRole::User,
33            content: ChatCompletionRequestUserMessageContent::Array(vec![
34                ChatCompletionRequestMessageContentPart::Text(msg.into()),
35                ChatCompletionRequestMessageContentPart::ImageUrl(ChatCompletionRequestMessageContentPartImage {
36                    image_url: ImageUrl {
37                        url:    image_b64.to_string(),
38                        detail: Some(ImageDetail::High),
39                    }
40                }),
41            ]),
42        }
43    }
44}