open_ai_rust 0.2.16

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 crate::logoi::input::tool::{FunctionCall, FunctionParameter, FunctionType};

#[derive(Debug, PartialEq)]
pub struct FunctionCallRaw<'a> {
    pub name: &'a str,
    pub description: &'a str,
    pub parameters: [&'a str; 100]
}

impl<'a> FunctionCallRaw<'a> {
    pub fn to_fn_call(self) -> Result<FunctionCall, String> {
        let name = self.name.to_string();
        let description = match self.description {
            raw if raw.len() > 0 => Some(raw.to_string()),
            _ => None
        };
        let parameters = parse_raw_params(self.parameters)?;

        return Ok(FunctionCall {
            name,
            description,
            parameters
        })
    }
}


fn parse_raw_params(parameters: [&str; 100]) -> Result<Vec<FunctionParameter>, String> {
    let mut refined_parameters: Vec<FunctionParameter> = vec![];

    for param in parameters {
        let (name, _type) = match param.split_once(':') {
            Some((name, _type)) => (name.trim(), _type.trim()),
            None => continue,
        };


        let refined_parameter = FunctionParameter {
            name: name.to_string(),
            _type: parse_raw_type(_type)?,
            description: None
        };

        refined_parameters.push(refined_parameter);
    }

    return Ok(refined_parameters)
}

fn parse_raw_type(_type: &str) -> Result<FunctionType, String> {
    match _type.to_lowercase().as_str() {
        "string" => Ok(FunctionType::String),
        "i64" | "i32" | "i16" | "i8"
        | "f64" | "f32" | "f16" | "f8"
        | "number" => Ok(FunctionType::Number),
        "bool" => Ok(FunctionType::Boolean),
        _ => return Err("Not yet supported".to_string())
    }
}