关于人工智能:如何安装和使用-Hugging-Face-Unity-API

23次阅读

共计 1719 个字符,预计需要花费 5 分钟才能阅读完成。

Hugging Face Unity API 提供了一个简略易用的接口,容许开发者在本人的 Unity 我的项目中不便地拜访和应用 Hugging Face AI 模型,已集成到 Hugging Face Inference API 中。本文将具体介绍 API 的装置步骤和应用办法。

装置步骤

  1. 关上您的 Unity 我的项目
  2. 导航至菜单栏的 Window -> Package Manager
  3. 在弹出窗口中,点击 +,抉择 Add Package from git URL
  4. 输出 https://github.com/huggingface/unity-api.git
  5. 装置实现后,将会弹出 Unity API 向导。如未弹出,能够手动导航至 Window -> Hugging Face API Wizard
  1. 在向导窗口输入您的 API 密钥。密钥能够在您的 Hugging Face 帐户设置 中找到或创立
  2. 输出实现后能够点击 Test API key 测试 API 密钥是否失常
  3. 如需替换应用模型,能够通过更改模型端点实现。您能够拜访 Hugging Face 网站,找到反对 Inference API 的任意模型端点,在对应页面点击 Deploy -> Inference API,复制 API_URL 字段的 url 地址
  4. 如需配置高级设置,能够拜访 unity 我的项目仓库页面 https://github.com/huggingface/unity-api 查看最新信息
  5. 如需查看 API 应用示例,能够点击 Install Examples。当初,您能够敞开 API 向导了。

API 设置实现后,您就能够从脚本中调用 API 了。让咱们来尝试一个计算文本句子类似度的例子,脚本代码如下所示:

using HuggingFace.API;

/* other code */

// Make a call to the API
void Query() {
    string inputText = "I'm on my way to the forest.";
    string[] candidates = {
        "The player is going to the city",
        "The player is going to the wilderness",
        "The player is wandering aimlessly"
    };
    HuggingFaceAPI.SentenceSimilarity(inputText, OnSuccess, OnError, candidates);
}

// If successful, handle the result
void OnSuccess(float[] result) {foreach(float value in result) {Debug.Log(value);
    }
}

// Otherwise, handle the error
void OnError(string error) {Debug.LogError(error);
}

/* other code */

反对的工作类型和自定义模型

Hugging Face Unity API 目前同样反对以下工作类型:

  • 对话 (Conversation)
  • 文本生成 (Text Generation)
  • 文生图 (Text to Image)
  • 文本分类 (Text Classification)
  • 问答 (Question Answering)
  • 翻译 (Translation)
  • 总结 (Summarization)
  • 语音辨认 (Speech Recognition)

您能够应用 HuggingFaceAPI 类提供的相应办法来实现这些工作。

如需应用您本人托管在 Hugging Face 上的自定义模型,能够在 API 向导中更改模型端点。

应用技巧

  1. 请牢记,API 通过异步形式调用,并通过回调来返回响应或错误信息。
  2. 如想放慢 API 响应速度或晋升推理性能,能够通过更改模型端点为资源需要较少的模型。

结语

Hugging Face Unity API 提供了一种简略的形式,能够将 AI 模型集成到 Unity 我的项目中。咱们心愿本教程对您有所帮忙。如果您有任何疑难,或想更多地参加 Hugging Face for Games 系列,能够来退出 Hugging Face Discord 频道!


英文原文: https://hf.co/blog/unity-api

作者: Dylan Ebert

译者: SuSung-boy

审校 / 排版: zhongdongy (阿东)

正文完
 0