use anyhow::Result;
use async_trait::async_trait;
use core::fmt::Debug;
use schemars::JsonSchema;
use serde::{de::DeserializeOwned, Serialize};
use serde_json::Value;
use crate::http::Request;
#[async_trait]
pub trait Cog: Sized + Send {
type Request: DeserializeOwned + JsonSchema + Send;
type Response: CogResponse + Debug + JsonSchema;
async fn setup() -> Result<Self>;
fn predict(&self, input: Self::Request) -> Result<Self::Response>;
}
#[async_trait]
pub trait CogResponse: Send {
async fn into_response(self, upload_url: Request) -> Result<Value>;
}
#[async_trait]
impl<T: Serialize + Send> CogResponse for T {
async fn into_response(self, _: Request) -> Result<Value> {
Ok(serde_json::to_value(self)?)
}
}