UNPKG

@prexo/ai-chat-sdk

Version:

AI Chat Component with Persistent History

106 lines (103 loc) 2.7 kB
import { Message } from 'ai'; import { QueryMode } from '@upstash/vector'; type VectorPayload = { question: string | number[]; similarityThreshold?: number; topK?: number; namespace?: string; contextFilter?: string; queryMode?: QueryMode; }; type FilePath = string; type URL = string; type ResetOptions = { namespace: string; }; type AddContextOptions = { /** * Namespace of the index you wanted to insert. Default is empty string. * @default "" */ metadata?: UpstashDict; namespace?: string; }; type UpstashDict = Record<string, unknown>; type SaveOperationResult = { success: true; ids: string[]; } | { success: false; error: string; }; type DatasWithFileSource = { type?: "pdf" | "csv" | "text-file" | "html"; fileSource: FilePath; options?: AddContextOptions; } | { type: "pdf"; fileSource: FilePath | Blob; options?: AddContextOptions; } | { type: "csv"; fileSource: FilePath | Blob; options?: AddContextOptions; } | { type: "text-file"; fileSource: FilePath | Blob; options?: AddContextOptions; } | ({ type: "html"; source: URL; options?: AddContextOptions; } | { type: "html"; source: FilePath | Blob; options?: AddContextOptions; }); type AddContextPayload = { type: "text"; data: string; options?: AddContextOptions; id?: string | number; } | { type: "embedding"; data: number[]; text?: string; options?: AddContextOptions; id?: string | number; } | DatasWithFileSource; interface BaseMessageHistory { addMessage(params: { message: Message; sessionId: string; sessionTTL?: number; }): Promise<void>; deleteMessages(params: { sessionId: string; }): Promise<void>; getMessages(params: { sessionId: string; amount?: number; startIndex?: number; }): Promise<Message[]>; } interface SuggestedActionsT { label: string; action: string; } interface BaseVectorContext { addContext(input: AddContextPayload): Promise<SaveOperationResult>; removeContext(ids: string[]): Promise<void>; getContext<TMetadata = any>(payload: Omit<VectorPayload, "namespace">): Promise<{ data: string; id: string; metadata: TMetadata; }[]>; resetContext(): Promise<void>; } type VectorContextResult<TMetadata = any> = { data: string; id: string; metadata: TMetadata; }; export type { AddContextOptions, AddContextPayload, BaseMessageHistory, BaseVectorContext, DatasWithFileSource, FilePath, ResetOptions, SaveOperationResult, SuggestedActionsT, URL, UpstashDict, VectorContextResult, VectorPayload };