Back
Version 31
7/10/2024
/** @jsxImportSource npm:react **/
import process from "node:process";
import { renderToString } from "npm:react-dom@18/server";
import { QueryVectorStore, sb, Substrate } from "npm:substrate";
type ShotResult = {
id: string;
distance: number;
metadata: {
doc: string; // base64 img data
doc_id: string;
};
};
async function getResults(q: string, n: number): Promise<ShotResult[]> {
const substrate = new Substrate({
apiKey: process.env.SUBSTRATE_API_KEY,
});
const collectionName = "shotclip";
const query = new QueryVectorStore({
collection_name: collectionName,
model: "clip",
query_strings: [q],
include_metadata: true,
top_k: n,
});
const res = await substrate.run(query);
console.log(q, res.get(query).results[0]);
return res.get(query).results[0] as ShotResult[];
}
export default async (req: Request) => {
const searchParams = new URL(req.url).searchParams;
const { prompt = "tarantino", n = 12 } = Object.fromEntries(searchParams);
const res = await getResults(prompt, Number(n));
kousun12-shotclip.web.val.run
Updated: July 10, 2024