| 26 | const MODEL_NAME: &'static str = "phi4"; |
| 27 | |
| 28 | async fn load(ctx: &mut Context) -> Result<Option<Box<Self>>> { |
| 29 | let mut base = TextModelBase::load::<Transformer>(ctx, DEFAULT_EOS_TOKEN).await?; |
| 30 | |
| 31 | // Phi-4 also stops at <|end|> (end-of-turn marker) in addition to <|endoftext|>. |
| 32 | if let Some(end_id) = base.tokenizer.token_to_id("<|end|>") { |
| 33 | base.eos_token_id = Some(match base.eos_token_id.take() { |
| 34 | Some(EosTokenId::Single(id)) => EosTokenId::Multiple(vec![id, end_id]), |
| 35 | Some(EosTokenId::Multiple(mut ids)) => { |
| 36 | ids.push(end_id); |
| 37 | EosTokenId::Multiple(ids) |
| 38 | } |
| 39 | None => EosTokenId::Single(end_id), |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | let history = Phi4History::new(); |
| 44 | Ok(Some(Box::new(Self { base, history }))) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | #[async_trait] |