Skip to content

Commit

Permalink
renamed chat endpoint configurations object
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-kural committed Aug 2, 2024
1 parent ff4cf10 commit 30c8615
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 11 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Develop a self-hosted production-ready AI-powered chat app or service at a rapid
- **LangChain**: Built using the open-source [LangChain framework](https://js.langchain.com/v0.2/docs/introduction/) to help you process data for RAG and information retrieval. Easily extend the framework by using any LangChain-supported embedding model, vector store, data loader, and more.
- **Focus on Performance, Reliability, and Security**: Every component in QvikChat is built to ensure low latency and scalable performance without compromising on security. From using prompts that help mitigate LLM hallucination and deter prompt injection attacks, to providing in-built support for enabling authentication for each endpoint, QvikChat is designed to help you build secure, performant, and reliable chat apps and services.


## QvikChat Starter Template

To get up and running quickly, you can use the QvikChat starter template. The starter template is a pre-configured project with all the necessary configurations and setup to get you started with QvikChat write quality and reliable code. It comes pre-configured with support for TypeScript, ESLint, Prettier, Jest, SWC, and GitHub Actions, so you can get started with developing the next revolutionary chat app right away.
Expand Down Expand Up @@ -58,7 +57,7 @@ If you find value from this project, please consider contributing or sponsoring
## Notes

QvikChat uses the [Firebase Genkit](https://github.com/firebase/genkit) and [LangChain](https://js.langchain.com/v0.2/docs/introduction/) open-source frameworks under the hood for several functionalities. Its important to note that Firebase Genkit is currently in beta, and the public API and framework design may change in backward-incompatible ways. We will do our best to keep this project up-to-date with the latest changes in Firebase Genkit and LangChain.

## Contributions

Contributions are welcome! Please refer to the [contribution guidelines](CONTRIBUTING.md) for more information.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oconva/qvikchat",
"version": "2.0.1",
"version": "2.0.2",
"repository": {
"type": "git",
"url": "https://github.com/oconva/qvikchat.git"
Expand Down
80 changes: 77 additions & 3 deletions src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ import {
} from '../models/models';
import {getSystemPromptText} from '../prompts/system-prompts';

/**
* Type definition for the chat history parameters.
*
* @typedef {Object} ChatHistoryParams - Type parameters for chat history.
*
* @property {boolean} [enableChatHistory] - Enable chat history for this endpoint. If chat ID is provided, chat history will be fetched and used to generate response. If no chat ID is provided, a new chat ID will be generated to store chat history, and will be returned in the response.
* @property {ChatHistoryStore} [chatHistoryStore] - Chat History Store instance to use for this endpoint.
*/
type ChatHistoryParams =
| {
enableChatHistory: true;
Expand All @@ -39,6 +47,14 @@ type ChatHistoryParams =
enableChatHistory?: false;
};

/**
* Type definition for the authentication parameters.
*
* @typedef {Object} AuthParams - Type parameters for authentication.
*
* @property {boolean} [enableAuth] - Enable authentication for this endpoint. Must provide an API Key Store instance if set to true.
* @property {APIKeyStore} [apiKeyStore] - API Key Store instance to use for this endpoint.
*/
type AuthParams =
| {
enableAuth: true;
Expand All @@ -48,6 +64,14 @@ type AuthParams =
enableAuth?: false;
};

/**
* Type definition for the cache parameters.
*
* @typedef {Object} CacheParams - Type parameters for caching.
*
* @property {boolean} [enableCache] - Enable caching for this endpoint. Must provide a Cache Store instance if set to true.
* @property {CacheStore} [cacheStore] - Cache Store instance to use for this endpoint.
*/
type CacheParams =
| {
enableCache: true;
Expand All @@ -57,6 +81,16 @@ type CacheParams =
enableCache?: false;
};

/**
*
* Type definition for the RAG parameters.
*
* @typedef {Object} RAGParams - Type parameters for RAG.
*
* @property {boolean} [enableRAG] - Enable RAG (Retrieval Augmented Generation) functionality for this endpoint. Must provide a retriever method if set to true.
* @property {TextDataRetriever} [retriever] - Method to retrieve documents for RAG.
* @property {RetrieverConfig} [retrieverConfig] - Configuration for the RAG retriever.
*/
type RAGParams =
| {
enableRAG: true;
Expand All @@ -74,6 +108,14 @@ type RAGParams =
enableRAG?: false;
};

/**
* Type definition for the chat agent type parameters.
*
* @typedef {Object} ChatAgentTypeParams - Type parameters for the chat agent.
*
* @property {string} [agentType] - Type of chat agent to use for this endpoint. Can be "open-ended" or "close-ended".
* @property {string} [topic] - Topic for the close-ended or RAG chat agent. Required if agentType is "close-ended" or if RAG is enabled.
*/
type ChatAgentTypeParams =
| {
agentType?: 'open-ended';
Expand All @@ -83,13 +125,46 @@ type ChatAgentTypeParams =
topic: string;
};

/**
* Type definition for the verbose details.
*
* @typedef {Object} VerboseDetails - Type definition for the verbose details.
*
* @property {GenerationUsage} usage - Usage details for the response.
* @property {GenerateRequest} [request] - Request details for the response.
* @property {ToolRequestPart[]} [tool_requests] - Tool request details for the response.
*/
type VerboseDetails = {
usage: GenerationUsage;
request?: GenerateRequest;
tool_requests?: ToolRequestPart[];
};

export type DefineChatEndpointConfig = {
/**
* Type definition for the chat endpoint configurations.
*
* @typedef {Object} ChatEndpointConfig - Configuration object for the chat endpoint.
*
* @property {string} endpoint - Server endpoint to which queries should be sent to run this chat flow.
* @property {Dotprompt} [systemPrompt] - System prompt to use for the chat endpoint.
* @property {Dotprompt} [chatPrompt] - Chat prompt to use for the chat endpoint.
* @property {ToolArgument[]} [tools] - Tools to use for the chat endpoint.
* @property {ModelConfig} [modelConfig] - Model configuration to use for the chat endpoint.
* @property {boolean} [verbose] - A flag to indicate whether to return a verbose response or not.
* @property {OutputSchemaType} [outputSchema] - Output schema for the chat endpoint. Can be "text", "json" or "media". By default, the output format is text.
* @property {string} [agentType] - Type of chat agent to use for this endpoint. Can be "open-ended" or "close-ended".
* @property {string} [topic] - Topic for the close-ended or RAG chat agent. Required if agentType is "close-ended" or if RAG is enabled.
* @property {boolean} [enableChatHistory] - Enable chat history for this endpoint. If chat ID is provided, chat history will be fetched and used to generate response. If no chat ID is provided, a new chat ID will be generated to store chat history, and will be returned in the response.
* @property {ChatHistoryStore} [chatHistoryStore] - Chat History Store instance to use for this endpoint.
* @property {boolean} [enableAuth] - Enable authentication for this endpoint. Must provide an API Key Store instance if set to true.
* @property {APIKeyStore} [apiKeyStore] - API Key Store instance to use for this endpoint.
* @property {boolean} [enableCache] - Enable caching for this endpoint. Must provide a Cache Store instance if set to true.
* @property {CacheStore} [cacheStore] - Cache Store instance to use for this endpoint.
* @property {boolean} [enableRAG] - Enable RAG (Retrieval Augmented Generation) functionality for this endpoint. Must provide a retriever method if set to true.
* @property {TextDataRetriever} [retriever] - Method to retrieve documents for RAG.
* @property {RetrieverConfig} [retrieverConfig] - Configuration for the RAG retriever.
*/
export type ChatEndpointConfig = {
endpoint: string;
systemPrompt?: Dotprompt;
chatPrompt?: Dotprompt;
Expand All @@ -105,7 +180,6 @@ export type DefineChatEndpointConfig = {

/**
* Method to define a chat endpoint using the provided chat agent and endpoint, with support for chat history.
* @param chatAgentConfig Configurations for the chat agent, like LLM model, system prompt, chat prompt, and tools.
* @param endpoint Server endpoint to which queries should be sent to run this chat flow.
* @param outputSchema Output schema for the chat endpoint. Can be "text", "json" or "media". By default, the output format is text.
* @param verbose A flag to indicate whether to return a verbose response or not.
Expand All @@ -122,7 +196,7 @@ export type DefineChatEndpointConfig = {
* @param retrieverConfig Configuration for the RAG retriever.
* @returns Object containing the response generated by the chat agent and the chat ID (if available), or an error message.
*/
export const defineChatEndpoint = (config: DefineChatEndpointConfig) =>
export const defineChatEndpoint = (config: ChatEndpointConfig) =>
defineFlow(
{
name: config.endpoint,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
defineChatEndpoint,
getChatEndpointRunner,
type DefineChatEndpointConfig,
type ChatEndpointConfig,
} from './core/core';
import {setupGenkit, type SetupGenkitConfig} from './core/genkit';
import {runServer, type StartServerParamsType} from './core/server';
Expand All @@ -17,7 +17,7 @@ export {
// endpoint
defineChatEndpoint,
getChatEndpointRunner,
type DefineChatEndpointConfig,
type ChatEndpointConfig,
};

/**
Expand All @@ -28,7 +28,7 @@ export {
* @param serverConfig server configuration to start the server. If not provided, default server configuration will be used.
*/
export type ConfigureAndRunServerParams = {
endpointConfigs: DefineChatEndpointConfig[];
endpointConfigs: ChatEndpointConfig[];
genkitConfig?: SetupGenkitConfig;
serverConfig?: StartServerParamsType;
};
Expand Down

0 comments on commit 30c8615

Please sign in to comment.