Skip to content

Commit

Permalink
updated documentation to reflect recent changes in qvikchat package
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-kural committed Jul 9, 2024
1 parent 2119524 commit 0da2cac
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 50 deletions.
4 changes: 3 additions & 1 deletion pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"index": "Introduction",
"getting-started": "Getting Started",
"chat-endpoints": "Chat Endpoints",
"chat-agent": "Chat Agent",
"chat-agent": {
"display": "hidden"
},
"chat-history": "Chat History",
"prompts": "Prompts",
"rag-guide": "RAG Guide",
Expand Down
145 changes: 96 additions & 49 deletions pages/chat-endpoints/chat-endpoint-configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,101 @@ import { defineChatEndpoint } from "@oconva/qvikchat/endpoints";

Below are some of the chat endpoint configurations you can define.

- `chatAgentConfig`: Configurations for the chat agent, like LLM model, system prompt, chat prompt, and tools.
- `endpoint`: Server endpoint to which queries should be sent to run this chat flow.

**Close-ended Chat Configurations**

- `agentType`: Type of chat agent to use for this endpoint. Can set it to "close-ended" to create a close-ended chat endpoint. By default, it is set to "open-ended".
- `topic`: Topic for close-ended chat agent. Required if RAG is enabled. Queries are restricted to be relevant to the given topic so to prevent unintended use.

**Chat History Configurations**

- `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.
- `chatHistoryStore`: Chat History Store instance to use for this endpoint.

**Auth Configurations**

- `enableAuth`: Enable authentication for this endpoint. Must provide an API Key Store instance if set to true.
- `apiKeyStore`: API Key Store instance to use for this endpoint.

**Cache Configurations**

- `enableCache`: Enable caching for this endpoint. Must provide a Cache Store instance if set to true.
- `cacheStore`: Cache Store instance to use for this endpoint.

**RAG Configurations**

- `topic`: Topic for RAG chat agent. Required if RAG is enabled. Queries are restricted to be relevant to the given topic so to prevent unintended use.
- `enableRAG`: Enable RAG (Retrieval Augmented Generation) functionality for this endpoint. Must provide a retriever method if set to true.
- `retriever`: Method to retrieve documents for RAG. Can be obtained from the `getDataRetriever` method.
- `retrieverConfig`: Configuration for the RAG retriever, for example, number of documents to retrieve, algorithm to use, etc.

## Example

Below is an example of a comprehensively configured chat endpoint. You don't need to provide all the configurations, only the ones you need. Below example is only for demonstration purposes.

```typescript copy
/**
* Represents the parameters for defining a chat endpoint.
*/
export interface DefineChatEndpointParams {
/**
* The chat agent used for the endpoint.
*/
chatAgent: ChatAgent;

/**
* The endpoint for the chat endpoint.
*/
endpoint: string;

/**
* Optional flag to enable chat history.
*/
enableChatHistory?: boolean;

/**
* Optional flag to enable authentication.
*/
enableAuth?: boolean;

/**
* Optional API key store.
*/
apiKeyStore?: APIKeyStore;

/**
* Optional flag to enable caching.
*/
enableCache?: boolean;

/**
* Optional cache store.
*/
cacheStore?: CacheStore;

/**
* Optional flag to enable RAG (Retrieve, Answer, Generate) functionality.
*/
enableRAG?: boolean;

/**
* Optional method to retrieve documents for RAG.
*/
retriever?: TextDataRetriever;
}
import { FirestoreAPIKeyStore } from "@oconva/qvikchat/auth";
import { FirestoreCacheStore } from "@oconva/qvikchat/cache";
import { getEmbeddingModel } from "@oconva/qvikchat/data-embeddings";
import { TaskType } from "@oconva/qvikchat/data-retrievers";
import { defineChatEndpoint } from "@oconva/qvikchat/endpoints";
import { FirestoreChatHistoryStore } from "@oconva/qvikchat/history";
import { credential, getFirebaseApp } from "@oconva/qvikchat/firebase";

// Initialize Firebase app
const firebaseApp = getFirebaseApp({
credential: credential.cert(
process.env.GOOGLE_APPLICATION_CREDENTIALS as string
),
});

// Define chat endpoint with RAG, chat history, cache and auth
// uses Firestore API key store, Firestore chat history store, Firestore cache store
// uses Gemini 15 Pro model for chat and embedding-001 embedding model
// uses custom retrieval strategy for RAG
defineChatEndpoint({
endpoint: "chat",
topic: "inventory data",
chatAgentConfig: {
model: "gemini15Pro",
modelConfig: {
temperature: 0.9,
},
},
enableAuth: true,
apiKeyStore: new FirestoreAPIKeyStore({
firebaseApp: firebaseApp,
collectionName: "api-keys",
}),
enableChatHistory: true,
chatHistoryStore: new FirestoreChatHistoryStore({
firebaseApp: firebaseApp,
collectionName: "chat-history",
}),
enableCache: true,
cacheStore: new FirestoreCacheStore({
firebaseApp: firebaseApp,
collectionName: "cache",
}),
enableRAG: true,
retrieverConfig: {
dataType: "csv",
filePath: "data/inventory.csv",
csvLoaderOptions: {
column: "products",
separator: ",",
},
generateEmbeddings: true,
retrievalOptions: {
k: 10,
searchType: "mmr",
},
embeddingModel: getEmbeddingModel({
modelName: "embedding-001",
taskType: TaskType.RETRIEVAL_DOCUMENT,
}),
},
});
```
3 changes: 3 additions & 0 deletions pages/chat-endpoints/rag-chat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const inventoryDataRetriever = await getDataRetriever({
// Inventory Data chat endpoint with support for RAG
defineChatEndpoint({
endpoint: "chat-rag-inventory",
topic: "inventory data",
enableRAG: true,
retriever: inventoryDataRetriever,
});
Expand Down Expand Up @@ -164,6 +165,7 @@ const inventoryDataRetriever = await getDataRetriever({
// Inventory Data chat endpoint with support for RAG and chat history
defineChatEndpoint({
endpoint: "chat-rag-history-inventory",
topic: "inventory data",
enableRAG: true,
retriever: inventoryDataRetriever,
enableChatHistory: true,
Expand Down Expand Up @@ -263,6 +265,7 @@ const inventoryDataRetriever = await getDataRetriever({
// Inventory Data chat endpoint with support for RAG, chat history, cache and auth
defineChatEndpoint({
endpoint: "chat-rag-history-auth-cached-inventory",
topic: "inventory data",
enableChatHistory: true,
chatHistoryStore: new InMemoryChatHistoryStore(),
enableAuth: true,
Expand Down
16 changes: 16 additions & 0 deletions pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ Or
pnpm add @oconva/qvikchat
```

## Setup Environment Variables

Create a `.env` file in the root of the project and add the following environment variables:

```env copy
GOOGLE_GENAI_API_KEY=
OPENAI_API_KEY=
GOOGLE_APPLICATION_CREDENTIALS=
```

Alternatively, you can copy the `.env.tmp` file or rename it to `.env` and fill in the values.

By default QvikChat uses the Google GenAI, so to use QvikChat with default settings, you need to provide the `GOOGLE_GENAI_API_KEY`. You don't have to set values for other environment variables if you are using the default settings.

Add value to the `OPENAI_API_KEY` variable if you're going to use OpenAI models and to the `GOOGLE_APPLICATION_CREDENTIALS` variable if you're going to use Firebase Firestore.

## Usage

Before you can deploy your chat endpoints, you need to setup Firebase Genkit, either by using the default configurations or by providing your own configurations, these may include additional Genkit plugins you may want to enable (e.g. to add support for a new language model). When starting out, we recommend using the default configurations.
Expand Down

0 comments on commit 0da2cac

Please sign in to comment.