The Genkit Alpha Bot is a conversational application built using Genkit, Firebase Firestore, and Google Vertex AI. This bot assists users in setting up dating profiles with customized responses based on user preferences and goals. With a step-by-step approach, users receive tailored archetype suggestions and guidance that fit their objectives, providing a seamless and engaging profile setup experience.
- Guided Profile Setup: Interactive profile creation tailored to user preferences.
- Archetype Suggestions: Intelligent archetype recommendations based on relationship goals.
- In-Memory Caching: Efficiently caches data from Firestore, reducing database load and improving response times.
- Contextual Conversations: Stateful conversations that maintain user context and smooth transitions between states.
- Vertex AI Integration: Utilizes Vertex AI to generate personalized, natural language responses.
- Customizable Tones: Configurable response tones, including "friendly," "sarcastic," and more, based on user input and archetypes.
- Setup
- Environment Variables
- Project Structure
- Main Components
- API Usage
- Development Workflow
- License
- Node.js: Version 14 or higher
- Firebase: Ensure Firestore is enabled in Firebase for data storage.
- Genkit CLI: Install Genkit CLI to assist with plugin setups.
- Clone the repository:
git clone https://github.com/yourusername/genkit-alpha-bot.git
cd genkit-alpha-bot
- Install dependencies:
npm install
-
Environment Configuration:
- Set up environment variables as detailed below.
-
Start the development server:
genkit start
- Enable Vertex AI in your Google Cloud project and create your language models as needed.
- Set up Firebase with Firestore and obtain your API credentials.
Create a .env
file in the project root with the following variables:
MODEL_TEMPERATURE=0.7 # Controls model response creativity
CACHE_DURATION=60000 # Cache duration in milliseconds
FIREBASE_API_KEY=your-firebase-api-key # Firebase API Key
FIREBASE_PROJECT_ID=your-project-id # Firebase Project ID
FIREBASE_APP_ID=your-app-id
FIREBASE_STORAGE_BUCKET=your-storage-bucket
FIREBASE_AUTH_DOMAIN=your-auth-domain
genkit-alpha-bot/
├── src/
│ ├── config/
│ │ ├── firebase.ts # Firebase initialization, setting up Firestore and Firebase Auth access
│ │ └── genkit.ts # Configures Genkit with plugins (Firebase, Vertex AI) and flow state logging
│ ├── constants/
│ │ └── flowState.ts # Defines possible states in the bot's flow as constants for improved type safety
│ ├── cache/
│ │ └── archetypeCache.ts # Caches archetype data temporarily to reduce redundant Firestore reads
│ ├── prompts/
│ │ ├── welcomePrompt.ts # Defines the initial welcome prompt structure for new users
│ │ ├── archetypePrompt.ts # Template for archetype suggestions
│ │ └── partials/
│ │ └── defaultStyle.ts # Defines default style formatting for responses
│ ├── data/
│ │ ├── models/
│ │ │ ├── Archetype.ts # Type definitions for archetypes
│ │ │ └── UserDetails.ts # Type definitions for user details
│ │ └── repositories/
│ │ ├── archetypeRepository.ts # Handles data access for archetypes
│ │ └── userRepository.ts # Manages data access for user profiles
│ ├── services/
│ │ ├── archetypeService.ts # Core logic for handling archetype-related operations
│ │ └── userService.ts # Provides user-related services
│ ├── flows/
│ │ ├── profileSetupFlow.ts # Manages the main profile setup flow
│ │ └── resetFlowStateFlow.ts # Handles flow state resets
│ ├── utils/
│ │ └── index.ts # Contains utility functions for JSON parsing and response formatting
│ └── index.ts # Main entry point; initializes and starts the server
Guides users through profile creation using a series of states, transitioning as follows:
awaiting_welcome
: Welcomes users and prompts them to choose their relationship goal.awaiting_archetype
: Suggests archetypes based on the user's selected goal.awaiting_photos
: Asks users to select photos matching their chosen archetypes.completed
: Final state after completing profile setup.error
: Handles any errors that occur during the flow.
- Resets the flow state for a given conversation, allowing users to restart their profile setup if needed.
Generates prompts using Vertex AI's language models, configured with customizable parameters such as temperature for controlling response creativity.
Primary functions include:
generateWelcomeMessage
: Welcomes users and introduces the setup flow.generateArchetypeSuggestion
: Suggests archetypes based on user details.
- Manages the flow state for each user session, ensuring continuity.
- Works with Firestore or in-memory storage for flexibility across environments.
- Response Parsing:
parseResponse
andparseWelcomeResponse
- Parses JSON responses from Vertex AI, filtering out irrelevant data (e.g., safety-related metadata) to ensure responses are user-friendly.
To run the server locally:
npm start
The bot maintains state across user interactions. Below is a guide to the states in profileSetupFlow:
Flow State | Description |
---|---|
awaiting_welcome | Prompts user to choose a relationship goal. |
awaiting_archetype | Recommends archetypes based on user's relationship goal. |
awaiting_photos | Requests photos that represent chosen archetypes. |
completed | Final state after profile setup is complete. |
error | Handles errors and prompts the user to restart the flow. |
Endpoint: POST /profileSetupFlow
Sample Request:
{
"data": {
"conversationId": "1234-5678-91011",
"userDetails": {
"firstName": "Teodor",
"age": 22,
"sex": "male",
"goal": "long-term"
}
}
}
Expected Response:
{
"flowState": "awaiting_welcome",
"response": "Hey Teodor, welcome! What's your relationship goal, long-term or short-term?",
"suggestions": ["Long-term relationship", "Short-term relationship"]
}
Endpoint: POST /profileSetupFlow
Sample Request:
{
"data": {
"conversationId": "1234-5678-91011",
"prompt": "Long-term relationship",
"flowState": "awaiting_archetype",
"userDetails": {
"firstName": "Teodor",
"age": 22,
"sex": "male",
"goal": "long-term"
}
}
}
Expected Response:
{
"flowState": "awaiting_archetype",
"response": "Based on your long-term goal, here are some archetypes that may fit you:",
"suggestions": ["The Visionary", "The Adventurer", "The Protector"]
}
Endpoint: POST /resetFlowStateFlow
Sample Request:
{
"data": {
"conversationId": "1234-5678-91011"
}
}
Expected Response:
{
"message": "Flow state reset successfully for conversation ID: 1234-5678-91011"
}
Run unit tests for flows and services to ensure functionality:
npm test
- Use the Genkit CLI for flow state inspection to confirm expected states.
- Adjust
.env
file variables to control model settings and Firestore configurations.
- Track error logs to diagnose issues with prompts, state transitions, and Firestore interactions.
This project is licensed under the License. See the LICENSE file for more information.