Gemini Integration

Google Gemini integration with Frappe ERPNext 15.

Install Gemini Integration

bench get-app https://github.com/sapphirefountains/gemini_integration

Add the Frappe Gems badge to your README

Maintain Gemini Integration? Paste this into your README:

[![Listed on Frappe Gems](https://frappegems.com/api/method/frappe_gems.seo.badge?app=sapphirefountains%2Fgemini_integration)](https://frappegems.com/gems/apps/sapphirefountains/gemini_integration)

About Gemini Integration

Gemini Integration for Frappe ERPNext

1. Purpose

This app integrates Google's Gemini AI and Google Workspace (Gmail, Drive, Calendar) directly into your Frappe ERPNext v15 instance. It provides a powerful, centralized chat interface where you can interact with your ERP data and Google Workspace content seamlessly. The goal is to streamline workflows by allowing users to query documents, generate content, and get insights without leaving their ERP.

2. Key Features

  • Conversational AI Chat: A central chat interface powered by Google Gemini.
  • ERPNext Data Integration:
    • Directly reference any DocType in your ERPNext instance (e.g., Project, Customer, Sales Invoice) to pull its data into the chat.
    • An intelligent search function helps you find the right document even if you don't know the exact ID.
  • Google Workspace Integration:
    • Securely connect your Google account using OAuth 2.0.
    • Search across Gmail, Google Drive, and Google Calendar.
    • Reference specific emails and documents to get their details and a direct link.
  • Context-Aware Responses: The integration combines data from ERPNext and Google Workspace to provide comprehensive, context-aware answers in a single response.
  • Project Management Tools:
    • Automatically generate a list of tasks for a project based on its details.
    • Analyze a project for potential risks (e.g., budget, timeline, scope creep).

3. Architecture

The integration uses a combination of techniques to understand your queries and fetch the right information:

  1. Reference Detection: The system scans your chat message for special syntax (@ references) to identify direct links to ERPNext documents (@PROJ-00123) or Google files (@gdrive/...).
  2. Keyword-Based Search: If no direct references are found, the system looks for keywords like "email," "drive," or "calendar" to target a specific Google Workspace service. It also listens for action words like "list" or "find" to initiate a search in ERPNext.
  3. Fuzzy Search & Ranking: When searching ERPNext, the system uses a weighted fuzzy search algorithm (thefuzz) to find the most relevant documents, even if your query has typos or incomplete names. It ranks results based on relevance and user feedback.
  4. Context Assembly: All the retrieved data from ERPNext and Google Workspace is compiled into a single context block.
  5. AI Processing: This context, along with your original prompt and a system instruction, is sent to the Google Gemini API to generate a helpful, human-readable response.

4. Installation

You can install this app using the bench CLI:

cd $PATH_TO_YOUR_BENCH
bench get-app https://github.com/Sapphire-Fountains/gemini-integration.git --branch main
bench install-app gemini_integration

5. Configuration

To use the Google Workspace integration, you need to set up a project in the Google Cloud Platform (GCP) and enable the necessary APIs.

  1. Create a GCP Project: If you don't have one already, create a new project at the GCP Console.
  2. Enable APIs: In your project, go to the "APIs & Services" dashboard and enable the following APIs:
    • Google Drive API
    • Gmail API
    • Google Calendar API
    • Google People API
  3. Configure OAuth Consent Screen:
    • Go to "OAuth consent screen" in the APIs & Services dashboard.
    • Choose "External" user type and create a new consent screen.
    • Add the necessary scopes: .../auth/drive.readonly, .../auth/gmail.readonly, .../auth/calendar.readonly, .../auth/userinfo.email, and openid.
    • Add your Frappe site domain to the "Authorized domains" list.
  4. Create OAuth 2.0 Credentials:
    • Go to "Credentials" and create a new "OAuth 2.0 Client ID."
    • Select "Web application" as the type.
    • Add your site's callback URL to the "Authorized redirect URIs" list: https:///api/method/gemini_integration.api.handle_google_callback
    • Copy the Client ID and Client Secret.
  5. Configure the App in ERPNext:
    • Gemini Settings:
      • Go to the "Gemini Settings" page in your ERPNext Desk.
      • Enter the API Key for the Google Gemini AI service. You can get this from Google AI Studio.
    • Social Login Keys (Google):
      • Go to the "Social Login Keys" page and open the "Google" document.
      • Check the "Enable Social Login" box.
      • Paste the Client ID and Client Secret you copied from GCP.

6. Running the Application

Once installed and configured, you can access the chat interface from the Gemini Chat page in your Desk.

7. Usage

1. Interacting with ERPNext Data

  • Smart Referencing with @: To pull data from an ERPNext document, simply use the @ symbol followed by the document's name or ID. The system is designed to be flexible, so you don't need to know the exact DocType.
    • Example: What is the status of @PRJ-00183?
    • Example: Tell me more about @"Test Customer".
  • Interactive Clarification: If your query is ambiguous and Gemini finds multiple possible matches (e.g., you search for @"Test" and it finds "Test Project" and "Test Task"), it will present you with a list of options. Simply select the correct document(s) to provide the context for your query. This ensures you always get the most relevant information.

2. Interacting with Google Workspace

  1. Connect Your Account: The first time you use a Google service, the system will prompt you to connect your account. Click the link, sign in with Google, and grant the necessary permissions.
  2. Smart Search: There's no special syntax required. Just ask your question naturally. If you mention keywords like email, drive, file, or calendar, Gemini will use them to narrow the search.
    • Search my email for the latest updates from Riverton City.
    • Find the contract file in my drive for the Main Street Fountain project.
    • What is on my calendar for next week?
  • Interactive Clarification: Just like with ERPNext data, if your search in Google Drive or Gmail returns multiple relevant results, Gemini will ask you to choose the correct one(s) before proceeding. This avoids guesswork and ensures the AI has the exact context you intended.

3. Combining Queries

The real power comes from combining these references in a single, natural language query.

Example: Draft a follow-up email to the contact in @CUST-00234 regarding the issues mentioned in @gmail/a1b2c3d4e5f6. Use the service details from @SC-00105 as a reference.

8. Contributing

This app uses pre-commit for code formatting and linting. Please install pre-commit and enable it for this repository:

cd apps/gemini_integration
pre-commit install

Pre-commit is configured to use the following tools for checking and formatting your code:

  • ruff
  • eslint
  • prettier
  • pyupgrade

9. License

This project is licensed under the MIT License. See the license.txt file for details.

Related Integrations apps for Frappe & ERPNext

  • Insights — Open Source Business Intelligence Tool
  • Raven — Simple, open source team messaging platform
  • Frappe Whatsapp — WhatsApp cloud integration for frappe
  • Frappe Assistant Core — Infrastructure that connects LLMs to ERPNext. Frappe Assistant Core works with the Model Context Protocol (MCP) to expose ERPNext functionality to any compatible Language Model
  • Biometric Attendance Sync Tool — A simple tool for syncing Biometric Attendance data with your ERPNext server
  • Frappe React Sdk — React hooks for Frappe
  • Frappe Js Sdk — TypeScript/JavaScript library for Frappe REST API
  • Mcp — Frappe MCP allows Frappe apps to function as MCP servers