Readme
This is a very simple model that takes a string as input and returns a string with “hello” prepended to the input.
It runs fully on Rust (no Python or Go used anywhere), which is pretty cool I’d say. Here’s the source:
use cog_rust::Cog;
use anyhow::Result;
use schemars::JsonSchema;
use async_trait::async_trait;
#[derive(serde::Deserialize, JsonSchema)]
struct ModelRequest {
/// Text to prefix with 'hello '
text: String,
}
struct ExampleModel {
prefix: String,
}
#[async_trait]
impl Cog for ExampleModel {
type Request = ModelRequest;
type Response = String;
async fn setup() -> Result<Self> {
Ok(Self {
prefix: "hello".to_string(),
})
}
fn predict(&self, input: Self::Request) -> Result<Self::Response> {
Ok(format!("{} {}", self.prefix, input.text))
}
}
cog_rust::start!(ExampleModel);