Trait kalosm_language_model::SyncModel
source · pub trait SyncModel {
type Session: Session;
// Required methods
fn new_session(&self) -> Result<Self::Session>;
fn feed_text(
&self,
session: &mut Self::Session,
prompt: &str,
top_k: Option<usize>
) -> Result<Logits>;
fn feed_tokens(
&self,
session: &mut Self::Session,
tokens: &[u32],
top_k: Option<usize>
) -> Result<Logits>;
fn stop_token(&self) -> Result<u32>;
fn tokenizer(&self) -> Arc<dyn Tokenizer + Send + Sync>;
}
Expand description
A raw interface for a model that can be used to generate text synchronously. This provides a very low level interface to a model’s session:
§Example
use rphi::prelude::*;
use kalosm_language_model::Model;
#[tokio::main]
async fn main() {
let mut llm = Phi::start().await;
let tokenizer = llm.tokenizer();
// Start a sync task on the model
llm.run_sync(move |llm: &mut <Phi as Model>::SyncModel| {
Box::pin(async move {
let question = "What is 10 + 10?";
// Create a new session of the model
let mut session = llm.new_session().unwrap();
// Feed the question into the model
let mut logits = llm.feed_text(&mut session, question, None).unwrap();
println!("logits: {:?}", logits);
})
})
.unwrap();
}
Required Associated Types§
Required Methods§
sourcefn new_session(&self) -> Result<Self::Session>
fn new_session(&self) -> Result<Self::Session>
Create a new session for this model.
sourcefn feed_text(
&self,
session: &mut Self::Session,
prompt: &str,
top_k: Option<usize>
) -> Result<Logits>
fn feed_text( &self, session: &mut Self::Session, prompt: &str, top_k: Option<usize> ) -> Result<Logits>
Run the model synchronously. The model implementation may choose to return only the top k logits.
sourcefn feed_tokens(
&self,
session: &mut Self::Session,
tokens: &[u32],
top_k: Option<usize>
) -> Result<Logits>
fn feed_tokens( &self, session: &mut Self::Session, tokens: &[u32], top_k: Option<usize> ) -> Result<Logits>
Run the model synchronously with a pre-tokenized input. The model implementation may choose to return only the top k logits.
sourcefn stop_token(&self) -> Result<u32>
fn stop_token(&self) -> Result<u32>
Get the token ID that represents the end of a sequence.