Skip to content

Commit 7fbf58d

Browse files
committed
feature: updated route to track all usages and added usages to the frontend
1 parent d16f651 commit 7fbf58d

21 files changed

Lines changed: 604 additions & 67 deletions

clients/ts-sdk/openapi.json

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5964,7 +5964,7 @@
59645964
}
59655965
},
59665966
"/api/organization/usage/{organization_id}": {
5967-
"get": {
5967+
"post": {
59685968
"tags": [
59695969
"Organization"
59705970
],
@@ -5993,13 +5993,24 @@
59935993
}
59945994
}
59955995
],
5996+
"requestBody": {
5997+
"description": "The organization usage timeframe that you want to fetch",
5998+
"content": {
5999+
"application/json": {
6000+
"schema": {
6001+
"$ref": "#/components/schemas/GetOrganizationUsageReqPayload"
6002+
}
6003+
}
6004+
},
6005+
"required": true
6006+
},
59966007
"responses": {
59976008
"200": {
59986009
"description": "The current usage of the specified organization",
59996010
"content": {
60006011
"application/json": {
60016012
"schema": {
6002-
"$ref": "#/components/schemas/OrganizationUsageCount"
6013+
"$ref": "#/components/schemas/ExtendedOrganizationUsageCount"
60036014
}
60046015
}
60056016
}
@@ -11235,6 +11246,7 @@
1123511246
"title": "Search",
1123611247
"required": [
1123711248
"query",
11249+
"tokens",
1123811250
"event_type"
1123911251
],
1124011252
"properties": {
@@ -11284,6 +11296,12 @@
1128411296
],
1128511297
"nullable": true
1128611298
},
11299+
"tokens": {
11300+
"type": "integer",
11301+
"format": "int64",
11302+
"description": "Number of tokens used in the search",
11303+
"minimum": 0
11304+
},
1128711305
"top_score": {
1128811306
"type": "number",
1128911307
"format": "float",
@@ -11302,6 +11320,7 @@
1130211320
"title": "RAG",
1130311321
"required": [
1130411322
"user_message",
11323+
"tokens",
1130511324
"event_type"
1130611325
],
1130711326
"properties": {
@@ -11362,6 +11381,12 @@
1136211381
"description": "The search id to associate the RAG event with a search",
1136311382
"nullable": true
1136411383
},
11384+
"tokens": {
11385+
"type": "integer",
11386+
"format": "int64",
11387+
"description": "The number of tokens used for this chat",
11388+
"minimum": 0
11389+
},
1136511390
"topic_id": {
1136611391
"type": "string",
1136711392
"format": "uuid",
@@ -11476,6 +11501,87 @@
1147611501
"filter_clicked"
1147711502
]
1147811503
},
11504+
"ExtendedOrganizationUsageCount": {
11505+
"type": "object",
11506+
"required": [
11507+
"search_tokens",
11508+
"message_tokens",
11509+
"dataset_count",
11510+
"user_count",
11511+
"file_storage",
11512+
"message_count",
11513+
"search_count",
11514+
"chunk_count",
11515+
"bytes_ingested",
11516+
"tokens_ingested",
11517+
"ocr_pages_ingested",
11518+
"website_pages_scraped",
11519+
"events_ingested"
11520+
],
11521+
"properties": {
11522+
"bytes_ingested": {
11523+
"type": "integer",
11524+
"format": "int64",
11525+
"minimum": 0
11526+
},
11527+
"chunk_count": {
11528+
"type": "integer",
11529+
"format": "int32"
11530+
},
11531+
"dataset_count": {
11532+
"type": "integer",
11533+
"format": "int32"
11534+
},
11535+
"events_ingested": {
11536+
"type": "integer",
11537+
"format": "int64",
11538+
"minimum": 0
11539+
},
11540+
"file_storage": {
11541+
"type": "integer",
11542+
"format": "int64"
11543+
},
11544+
"message_count": {
11545+
"type": "integer",
11546+
"format": "int64",
11547+
"minimum": 0
11548+
},
11549+
"message_tokens": {
11550+
"type": "integer",
11551+
"format": "int64",
11552+
"minimum": 0
11553+
},
11554+
"ocr_pages_ingested": {
11555+
"type": "integer",
11556+
"format": "int64",
11557+
"minimum": 0
11558+
},
11559+
"search_count": {
11560+
"type": "integer",
11561+
"format": "int64",
11562+
"minimum": 0
11563+
},
11564+
"search_tokens": {
11565+
"type": "integer",
11566+
"format": "int64",
11567+
"minimum": 0
11568+
},
11569+
"tokens_ingested": {
11570+
"type": "integer",
11571+
"format": "int64",
11572+
"minimum": 0
11573+
},
11574+
"user_count": {
11575+
"type": "integer",
11576+
"format": "int32"
11577+
},
11578+
"website_pages_scraped": {
11579+
"type": "integer",
11580+
"format": "int64",
11581+
"minimum": 0
11582+
}
11583+
}
11584+
},
1147911585
"FieldCondition": {
1148011586
"type": "object",
1148111587
"description": "FieldCondition is a JSON object which can be used to filter chunks by a field. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.",
@@ -12192,6 +12298,19 @@
1219212298
}
1219312299
}
1219412300
},
12301+
"GetOrganizationUsageReqPayload": {
12302+
"type": "object",
12303+
"properties": {
12304+
"date_range": {
12305+
"allOf": [
12306+
{
12307+
"$ref": "#/components/schemas/DateRange"
12308+
}
12309+
],
12310+
"nullable": true
12311+
}
12312+
}
12313+
},
1219512314
"GetPagefindIndexResponse": {
1219612315
"type": "object",
1219712316
"required": [
@@ -19412,6 +19531,11 @@
1941219531
"id": {
1941319532
"type": "string",
1941419533
"format": "uuid"
19534+
},
19535+
"organization_id": {
19536+
"type": "string",
19537+
"format": "uuid",
19538+
"nullable": true
1941519539
}
1941619540
},
1941719541
"example": {

clients/ts-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"files": [
1818
"dist"
1919
],
20-
"version": "0.0.64",
20+
"version": "0.0.67",
2121
"license": "MIT",
2222
"scripts": {
2323
"lint": "eslint 'src/**/*.ts'",

clients/ts-sdk/src/types.gen.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,10 @@ export type EventTypes = {
15471547
*/
15481548
results?: Array<unknown> | null;
15491549
search_type?: ((ClickhouseSearchTypes) | null);
1550+
/**
1551+
* Number of tokens used in the search
1552+
*/
1553+
tokens: number;
15501554
/**
15511555
* The top score of the search
15521556
*/
@@ -1583,6 +1587,10 @@ export type EventTypes = {
15831587
* The search id to associate the RAG event with a search
15841588
*/
15851589
search_id?: (string) | null;
1590+
/**
1591+
* The number of tokens used for this chat
1592+
*/
1593+
tokens: number;
15861594
/**
15871595
* The topic id to associate the RAG event with a topic
15881596
*/
@@ -1640,6 +1648,22 @@ export type event_type = 'view';
16401648

16411649
export type EventTypesFilter = 'add_to_cart' | 'purchase' | 'view' | 'click' | 'filter_clicked';
16421650

1651+
export type ExtendedOrganizationUsageCount = {
1652+
bytes_ingested: number;
1653+
chunk_count: number;
1654+
dataset_count: number;
1655+
events_ingested: number;
1656+
file_storage: number;
1657+
message_count: number;
1658+
message_tokens: number;
1659+
ocr_pages_ingested: number;
1660+
search_count: number;
1661+
search_tokens: number;
1662+
tokens_ingested: number;
1663+
user_count: number;
1664+
website_pages_scraped: number;
1665+
};
1666+
16431667
/**
16441668
* FieldCondition is a JSON object which can be used to filter chunks by a field. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
16451669
*/
@@ -1910,6 +1934,10 @@ export type GetGroupsForChunksReqPayload = {
19101934
chunk_tracking_ids?: Array<(string)> | null;
19111935
};
19121936

1937+
export type GetOrganizationUsageReqPayload = {
1938+
date_range?: ((DateRange) | null);
1939+
};
1940+
19131941
export type GetPagefindIndexResponse = {
19141942
url: string;
19151943
};
@@ -4035,6 +4063,7 @@ export type WorkerEvent = {
40354063
event_data: string;
40364064
event_type: string;
40374065
id: string;
4066+
organization_id?: (string) | null;
40384067
};
40394068

40404069
export type SendCtrDataData = {
@@ -5310,13 +5339,17 @@ export type GetOrganizationUsageData = {
53105339
* The id of the organization you want to fetch the usage of.
53115340
*/
53125341
organizationId: string;
5342+
/**
5343+
* The organization usage timeframe that you want to fetch
5344+
*/
5345+
requestBody: GetOrganizationUsageReqPayload;
53135346
/**
53145347
* The organization id to use for the request
53155348
*/
53165349
trOrganization: string;
53175350
};
53185351

5319-
export type GetOrganizationUsageResponse = (OrganizationUsageCount);
5352+
export type GetOrganizationUsageResponse = (ExtendedOrganizationUsageCount);
53205353

53215354
export type GetOrganizationUsersData = {
53225355
/**
@@ -6954,13 +6987,13 @@ export type $OpenApiTs = {
69546987
};
69556988
};
69566989
'/api/organization/usage/{organization_id}': {
6957-
get: {
6990+
post: {
69586991
req: GetOrganizationUsageData;
69596992
res: {
69606993
/**
69616994
* The current usage of the specified organization
69626995
*/
6963-
200: OrganizationUsageCount;
6996+
200: ExtendedOrganizationUsageCount;
69646997
/**
69656998
* Service error relating to finding the organization's usage by id
69666999
*/

frontends/dashboard/src/analytics/components/SingleEventInfo/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ export const SingleEventQuery = (props: SingleEventQueryProps) => {
9898
let link;
9999
switch (props.event_data.request_type) {
100100
case "search":
101-
link = `/dataset/${dataset.datasetId()}/analytics/query/${props.event_data.request_id
102-
}`;
101+
link = `/dataset/${dataset.datasetId()}/analytics/query/${
102+
props.event_data.request_id
103+
}`;
103104
break;
104105
case "rag":
105-
link = `/dataset/${dataset.datasetId()}/analytics/rag/${props.event_data.request_id
106-
}`;
106+
link = `/dataset/${dataset.datasetId()}/analytics/rag/${
107+
props.event_data.request_id
108+
}`;
107109
break;
108110
case "recommendations":
109-
link = `/dataset/${dataset.datasetId()}/analytics/recommendations/${props.event_data.request_id
110-
}`;
111+
link = `/dataset/${dataset.datasetId()}/analytics/recommendations/${
112+
props.event_data.request_id
113+
}`;
111114
break;
112115
default:
113116
break;
@@ -132,10 +135,12 @@ export const SingleEventQuery = (props: SingleEventQueryProps) => {
132135
<Card title="Items">
133136
<ProductItem
134137
chunkId={
135-
(JSON.parse(props.event_data.items[0]) as { chunk_id: string }).chunk_id
138+
(JSON.parse(props.event_data.items[0]) as { chunk_id: string })
139+
.chunk_id
136140
}
137141
position={
138-
(JSON.parse(props.event_data.items[0]) as { position: string }).position
142+
(JSON.parse(props.event_data.items[0]) as { position: string })
143+
.position
139144
}
140145
index={0}
141146
/>

frontends/dashboard/src/components/OnboardingSteps.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export const OnboardingSteps = () => {
99
const usageQuery = createQuery(() => ({
1010
queryKey: ["org-usage", userContext.selectedOrg().id],
1111
queryFn: async () => {
12-
return trieve.fetch("/api/organization/usage/{organization_id}", "get", {
12+
return trieve.fetch("/api/organization/usage/{organization_id}", "post", {
1313
organizationId: userContext.selectedOrg().id,
14+
data: {},
1415
});
1516
},
1617
}));

0 commit comments

Comments
 (0)