mongodb-chatbot-server
Version:
A chatbot server for retrieval augmented generation (RAG).
134 lines • 4.76 kB
TypeScript
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 { 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;
}, "strip", z.ZodTypeAny, {
message: string;
}, {
message: string;
}>;
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;
}, "strip", z.ZodTypeAny, {
message: string;
}, {
message: string;
}>;
}>, "strip", z.ZodTypeAny, {
params: {
conversationId: string;
};
headers: {
"req-id": string;
};
query: {
stream?: string | undefined;
};
body: {
message: string;
};
}, {
params: {
conversationId: string;
};
headers: {
"req-id": string;
};
query: {
stream?: string | undefined;
};
body: {
message: string;
};
}>;
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;
}
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>;
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