pub mod library;
pub use library::{ModelComponents, ModelLibrary, ResolvedModel};
use serde::{Deserialize, Serialize};
use crate::schema::ManifestId;
use crate::schema::{Hash, SchemaRef};
use crate::typed::TypedPayload;
const MODEL_MANIFEST_SCHEMA_PAYLOAD: &[u8] = br#"{"format":"mere-native","schema_id":"eidetic.ModelManifest/v1","body":{"version":1,"description":"Manifest for a machine-learning model.","required":["model_id","architecture","weight_blob","tokenizer_blob"],"fields":{"model_id":{"type":"string"},"architecture":{"type":"string"},"license":{"type":"string"},"config":{"type":"object"},"weight_blob":{"type":"string"},"tokenizer_blob":{"type":"string"}}}}"#;
pub static MODEL_MANIFEST_SCHEMA_REF: std::sync::LazyLock<SchemaRef> =
std::sync::LazyLock::new(|| {
SchemaRef::from_id(ManifestId::from_hash(Hash::of(
MODEL_MANIFEST_SCHEMA_PAYLOAD,
)))
});
const OPAQUE_BLOB_SCHEMA_PAYLOAD: &[u8] = br#"{"format":"mere-native","schema_id":"eidetic.OpaqueBlob/v1","body":{"version":1,"description":"An uninterpreted byte buffer.","required":["bytes"],"fields":{"bytes":{"type":"string"}}}}"#;
pub static OPAQUE_BLOB_SCHEMA_REF: std::sync::LazyLock<SchemaRef> =
std::sync::LazyLock::new(|| {
SchemaRef::from_id(ManifestId::from_hash(Hash::of(OPAQUE_BLOB_SCHEMA_PAYLOAD)))
});
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ModelManifest {
pub model_id: String,
pub architecture: String,
#[serde(default)]
pub license: Option<String>,
pub config: serde_json::Value,
pub weight_blob: ManifestId,
pub tokenizer_blob: ManifestId,
}
impl TypedPayload for ModelManifest {
fn schema_ref() -> SchemaRef {
*MODEL_MANIFEST_SCHEMA_REF
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct OpaqueBlob(pub Vec<u8>);
impl TypedPayload for OpaqueBlob {
fn schema_ref() -> SchemaRef {
*OPAQUE_BLOB_SCHEMA_REF
}
fn serialize_to_bytes(&self) -> crate::Result<Vec<u8>> {
Ok(self.0.clone())
}
fn deserialize_from_bytes(bytes: &[u8]) -> crate::Result<Self> {
Ok(OpaqueBlob(bytes.to_vec()))
}
}