Skip to main content

ollama_rest/
models.rs

1//! Serde models
2
3use std::{fmt::Display, str::FromStr};
4
5use errors::ParsingError;
6use serde::{Deserialize, Serialize};
7
8pub mod chat;
9pub mod create;
10pub mod embeddings;
11pub mod errors;
12pub mod generate;
13pub mod json_schema;
14pub mod model;
15pub mod version;
16
17/// Request format
18#[derive(Debug, Serialize, Deserialize)]
19#[serde(rename_all = "lowercase")]
20pub enum RequestFormat {
21    /// JSON
22    ///
23    /// Currently the one and only format support by Ollama
24    Json,
25}
26
27impl Display for RequestFormat {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(f, "{}", match self {
30            Self::Json => "json",
31        })
32    }
33}
34
35impl FromStr for RequestFormat {
36    type Err = ParsingError;
37
38    fn from_str(s: &str) -> Result<Self, Self::Err> {
39        Ok(match s {
40            "json" => Self::Json,
41            _ => Err(ParsingError::InvalidStr)?,
42        })
43    }
44}
45
46/// Status message
47#[derive(Debug, Serialize, Deserialize)]
48pub struct Status {
49    pub status: String,
50}