2023-09-13 06:06:28 +00:00
|
|
|
use crate::{
|
|
|
|
ctx::Context,
|
|
|
|
dbs::{Options, Transaction},
|
|
|
|
doc::CursorDoc,
|
|
|
|
err::Error,
|
2023-11-18 13:56:13 +00:00
|
|
|
sql::value::Value,
|
2023-09-13 06:06:28 +00:00
|
|
|
};
|
2023-11-18 13:56:13 +00:00
|
|
|
use async_recursion::async_recursion;
|
|
|
|
use derive::Store;
|
|
|
|
use revision::revisioned;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::fmt;
|
2022-05-30 15:05:05 +00:00
|
|
|
|
2023-09-13 06:06:28 +00:00
|
|
|
#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
|
2023-08-17 18:03:46 +00:00
|
|
|
#[revisioned(revision = 1)]
|
2023-09-13 06:06:28 +00:00
|
|
|
pub struct Model {
|
|
|
|
pub name: String,
|
|
|
|
pub version: String,
|
2023-10-25 11:38:03 +00:00
|
|
|
pub args: Vec<Value>,
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 06:06:28 +00:00
|
|
|
impl fmt::Display for Model {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2023-10-25 11:38:03 +00:00
|
|
|
write!(f, "ml::{}<{}>(", self.name, self.version)?;
|
|
|
|
for (idx, p) in self.args.iter().enumerate() {
|
|
|
|
if idx != 0 {
|
|
|
|
write!(f, ",")?;
|
|
|
|
}
|
|
|
|
write!(f, "{}", p)?;
|
|
|
|
}
|
|
|
|
write!(f, ")")
|
2022-05-30 15:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 06:06:28 +00:00
|
|
|
impl Model {
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), async_recursion)]
|
|
|
|
#[cfg_attr(target_arch = "wasm32", async_recursion(?Send))]
|
|
|
|
pub(crate) async fn compute(
|
|
|
|
&self,
|
|
|
|
_ctx: &Context<'_>,
|
|
|
|
_opt: &Options,
|
|
|
|
_txn: &Transaction,
|
|
|
|
_doc: Option<&'async_recursion CursorDoc<'_>>,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
Err(Error::Unimplemented("ML model evaluation not yet implemented".to_string()))
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|