open_ai_rust 0.2.15

Open AI SDK for Rust. To my knowledge, the only fully comprehensive and up-to-date Open AI crate built in and for Rust. Provides both low-level control with high level ergonomics for doing cool things (the whole reason we use Rust in the first place). Is maintained and has been used and tested in products used in production.
Documentation
use core::fmt;
use std::fmt::{Display, Formatter};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;


#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ChatMessage {
    /// The role of the author of this message.
    pub role: ChatMessageRole,
    /// The contents of the message
    ///
    /// This is always required for all messages, except for when ChatGPT calls
    /// a function.
    pub content: String,
    /// The name of the user in a multi-user chat
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
}

#[derive(Deserialize, Serialize, Debug, Clone, Copy, ToSchema)]
#[serde(rename_all = "lowercase")]
pub enum ChatMessageRole {
    System,
    User,
    Assistant,
    Function,
}

impl From<String> for ChatMessageRole {
    fn from(role: String) -> Self {
        match role.as_str() {
            "system" => ChatMessageRole::System,
            "user" => ChatMessageRole::User,
            "assistant" => ChatMessageRole::Assistant,
            "function" => ChatMessageRole::Function,
            _ => ChatMessageRole::User,
        }
    }
}

impl Display for ChatMessageRole {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}