[feat] added horde support, added spec2 requirements that didn't implemented

This commit is contained in:
kwaroran
2023-05-24 08:49:35 +09:00
parent 022f70f214
commit a999d6d780
9 changed files with 214 additions and 62 deletions

34
src/ts/horde/getModels.ts Normal file
View File

@@ -0,0 +1,34 @@
import { sleep } from "../util"
let modelList:string[]|'loading' = null
//until horde is ready
modelList = []
export async function getHordeModels():Promise<string[]> {
if(modelList === null){
try {
modelList = 'loading'
const models = await fetch("https://stablehorde.net/api/v2/status/models?type=text")
modelList = ((await models.json()).map((a) => {
return a.name
}) as string[])
return modelList
} catch (error) {
modelList = null
return []
}
}
else if(modelList === 'loading'){
while(true){
if(modelList !== 'loading'){
return getHordeModels()
}
await sleep(10)
}
}
else{
return modelList
}
}