knowmax-quest-utils
v3.13.0
Published
Utilities for creating a Knowmax Quest client.
Readme
Knowmax Quest Utils
Contains utilities for working with Knowmax Quest.
Usage
Streaming intelligence endpoints
The Document Insight and Index Research intelligence endpoints have streaming (Server-Sent Events) variants.
Because these endpoints require a POST body, the browser's native EventSource API cannot be used. Instead,
combine the stream endpoint builders with fetch and the readIntelligenceStream async generator:
import { documentInsightStreamEndpoint, readIntelligenceStream } from 'knowmax-quest-utils'
import type { IDocumentInsight } from 'knowmax-quest-types'
const response = await fetch(documentInsightStreamEndpoint(endpoint, questId), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(documentInsightRequest)
});
for await (const event of readIntelligenceStream<IDocumentInsight>(response)) {
// handle event, see IDocumentInsightStreamEvent in knowmax-quest-types
}Use indexResearchStreamEndpoint and IIndexResearch for the Index Research stream endpoint.
File attachments
Use validateIntelligenceAttachments to check user-selected files against the limits reported by the models endpoint
before offering the upload UI, and createIntelligenceChatMessageAttachmentRequest to build the base64 encoded
attachment payload for the chat message:
import { validateIntelligenceAttachments, createIntelligenceChatMessageAttachmentRequest } from 'knowmax-quest-utils'
import type { IIntelligenceModel } from 'knowmax-quest-types'
const selectedFiles: File[] = [ /* files chosen by the user */ ];
if (model.supportsAttachments && model.attachments) {
const errors = validateIntelligenceAttachments(
selectedFiles.map(file => ({ name: file.name, contentType: file.type, size: file.size })),
model.attachments
);
if (errors.length === 0) {
const attachments = await Promise.all(selectedFiles.map(file => createIntelligenceChatMessageAttachmentRequest(file)));
}
}License
This repository is licensed MIT, which waives all copyright restrictions.
