Skip to content

Commit

Permalink
Merge pull request #46 from tensorlakeai/feat/analytics-api
Browse files Browse the repository at this point in the history
feat: add analytics API
  • Loading branch information
adithyaakrishna authored Aug 1, 2024
2 parents c63b32d + 18f60f2 commit 0b1f9c8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 49 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "getindexify",
"version": "0.0.64",
"version": "0.0.65",
"description": "This is the TypeScript client for interacting with the Indexify service.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
105 changes: 60 additions & 45 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IContent,
IExtractResponse,
IExtractedMetadata,
ExtractionGraphAnalytics,
} from "./types";
import { v4 as uuidv4 } from "uuid";
import CryptoJS from "crypto-js";
Expand Down Expand Up @@ -450,6 +451,20 @@ class IndexifyClient {
return resp.data;
}

async getExtractionGraphAnalytics({
namespace,
extractionGraph,
}: {
namespace: string;
extractionGraph: string;
}): Promise<ExtractionGraphAnalytics> {
const response = await this.client.get(
`namespaces/${namespace}/extraction_graphs/${extractionGraph}/analytics`
);

return response.data;
}

async waitForExtraction(contentIds: string | string[]): Promise<void> {
const ids = Array.isArray(contentIds) ? contentIds : [contentIds];

Expand Down Expand Up @@ -525,51 +540,51 @@ class IndexifyClient {
}

async listContent(
extractionGraph: string,
namespace?: string,
params?: {
namespace: string;
extractionGraph: string;
source?: string;
ingestedContentId?: string;
parentId?: string;
labelsFilter?: string[];
startId?: string;
limit?: number;
returnTotal?: boolean;
}
): Promise<{ contentList: IContentMetadata[]; total?: number }> {
const defaultParams = {
namespace: namespace || this.namespace,
extraction_graph: extractionGraph,
return_total: false,
};

const mergedParams = {
...defaultParams,
...params,
namespace: params?.namespace || namespace || this.namespace,
extraction_graph: params?.extractionGraph || extractionGraph,
labels_filter: params?.labelsFilter,
ingested_content_id: params?.ingestedContentId,
parent_id: params?.parentId,
start_id: params?.startId,
};

const response = await this.client.get(
`extraction_graphs/${mergedParams.extraction_graph}/content`,
{ params: mergedParams }
);

const contentList = response.data.content_list.map((item: IBaseContentMetadata) =>
this.baseContentToContentMetadata(item)
);

return {
contentList,
total: mergedParams.return_total ? response.data.total : undefined
};
}
extractionGraph: string,
namespace?: string,
params?: {
namespace: string;
extractionGraph: string;
source?: string;
ingestedContentId?: string;
parentId?: string;
labelsFilter?: string[];
startId?: string;
limit?: number;
returnTotal?: boolean;
}
): Promise<{ contentList: IContentMetadata[]; total?: number }> {
const defaultParams = {
namespace: namespace || this.namespace,
extraction_graph: extractionGraph,
return_total: false,
};

const mergedParams = {
...defaultParams,
...params,
namespace: params?.namespace || namespace || this.namespace,
extraction_graph: params?.extractionGraph || extractionGraph,
labels_filter: params?.labelsFilter,
ingested_content_id: params?.ingestedContentId,
parent_id: params?.parentId,
start_id: params?.startId,
};

const response = await this.client.get(
`extraction_graphs/${mergedParams.extraction_graph}/content`,
{ params: mergedParams }
);
const contentList = response.data.content_list.map((item: IBaseContentMetadata) =>
this.baseContentToContentMetadata(item)
);

return {
contentList,
total: mergedParams.return_total ? response.data.total : undefined
};
}

async sqlQuery(query: string): Promise<any> {
const response = await this.client.post(
Expand Down
14 changes: 13 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,16 @@ export interface StateChange extends IBase {
created_at: number;
processed_at: number;
refcnt_object_id: string | null;
}
}

export interface ExtractionPolicyStatus {
pending: number;
success: number;
failure: number;
}

export interface ExtractionGraphAnalytics {
task_analytics: {
[policyName: string]: ExtractionPolicyStatus;
};
}

0 comments on commit 0b1f9c8

Please sign in to comment.