mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-02 22:41:01 +02:00
28 lines
922 B
TypeScript
28 lines
922 B
TypeScript
/**
|
|
* Embeddings CLI commands.
|
|
*
|
|
* Generate text embeddings using the configured embedding model.
|
|
*/
|
|
|
|
import { Effect } from "effect";
|
|
import * as Argument from "effect/unstable/cli/Argument";
|
|
import * as Command from "effect/unstable/cli/Command";
|
|
import { cliCommandError, withSocket, writeJson } from "./util.js";
|
|
|
|
export const embeddingsCommand = Command.make("embeddings", {
|
|
texts: Argument.string("text").pipe(
|
|
Argument.withDescription("Text(s) to embed"),
|
|
Argument.variadic({ min: 1 }),
|
|
),
|
|
}, ({ texts }) =>
|
|
withSocket((socket, opts) =>
|
|
Effect.gen(function* () {
|
|
const flow = socket.flow(opts.flow);
|
|
const vectors = yield* Effect.tryPromise({
|
|
try: () => flow.embeddings(Array.from(texts)),
|
|
catch: (error) => cliCommandError("embeddings", error),
|
|
});
|
|
yield* writeJson(vectors);
|
|
}),
|
|
),
|
|
).pipe(Command.withDescription("Generate text embeddings"));
|