mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-09-11 04:14:52 +00:00
Trying to fix that flaky test.
This commit is contained in:
parent
16958fe312
commit
29fa60ec3e
@ -548,26 +548,12 @@ pub(crate) struct ErrorResponse {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Write;
|
||||
use tokenizers::Tokenizer;
|
||||
|
||||
pub(crate) async fn get_tokenizer() -> Tokenizer {
|
||||
let filename = std::path::Path::new("tokenizer.json");
|
||||
if !filename.exists() {
|
||||
let content = reqwest::get("https://huggingface.co/gpt2/raw/main/tokenizer.json")
|
||||
.await
|
||||
.unwrap()
|
||||
.bytes()
|
||||
.await
|
||||
.unwrap();
|
||||
let tmp_filename = "tokenizer.json.temp";
|
||||
let mut file = std::fs::File::create(tmp_filename).unwrap();
|
||||
file.write_all(&content).unwrap();
|
||||
// Re-check if another process has written this file maybe.
|
||||
if !filename.exists() {
|
||||
std::fs::rename(tmp_filename, filename).unwrap()
|
||||
}
|
||||
}
|
||||
Tokenizer::from_file("tokenizer.json").unwrap()
|
||||
let api = hf_hub::api::sync::Api::new().unwrap();
|
||||
let repo = api.model("gpt2".to_string());
|
||||
let filename = repo.get("tokenizer.json").unwrap();
|
||||
Tokenizer::from_file(filename).unwrap()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user