mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-03 06:51:00 +02:00
refactor(ts): make port effect native
This commit is contained in:
parent
2868ced2d3
commit
b6759e75df
113 changed files with 4140 additions and 4554 deletions
|
|
@ -4,25 +4,25 @@
|
|||
* Generate text embeddings using the configured embedding model.
|
||||
*/
|
||||
|
||||
import type { Command } from "commander";
|
||||
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 function registerEmbeddingsCommands(program: Command): void {
|
||||
program
|
||||
.command("embeddings")
|
||||
.description("Generate text embeddings")
|
||||
.argument("<text...>", "Text(s) to embed")
|
||||
.action((texts: string[], _opts, cmd) =>
|
||||
Effect.runPromise(withSocket(cmd, (socket, opts) =>
|
||||
Effect.gen(function* () {
|
||||
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(texts),
|
||||
catch: (error) => cliCommandError("embeddings", error),
|
||||
});
|
||||
yield* writeJson(vectors);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
}
|
||||
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"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue