Skip to content

Commit

Permalink
feature: add route to get message by id
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev committed Nov 19, 2024
1 parent bbb9d67 commit ca9ce6c
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 24 deletions.
93 changes: 84 additions & 9 deletions clients/ts-sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "BSL",
"url": "https://github.com/devflowinc/trieve/blob/main/LICENSE.txt"
},
"version": "0.12.0"
"version": "0.12.1"
},
"servers": [
{
Expand Down Expand Up @@ -1426,7 +1426,7 @@
"Chunk"
],
"summary": "Split HTML Content into Chunks",
"description": "This endpoint receives a single html string and splits it into chunks based on the headings and\nbody content. The headings are split based on headding html tags. chunk_html has a maximum size\nof 256Kb.",
"description": "This endpoint receives a single html string and splits it into chunks based on the headings and\nbody content. The headings are split based on heading html tags. chunk_html has a maximum size\nof 256Kb.",
"operationId": "split_html_content",
"requestBody": {
"description": "JSON request payload to perform RAG on some chunks (chunks)",
Expand Down Expand Up @@ -4648,7 +4648,7 @@
"security": [
{
"ApiKey": [
"readonly"
"admin"
]
}
]
Expand Down Expand Up @@ -4710,7 +4710,7 @@
"security": [
{
"ApiKey": [
"readonly"
"admin"
]
}
]
Expand Down Expand Up @@ -4780,7 +4780,7 @@
"security": [
{
"ApiKey": [
"readonly"
"admin"
]
}
]
Expand Down Expand Up @@ -4849,7 +4849,68 @@
"security": [
{
"ApiKey": [
"readonly"
"admin"
]
}
]
}
},
"/api/message/{message_id}": {
"get": {
"tags": [
"Message"
],
"summary": "Get a message by its ID",
"description": "Quickly get the full object for a given message. From the message, you can get the topic and all messages which exist on that topic.",
"operationId": "get_message_by_id",
"parameters": [
{
"name": "TR-Dataset",
"in": "header",
"description": "The dataset id or tracking_id to use for the request. We assume you intend to use an id if the value is a valid uuid.",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
},
{
"name": "message_id",
"in": "path",
"description": "The ID of the message to get.",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Message with the given ID",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Message"
}
}
}
},
"400": {
"description": "Service error relating to getting the message",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponseBody"
}
}
}
}
},
"security": [
{
"ApiKey": [
"admin"
]
}
]
Expand All @@ -4861,7 +4922,7 @@
"Message"
],
"summary": "Get all messages for a given topic",
"description": "Get all messages for a given topic. If the topic is a RAG topic then the response will include Chunks first on each message. The structure will look like `[chunks]||mesage`. See docs.trieve.ai for more information.",
"description": "If the topic is a RAG topic then the response will include Chunks first on each message. The structure will look like `[chunks]||mesage`. See docs.trieve.ai for more information.",
"operationId": "get_all_topic_messages",
"parameters": [
{
Expand Down Expand Up @@ -13599,7 +13660,7 @@
},
"group_size": {
"type": "integer",
"format": "int32",
"format": "int64",
"description": "Group_size is the number of chunks to fetch for each group. The default is 3. If a group has less than group_size chunks, all chunks will be returned. If this is set to a large number, we recommend setting slim_chunks to true to avoid returning the content and chunk_html of the chunks so as to lower the amount of time required for content download and serialization.",
"nullable": true,
"minimum": 0
Expand Down Expand Up @@ -13648,6 +13709,14 @@
"description": "Set slim_chunks to true to avoid returning the content and chunk_html of the chunks. This is useful for when you want to reduce amount of data over the wire for latency improvement (typicall 10-50ms). Default is false.",
"nullable": true
},
"sort_options": {
"allOf": [
{
"$ref": "#/components/schemas/SortOptions"
}
],
"nullable": true
},
"typo_options": {
"allOf": [
{
Expand Down Expand Up @@ -15489,6 +15558,11 @@
"type": "string",
"description": "Time stamp should be an ISO 8601 combined date and time without timezone. Time_stamp is used for time window filtering and recency-biasing search results. Will be passed down to the file's chunks.",
"nullable": true
},
"use_pdf2md_ocr": {
"type": "boolean",
"description": "Parameter to use pdf2md_ocr. If true, the file will be converted to markdown using gpt-4o.\nDefault is false.",
"nullable": true
}
},
"example": {
Expand All @@ -15512,7 +15586,8 @@
"tag2"
],
"target_splits_per_chunk": 20,
"time_stamp": "2021-01-01 00:00:00.000Z"
"time_stamp": "2021-01-01 00:00:00.000Z",
"use_pdf2md_ocr": false
}
},
"UploadFileResult": {
Expand Down
2 changes: 1 addition & 1 deletion clients/ts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
"dist"
],
"version": "0.0.30",
"version": "0.0.31",
"license": "MIT",
"scripts": {
"lint": "eslint 'src/**/*.ts'",
Expand Down
29 changes: 29 additions & 0 deletions clients/ts-sdk/src/functions/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CreateMessageReqPayload,
EditMessageReqPayload,
GetAllTopicMessagesData,
GetMessageByIdData,
RegenerateMessageReqPayload,
} from "../../fetch-client";
import { TrieveSDK } from "../../sdk";
Expand Down Expand Up @@ -358,3 +359,31 @@ export async function getAllMessagesForTopic(
signal
);
}

/**
* Quickly get the full object for a given message. From the message, you can get the topic and all messages which exist on that topic.
*
* Example:
* ```js
*const data = await trieve.getMessageById({
messageId: "3c90c3cc-1d76-27198-8888-8dd25736052a",
});
* ```
*/
export async function getMessageById(
/** @hidden */
this: TrieveSDK,
data: Omit<GetMessageByIdData, "trDataset">,
signal?: AbortSignal
) {
return await this.trieve.fetch(
"/api/message/{message_id}",
"get",
{
...data,
datasetId: this.datasetId,
},
signal
);
}

34 changes: 34 additions & 0 deletions clients/ts-sdk/src/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,7 @@ export type SearchOverGroupsReqPayload = {
* Set slim_chunks to true to avoid returning the content and chunk_html of the chunks. This is useful for when you want to reduce amount of data over the wire for latency improvement (typicall 10-50ms). Default is false.
*/
slim_chunks?: (boolean) | null;
sort_options?: ((SortOptions) | null);
typo_options?: ((TypoOptions) | null);
/**
* If true, quoted and - prefixed words will be parsed from the queries and used as required and negated words respectively. Default is false.
Expand Down Expand Up @@ -3050,6 +3051,11 @@ export type UploadFileReqPayload = {
* Time stamp should be an ISO 8601 combined date and time without timezone. Time_stamp is used for time window filtering and recency-biasing search results. Will be passed down to the file's chunks.
*/
time_stamp?: (string) | null;
/**
* Parameter to use pdf2md_ocr. If true, the file will be converted to markdown using gpt-4o.
* Default is false.
*/
use_pdf2md_ocr?: (boolean) | null;
};

export type UploadFileResult = {
Expand Down Expand Up @@ -4105,6 +4111,19 @@ export type RegenerateMessagePatchData = {

export type RegenerateMessagePatchResponse = (string);

export type GetMessageByIdData = {
/**
* The ID of the message to get.
*/
messageId: string;
/**
* The dataset id or tracking_id to use for the request. We assume you intend to use an id if the value is a valid uuid.
*/
trDataset: string;
};

export type GetMessageByIdResponse = (Message);

export type GetAllTopicMessagesData = {
/**
* The ID of the topic to get messages for.
Expand Down Expand Up @@ -5533,6 +5552,21 @@ export type $OpenApiTs = {
};
};
};
'/api/message/{message_id}': {
get: {
req: GetMessageByIdData;
res: {
/**
* Message with the given ID
*/
200: Message;
/**
* Service error relating to getting the message
*/
400: ErrorResponseBody;
};
};
};
'/api/messages/{messages_topic_id}': {
get: {
req: GetAllTopicMessagesData;
Expand Down
Loading

0 comments on commit ca9ce6c

Please sign in to comment.