#hugging-face #inference #api #wrapper #questions #classification #emotions

huggingface_inference_rs

这个包是 hugging face Inference API 的小型封装器。

4 个版本 (2 个破坏性版本)

0.5.0 2023 年 7 月 3 日
0.4.0 2023 年 6 月 29 日
0.3.1 2023 年 6 月 28 日
0.3.0 2023 年 6 月 28 日

#758机器学习

每月 21 次下载

GPL-3.0 许可证

17KB
291

Hugging face API 封装器

这是什么?

我使用 hugging face 推理 API。我为这个 API 写了一个封装器。目前它可以检测文本中的情绪,检测文本中的地点和人,并回答关于文本的问题。

示例用途

[dependencies]
huggingface_inference_rs = "0.3.0"
tokio = { version =  "1.28.2", features = ["rt-multi-thread", "macros"] }
#[tokio::main]
async fn main() {
    let mut config = hg_api::Config::default();
    config.key = "hf_key".to_string();
    let client = hg_api::Client::new(config);
    let test_string = "This is the story of a man named Stanley. Stanley worked for a company in a big building where he was Employee #427. Employee #427's job was simple: he sat at his desk in Room 427 and he pushed buttons on a keyboard. ".to_string();
    let emotions = client.get_emotions(test_string.to_owned()).await;
    let classifications = client.get_classifications(test_string.to_owned()).await;
    let answer = client
        .get_question(
            test_string,
            "what employee number does stanly have?".to_string(),
        )
        .await;

    match emotions {
        Ok(emotions) => {
            for emotion in emotions {
                println!("{},{}", emotion.label, emotion.score);
            }
        }
        Err(e) => {
            println!("{}", e);
        }
    }
    match classifications {
        Ok(classifications) => {
            for classification in classifications {
                println!("{},{}", classification.entity_group, classification.word);
            }
        }
        Err(e) => {
            println!("{}", e);
        }
    }
    match answer {
        Ok(answer) => {
            println!("{}", answer.answer)
        }
        Err(e) => {
            println!("{}", e);
        }
    }
}

依赖关系

~8–24MB
~341K SLoC