ai-tube / src /app /api /generators /search /unknownObjectToLatentSearchResults.ts
jbilcke-hf's picture
jbilcke-hf HF staff
upgraded to @aitube/client 0.0.12
f24ad59
raw
history blame
868 Bytes
import { generateSeed } from "@aitube/clap"
import { parseString } from "../../parsers/parseString"
import { parseStringArray } from "../../parsers/parseStringArray"
import { LatentSearchResult, LatentSearchResults } from "./types"
export function unknownObjectToLatentSearchResults(something: any): LatentSearchResults {
let results: LatentSearchResults = []
if (Array.isArray(something)) {
results = something.map(thing => ({
label: parseString(thing && (thing?.label || thing?.title)),
summary: parseString(thing && (thing?.summary || thing?.description || thing?.synopsis)),
thumbnail: parseString(thing && (thing?.thumbnail)),
tags: parseStringArray(thing && (thing?.tag)),
seed: generateSeed(), // a seed is necessary for consistency between search results and viewer
} as LatentSearchResult))
}
return results
}