mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
saving
This commit is contained in:
parent
e8c7a4f6e0
commit
ffd97375a8
160 changed files with 6704 additions and 1895 deletions
|
|
@ -24,15 +24,15 @@ export function registerAgentCommands(program: Command): void {
|
|||
question,
|
||||
(chunk) => {
|
||||
// think — show thought process
|
||||
if (chunk) process.stderr.write(chunk);
|
||||
if (chunk.length > 0) process.stderr.write(chunk);
|
||||
},
|
||||
(chunk) => {
|
||||
// observe — show observations
|
||||
if (chunk) process.stderr.write(chunk);
|
||||
if (chunk.length > 0) process.stderr.write(chunk);
|
||||
},
|
||||
(chunk, complete) => {
|
||||
// answer — print to stdout
|
||||
if (chunk) process.stdout.write(chunk);
|
||||
if (chunk.length > 0) process.stdout.write(chunk);
|
||||
if (complete) {
|
||||
process.stdout.write("\n");
|
||||
resolve();
|
||||
|
|
|
|||
|
|
@ -58,8 +58,9 @@ export function registerFlowCommands(program: Command): void {
|
|||
|
||||
try {
|
||||
const flows = socket.flows();
|
||||
const params = cmdOpts.parameters
|
||||
? JSON.parse(cmdOpts.parameters as string)
|
||||
const rawParameters = cmdOpts.parameters as string | undefined;
|
||||
const params = rawParameters !== undefined && rawParameters.length > 0
|
||||
? JSON.parse(rawParameters)
|
||||
: undefined;
|
||||
const resp = await flows.startFlow(
|
||||
id,
|
||||
|
|
|
|||
|
|
@ -21,13 +21,14 @@ export function registerGraphRagCommands(program: Command): void {
|
|||
|
||||
try {
|
||||
const flow = socket.flow(opts.flow);
|
||||
const collection = cmdOpts.collection as string | undefined;
|
||||
const response = await flow.graphRag(
|
||||
query,
|
||||
{
|
||||
entityLimit: parseInt(cmdOpts.entityLimit, 10),
|
||||
tripleLimit: parseInt(cmdOpts.tripleLimit, 10),
|
||||
},
|
||||
cmdOpts.collection,
|
||||
collection,
|
||||
);
|
||||
console.log(response);
|
||||
} finally {
|
||||
|
|
@ -47,10 +48,14 @@ export function registerGraphRagCommands(program: Command): void {
|
|||
|
||||
try {
|
||||
const flow = socket.flow(opts.flow);
|
||||
const docLimit = cmdOpts.docLimit as string | undefined;
|
||||
const collection = cmdOpts.collection as string | undefined;
|
||||
const response = await flow.documentRag(
|
||||
query,
|
||||
cmdOpts.docLimit ? parseInt(cmdOpts.docLimit, 10) : undefined,
|
||||
cmdOpts.collection,
|
||||
docLimit !== undefined && docLimit.length > 0
|
||||
? parseInt(docLimit, 10)
|
||||
: undefined,
|
||||
collection,
|
||||
);
|
||||
console.log(response);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,15 @@
|
|||
* Manages documents stored in the TrustGraph library.
|
||||
*/
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
import { basename } from "node:path";
|
||||
import type { Command } from "commander";
|
||||
import { createSocket, getOpts } from "./util.js";
|
||||
|
||||
function basenamePath(filepath: string): string {
|
||||
const normalized = filepath.replace(/\/+$/, "");
|
||||
const index = normalized.lastIndexOf("/");
|
||||
return index >= 0 ? normalized.slice(index + 1) : normalized;
|
||||
}
|
||||
|
||||
/** Simple MIME-type lookup by file extension. */
|
||||
function guessMimeType(filepath: string): string {
|
||||
const ext = filepath.split(".").pop()?.toLowerCase();
|
||||
|
|
@ -69,10 +73,10 @@ export function registerLibraryCommands(program: Command): void {
|
|||
|
||||
try {
|
||||
const lib = socket.librarian();
|
||||
const data = readFileSync(file);
|
||||
const b64 = data.toString("base64");
|
||||
const data = new Uint8Array(await Bun.file(file).arrayBuffer());
|
||||
const b64 = Buffer.from(data).toString("base64");
|
||||
const mimeType = (cmdOpts.mimeType as string | undefined) ?? guessMimeType(file);
|
||||
const title = (cmdOpts.title as string | undefined) ?? basename(file);
|
||||
const title = (cmdOpts.title as string | undefined) ?? basenamePath(file);
|
||||
const comments = cmdOpts.comments as string;
|
||||
const tags: string[] = (cmdOpts.tags as string[] | undefined) ?? [];
|
||||
|
||||
|
|
|
|||
|
|
@ -23,14 +23,17 @@ export function registerTriplesCommands(program: Command): void {
|
|||
|
||||
try {
|
||||
const flow = socket.flow(opts.flow);
|
||||
const s: Term | undefined = cmdOpts.subject
|
||||
? { t: "i", i: cmdOpts.subject as string }
|
||||
const subject = cmdOpts.subject as string | undefined;
|
||||
const predicate = cmdOpts.predicate as string | undefined;
|
||||
const object = cmdOpts.object as string | undefined;
|
||||
const s: Term | undefined = subject !== undefined && subject.length > 0
|
||||
? { t: "i", i: subject }
|
||||
: undefined;
|
||||
const p: Term | undefined = cmdOpts.predicate
|
||||
? { t: "i", i: cmdOpts.predicate as string }
|
||||
const p: Term | undefined = predicate !== undefined && predicate.length > 0
|
||||
? { t: "i", i: predicate }
|
||||
: undefined;
|
||||
const o: Term | undefined = cmdOpts.object
|
||||
? { t: "i", i: cmdOpts.object as string }
|
||||
const o: Term | undefined = object !== undefined && object.length > 0
|
||||
? { t: "i", i: object }
|
||||
: undefined;
|
||||
|
||||
const triples = await flow.triplesQuery(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export interface CliOpts {
|
|||
export function getOpts(cmd: Command): CliOpts {
|
||||
// Walk up to root command to get global options
|
||||
let root = cmd;
|
||||
while (root.parent) root = root.parent;
|
||||
while (root.parent !== null) root = root.parent;
|
||||
return root.opts() as CliOpts;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue