UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

54 lines 2.11 kB
import { getDocstore, createDocstoreClient } from "./index.js"; import { debugError, enableAllDebug } from "../../../common/debug.js"; /** * Get a document by ID * @param id Document ID * @param options Command options */ export async function getDoc(id, options) { try { // Enable debug output if debug flag is set if (options.debug) { enableAllDebug(); } const docstoreClient = await createDocstoreClient(options); const docstore = await getDocstore(docstoreClient, options.docstore); // Use the get method to retrieve the document const foundDoc = await docstoreClient.get(docstore.id, id); if (foundDoc) { console.log(`Document ID: ${foundDoc.id}`); console.log(`Docstore ID: ${foundDoc.docstore_id}`); console.log(`Type: ${foundDoc.type}`); console.log(`Created at: ${new Date(foundDoc.created_at * 1000).toISOString()}`); console.log(`Updated at: ${new Date(foundDoc.timestamp * 1000).toISOString()}`); console.log("Data:"); console.log(foundDoc.data); console.log("Embeddings:"); console.log(foundDoc.embeddings); } else { debugError(`Document with ID '${id}' not found in docstore '${docstore.id}'`); process.exit(1); } docstoreClient[Symbol.dispose](); } catch (error) { debugError(`Error getting document: ${error}`); process.exit(1); } } /** * Register the get command * @param docstoreCommand The parent docstore command * @param addPathOption Function to add path option to command */ export function registerGetCommand(docstoreCommand, addCommonOptions) { const getCommand = docstoreCommand .command("get") .description("Get a document by ID") .argument("<id>", "ID of the document to get") .option("-s, --docstore <id>", "ID of the docstore (required if more than one docstore exists)") .action(getDoc); addCommonOptions(getCommand); } //# sourceMappingURL=get.js.map