mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
28 lines
758 B
TypeScript
28 lines
758 B
TypeScript
|
|
/**
|
||
|
|
* Embeddings CLI commands.
|
||
|
|
*
|
||
|
|
* Generate text embeddings using the configured embedding model.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import type { Command } from "commander";
|
||
|
|
import { createSocket, getOpts } from "./util.js";
|
||
|
|
|
||
|
|
export function registerEmbeddingsCommands(program: Command): void {
|
||
|
|
program
|
||
|
|
.command("embeddings")
|
||
|
|
.description("Generate text embeddings")
|
||
|
|
.argument("<text...>", "Text(s) to embed")
|
||
|
|
.action(async (texts: string[], _opts, cmd) => {
|
||
|
|
const opts = getOpts(cmd);
|
||
|
|
const socket = await createSocket(opts);
|
||
|
|
|
||
|
|
try {
|
||
|
|
const flow = socket.flow(opts.flow);
|
||
|
|
const vectors = await flow.embeddings(texts);
|
||
|
|
console.log(JSON.stringify(vectors, null, 2));
|
||
|
|
} finally {
|
||
|
|
socket.close();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|