I want to start this off with the fact that I am very new to this and am probably the stupidest person in this forum, so I’m sorry if i waste anyone’s time:)
I am trying to create an AI chatbot in my Unity game. I followed along with a tutorial I found, but seem to have hit a wall.
The other example scenes work fine - I can generate images well. However, the conversation example scene keeps shooting errors my way. I have tried my best to fix them, but from what I can find its to do with a change in how Hugging Face classifies its models - there is no longer conversation models, but i think they are now classified as Text Generation. Here are the errors which pop up when i try to message the chatbot in engine -
If someone could please guide me as to what to do to fix this, it would really be appreciated! Sorry again if im just being a massive idiot :))
3 Likes
I wonder if Unity means JavaScript or C#…? My knowledge is a bit out of date, so I might be wrong, but basically you can call it from JavaScript using this method.
However, sometimes these official sample methods don’t work, and in such cases, try tweaking the code a little. Sometimes it works unexpectedly. This is because of specification changes or because these codes are automatically generated, so there are cases where they differ from the actual specifications.
If there are samples on the model card, they are often written manually, so they are correct in many cases.
import { InferenceClient } from "@huggingface/inference";
const client = new InferenceClient("hf_xxxxxxxxxxxxxxxxxxxxxxxx");
const output = await client.textGeneration({
model: "facebook/blenderbot-400M-distill",
inputs: "The answer to the universe is",
provider: "hf-inference",
});
console.log(output);
or
async function query(data) {
const response = await fetch(
"https://router.huggingface.co/hf-inference/models/facebook/blenderbot-400M-distill",
{
headers: {
Authorization: "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
}
query({"inputs": "The answer to the universe is"}).then((response) => {
console.log(JSON.stringify(response));
});