UNPKG

mongodb-chatbot-server

Version:

A chatbot server for retrieval augmented generation (RAG).

146 lines 5.86 kB
import { Request as ExpressRequest, Response as ExpressResponse } from "express"; import { SystemMessage } from "mongodb-rag-core"; import { ConversationsService, ChatLlm } from "mongodb-rag-core"; import { ApiMessage } from "./utils"; import { z } from "zod"; import { AddCustomDataFunc, ConversationsRouterLocals } from "./conversationsRouter"; import { GenerateUserPromptFunc } from "../../processors/GenerateUserPromptFunc"; import { FilterPreviousMessages } from "../../processors/FilterPreviousMessages"; import { Logger } from "mongodb-rag-core/braintrust"; import { UpdateTraceFunc } from "./UpdateTraceFunc"; export declare const DEFAULT_MAX_INPUT_LENGTH = 3000; export declare const DEFAULT_MAX_USER_MESSAGES_IN_CONVERSATION = 7; export type AddMessageRequestBody = z.infer<typeof AddMessageRequestBody>; export declare const AddMessageRequestBody: z.ZodObject<{ message: z.ZodString; clientContext: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }, "strip", z.ZodTypeAny, { message: string; clientContext?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; }, { message: string; clientContext?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; }>; export declare const AddMessageRequest: z.ZodObject<z.objectUtil.extendShape<{ headers: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; params: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; query: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; body: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; }, { headers: z.ZodObject<{ "req-id": z.ZodString; }, "strip", z.ZodTypeAny, { "req-id": string; }, { "req-id": string; }>; params: z.ZodObject<{ conversationId: z.ZodString; }, "strip", z.ZodTypeAny, { conversationId: string; }, { conversationId: string; }>; query: z.ZodObject<{ stream: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { stream?: string | undefined; }, { stream?: string | undefined; }>; body: z.ZodObject<{ message: z.ZodString; clientContext: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }, "strip", z.ZodTypeAny, { message: string; clientContext?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; }, { message: string; clientContext?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; }>; }>, "strip", z.ZodTypeAny, { params: { conversationId: string; }; headers: { "req-id": string; }; query: { stream?: string | undefined; }; body: { message: string; clientContext?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; }; }, { params: { conversationId: string; }; headers: { "req-id": string; }; query: { stream?: string | undefined; }; body: { message: string; clientContext?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; }; }>; export type AddMessageRequest = z.infer<typeof AddMessageRequest>; export interface AddMessageToConversationRouteParams { conversations: ConversationsService; llm: ChatLlm; generateUserPrompt?: GenerateUserPromptFunc; filterPreviousMessages?: FilterPreviousMessages; maxInputLengthCharacters?: number; maxUserMessagesInConversation?: number; addMessageToConversationCustomData?: AddCustomDataFunc; /** If present, the route will create a new conversation when given the `conversationIdPathParam` in the URL. */ createConversation?: { /** Create a new conversation when the `conversationId` is the string "null". */ createOnNullConversationId: boolean; /** The custom data to add to the new conversation when it is created. */ addCustomData?: AddCustomDataFunc; /** The system message to add to the new conversation when it is created. */ systemMessage?: SystemMessage; }; /** Custom function to update the Braintrust tracing after the response has been sent to the user. Can add additional tags, scores, etc. */ updateTrace?: UpdateTraceFunc; braintrustLogger?: Logger<true>; } export declare function makeAddMessageToConversationRoute({ conversations, llm, generateUserPrompt, maxInputLengthCharacters, maxUserMessagesInConversation, filterPreviousMessages, addMessageToConversationCustomData, createConversation, updateTrace, }: AddMessageToConversationRouteParams): (req: ExpressRequest<AddMessageRequest["params"]>, res: ExpressResponse<ApiMessage, ConversationsRouterLocals>) => Promise<ExpressResponse<{ role: "function" | "user" | "assistant" | "system"; id: string; content: string; createdAt: number; rating?: boolean | undefined; metadata?: Record<string, unknown> | undefined; references?: { url: string; title: string; metadata?: z.objectOutputType<{ sourceName: z.ZodOptional<z.ZodString>; /** Create a new conversation when the `conversationId` is the string "null". */ sourceType: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; }, z.ZodTypeAny, "passthrough"> | undefined; }[] | undefined; }, ConversationsRouterLocals> | undefined>; //# sourceMappingURL=addMessageToConversation.d.ts.map