This project is the codebase for the Insights Generation Service (IGS) of the TransacAI project.
TransacAI project is geared towards generation of enriched summaries and insights of transactional data in real-time or batch using Generative AI and Large Language Models (LLMs). It goes beyond visual and analytical processing of transactional data by generating context-aware and enriched insights in natural language using LLMs. It focuses on delivering human-centric analysis that is easier to understand and act upon, eliminating the need for multiple complex data processing steps to derive insights from raw data.
IGS is one of the core service of the TransacAI project. The primary goal of this service is to generate enriched insights from transactional data using Generative AI and Large Language Models (LLMs). The service is designed to be scalable and efficient to handle real-time and batch processing of transactional data.
IGS uses gRPC to communicate with the Prompt Builder Service (PBS) of the TransacAI project, to get the prompt to be used to generate LLM response.
Core functionalities of the IGS are:
- Receives a request through gRPC from the Workload Manager Service (WMS) to generate insights from transactional data.
- Uses gRPC to communicate with the Prompt Builder Service (PBS) to get the prompt to be used to generate insights using Large Language Model (LLM).
- Generates insights from LLM using Gemini API or OpenAI API through QvikChat.
- Save the generated insights in the database.
- Send update on Kafka topic to inform clients about the generated insights.
In a nutshell, flow looks like this:
1. WMS -> IGS
2. IGS <- PBS
3. IGS <- LLM
4. IGS -> Database
5. IGS -> Kafka
This project was setup using QvikChat Starter Template. It comes pre-configured with the following features:
- QvikChat: QvikChat installed and configured to start serving chat endpoints.
- TypeScript: TypeScript to allow you to write type-safe code efficiently.
- ESLint: ESLint to enforce code quality and consistency.
- Prettier: Prettier to format your code automatically and ensure consistent code style.
- Jest: Jest to run your tests and ensure your code works as expected.
- GitHub Actions: GitHub Actions to run your tests and lint your code automatically on every push.
- SWC: For faster and more efficient TypeScript compilation.
- PNPM: PNPM to manage your dependencies efficiently.
Clone the repository.
git clone https://github.com/pranav-kural/transacai-insights-generation-service.git
Create a .env
file in the root of the project and add the following environment variables:
GOOGLE_GENAI_API_KEY=
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.
You can run the following commands to get started:
pnpm install
pnpm dev
This project comes with Jest pre-configured to run your tests, and some tests predefined in the src/tests
directory. You can run the tests using the following command:
pnpm test
Please ensure you have the environment variables set up before running the tests.
By default, Jest is configured to test the source code in the src
directory. You can change the configuration in the jest.config.js
file, along with any other Jest configurations you may want to change.
You can run the Genkit developer UI to test the response generation through GUI interface. You can know more about the Genkit Developer UI here.
Start the Genkit developer UI:
npx genkit start
OR, you can install the Genkit CLI globally:
npm i -g genkit
Then start the Genkit developer UI:
genkit start
This project comes with ESLint pre-configured to enforce code quality and consistency. You can run ESLint using the following command:
pnpm lint
You can also run ESLint in watch mode using the following command:
pnpm lint:watch
This project comes with Prettier pre-configured to format your code automatically and ensure consistent code style. You can run Prettier using the following command:
pnpm format
You can build the project using the following command:
pnpm build
This will compile the TypeScript code in the src
directory and output the compiled JavaScript code in the lib
directory.
IGS exposes a GenerateInsights
method through gRPC which can be used by the Workload Manager Service (WMS) to initiate a request to generate insights. This method only returns an object for acknowledgement with a property received
set to true
to indicate that the request has been received successfully. The actual insights generation process is asynchronous and the generated insights are sent to the Kafka topic.
Proto file for the service is located at src/rpc/igs.proto
.
You can use the grpcurl CLI tool to test the gRPC service locally.
To list services:
grpcurl -plaintext 0.0.0.0:50051 list
Please note that reflections API is disabled in production, so you won't be able to list services in production.
To call the GenerateInsights
method (remember to change reqId
to a unique value), you can use a command similar to below:
grpcurl -plaintext -d '{"reqId":"ghgfjerherw","clientId":"test_client","promptId":2,"recordsSourceId":"SUPABASE","promptTemplatesSourceId":"SUPABASE","fromTime":"2019-12-29T06:39:22Z","toTime":"2019-12-29T23:49:22Z"}' 0.0.0.0:50051 igs.InsightsGenerationService/GenerateInsights
Above request uses test client and promptId
of 2, with sources for both records and prompt templates as SUPABASE
. You can change the values as per your requirement.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or bugs while using this project, please report them by following these steps:
- Check if the issue has already been reported by searching our issue tracker.
- If the issue hasn't been reported, create a new issue and provide a detailed description of the problem.
- Include steps to reproduce the issue and any relevant error messages or screenshots.