This repository has been archived on 2024-01-24. You can view files and clone it, but cannot push or open issues or pull requests.
celery-search/embed.ts
2023-09-09 16:19:07 -07:00

25 lines
887 B
TypeScript

const EMBEDDING_BASE_URL = Deno.env.get("EMBEDDING_BASE_URL");
async function post(path: string, body: any): any {
const req = await fetch(`${EMBEDDING_BASE_URL}${path}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}).catch(() => null);
return await req.json().catch(() => null);
}
export async function embedText(text: string): Promise<Array<number> | null> {
const data = await post("/embed/search/text", { text });
return data?.result ?? null;
}
// export async function embedClipText(text: string): Array<number> | null {
// const data = await post("/embed/clip/text", { text });
// return data?.result ?? null;
// }
// export async function embedClipImage(url: string): Array<number> | null {
// const data = await post("/embed/clip/url?image=true", { url });
// return data?.result ?? null;
// }