|
|
|
@ -36,7 +36,8 @@ class HuggingFaceAI {
|
|
|
|
|
this.memory = db.history ? db.history.map((m) => `${m.name}: "${m.content}"`) : [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async #query(prompt: string) {
|
|
|
|
|
//TODO: type our response object
|
|
|
|
|
async #query(prompt: string): Promise<Record<string, string>[]> {
|
|
|
|
|
const res = await fetch(`https://api-inference.huggingface.co/models/${this.model}`, {
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
inputs: prompt,
|
|
|
|
@ -51,7 +52,14 @@ class HuggingFaceAI {
|
|
|
|
|
if (this.tokenNum > this.tokens.length - 1) {
|
|
|
|
|
this.tokenNum = 0
|
|
|
|
|
}
|
|
|
|
|
return await res.json();
|
|
|
|
|
|
|
|
|
|
const jsonRes = await res.json();
|
|
|
|
|
if (!jsonRes[0].generated_text) {
|
|
|
|
|
console.log(jsonRes)
|
|
|
|
|
console.warn("Retrying generation with new token...")
|
|
|
|
|
return await this.#query(prompt) // bound to go well
|
|
|
|
|
}
|
|
|
|
|
return jsonRes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
|