[PR #16072] feat: google drive folder sync #10820

Open
opened 2025-11-11 19:14:42 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/16072
Author: @riez
Created: 7/27/2025
Status: 🔄 Open

Base: devHead: feat/google-drive-folder-sync


📝 Commits (5)

  • 708c065 feat: google drive folder sync
  • 4fdb9c6 fix: wrong field existing sync configurations
  • 426df23 chore: Revert package.json and package-lock.json changes to match main branch
  • 65aa8b5 refactor: google drive service in knowledge base route into generic content sources standalone folders
  • c620d5f chore: remove unused helper function

📊 Changes

32 files changed (+5820 additions, -294 deletions)

View changed files

📝 backend/open_webui/config.py (+13 -0)
backend/open_webui/content_sources/__init__.py (+24 -0)
backend/open_webui/content_sources/base.py (+245 -0)
backend/open_webui/content_sources/factory.py (+84 -0)
backend/open_webui/content_sources/providers/__init__.py (+1 -0)
backend/open_webui/content_sources/providers/google_drive/__init__.py (+4 -0)
backend/open_webui/content_sources/providers/google_drive/client.py (+587 -0)
backend/open_webui/content_sources/providers/google_drive/provider.py (+460 -0)
backend/open_webui/content_sources/registry.py (+125 -0)
backend/open_webui/content_sources/scheduler.py (+261 -0)
backend/open_webui/content_sources/syncer.py (+1385 -0)
📝 backend/open_webui/main.py (+32 -0)
📝 backend/open_webui/models/files.py (+126 -2)
backend/open_webui/routers/content_sources.py (+279 -0)
📝 backend/open_webui/routers/knowledge.py (+251 -5)
📝 backend/open_webui/routers/retrieval.py (+37 -0)
backend/open_webui/utils/content_sources.py (+38 -0)
📝 backend/requirements.txt (+1 -0)
📝 src/lib/apis/knowledge/index.ts (+128 -0)
📝 src/lib/components/admin/Settings/Documents.svelte (+136 -1)

...and 12 more files

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

This PR introduces Google Drive folder synchronization for Open WebUI's knowledge base system. Users can now sync entire Google Drive folders (including nested folders) with their knowledge bases, with automatic periodic synchronization. The implementation uses Google Drive service account authentication for secure server-side access without requiring OAuth flows.

Added

  • Google Drive folder synchronization service with automatic background scheduling
  • New API endpoints for Google Drive sync operations:
    • GET /knowledge/google-drive/service-account-email
    • POST /knowledge/{id}/google-drive/sync
  • Google Drive sync modal UI component with two-step configuration wizard
  • Support for synchronizing nested folders recursively
  • Configurable sync intervals (1-3 days in production, minutes in development)

Changed

  • Updated knowledge base API to support Google Drive metadata and sync operations
  • Add Content menu with Google Drive folder sync option
  • Added Google Drive specific types and interfaces
  • Updated package dependencies to include Google API client libraries

Deprecated

  • None

Removed

  • None

Fixed

  • None

Security

  • None

Breaking Changes

  • None

Notes

I'm not sure the about the contributing flow whether I should also create PR in the docs repository while this open or not. I will create the changes in that repo after getting insight on how things usually goes on this PR.


Additional Information

Opened discussion is here: https://github.com/open-webui/open-webui/discussions/14257. I think few people including myself needs this features those I created here.

  • The implementation uses Google Drive service accounts which requires users to share their folders with the service account email
  • Sync intervals are configurable: 1-3 days in production mode, or minutes in development mode
  • The feature is controlled by the ENABLE_GOOGLE_DRIVE_FOLDER_SYNC environment variable
  • Google Workspace documents are automatically exported to compatible formats during sync
  • Files removed from Google Drive are automatically removed from the knowledge base during sync
  • Additionally Add Configurable Option for Set up DRIVE_ID and DRIVE_SECRET via Settings UI

Local Testing

Some of the local testing log:

2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:251 - Google Drive API response: 3 items returned - {}
2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:258 - Google Drive item: 'Conduct: Offline Center - vApr 2025' (Type: application/vnd.google-apps.document) - {}
2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:258 - Google Drive item: 'Copy of Kitab Suci V.2' (Type: application/vnd.google-apps.document) - {}
2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:258 - Google Drive item: 'Kitab Suci V.2' (Type: application/vnd.google-apps.document) - {}
2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:286 - Google Drive: Added file 'Conduct: Offline Center - vApr 2025' to results - {}
2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:286 - Google Drive: Added file 'Copy of Kitab Suci V.2' to results - {}
2025-07-27 23:26:31.864 | INFO     | open_webui.services.google_drive:_get_files_in_folder:286 - Google Drive: Added file 'Kitab Suci V.2' to results - {}
2025-07-27 23:26:32.376 | INFO     | open_webui.services.google_drive:list_folder_files:156 - Google Drive: Found 3 total files before filtering - {}

Screenshots or Videos

Settings UI

image

Knowledge Base UI

image image image

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/16072 **Author:** [@riez](https://github.com/riez) **Created:** 7/27/2025 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `feat/google-drive-folder-sync` --- ### 📝 Commits (5) - [`708c065`](https://github.com/open-webui/open-webui/commit/708c065f5666a4fa7169113c7a38831d4e1f7713) feat: google drive folder sync - [`4fdb9c6`](https://github.com/open-webui/open-webui/commit/4fdb9c6ed05d0d856d15245774015c395ed88ed2) fix: wrong field existing sync configurations - [`426df23`](https://github.com/open-webui/open-webui/commit/426df238e86b8a873b4eccf8f256fc7c8cbfd4ef) chore: Revert package.json and package-lock.json changes to match main branch - [`65aa8b5`](https://github.com/open-webui/open-webui/commit/65aa8b5c032f274caf76c2001eef39a465cec8a7) refactor: google drive service in knowledge base route into generic content sources standalone folders - [`c620d5f`](https://github.com/open-webui/open-webui/commit/c620d5f2bc0b8de67b41c55972badf75036b02fe) chore: remove unused helper function ### 📊 Changes **32 files changed** (+5820 additions, -294 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/config.py` (+13 -0) ➕ `backend/open_webui/content_sources/__init__.py` (+24 -0) ➕ `backend/open_webui/content_sources/base.py` (+245 -0) ➕ `backend/open_webui/content_sources/factory.py` (+84 -0) ➕ `backend/open_webui/content_sources/providers/__init__.py` (+1 -0) ➕ `backend/open_webui/content_sources/providers/google_drive/__init__.py` (+4 -0) ➕ `backend/open_webui/content_sources/providers/google_drive/client.py` (+587 -0) ➕ `backend/open_webui/content_sources/providers/google_drive/provider.py` (+460 -0) ➕ `backend/open_webui/content_sources/registry.py` (+125 -0) ➕ `backend/open_webui/content_sources/scheduler.py` (+261 -0) ➕ `backend/open_webui/content_sources/syncer.py` (+1385 -0) 📝 `backend/open_webui/main.py` (+32 -0) 📝 `backend/open_webui/models/files.py` (+126 -2) ➕ `backend/open_webui/routers/content_sources.py` (+279 -0) 📝 `backend/open_webui/routers/knowledge.py` (+251 -5) 📝 `backend/open_webui/routers/retrieval.py` (+37 -0) ➕ `backend/open_webui/utils/content_sources.py` (+38 -0) 📝 `backend/requirements.txt` (+1 -0) 📝 `src/lib/apis/knowledge/index.ts` (+128 -0) 📝 `src/lib/components/admin/Settings/Documents.svelte` (+136 -1) _...and 12 more files_ </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests to validate the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description This PR introduces Google Drive folder synchronization for Open WebUI's knowledge base system. Users can now sync entire Google Drive folders (including nested folders) with their knowledge bases, with automatic periodic synchronization. The implementation uses Google Drive service account authentication for secure server-side access without requiring OAuth flows. ### Added - Google Drive folder synchronization service with automatic background scheduling - New API endpoints for Google Drive sync operations: - GET /knowledge/google-drive/service-account-email - POST /knowledge/{id}/google-drive/sync - Google Drive sync modal UI component with two-step configuration wizard - Support for synchronizing nested folders recursively - Configurable sync intervals (1-3 days in production, minutes in development) ### Changed - Updated knowledge base API to support Google Drive metadata and sync operations - Add Content menu with Google Drive folder sync option - Added Google Drive specific types and interfaces - Updated package dependencies to include Google API client libraries ### Deprecated - None ### Removed - None ### Fixed - None ### Security - None ### Breaking Changes - None ### Notes I'm not sure the about the contributing flow whether I should also create PR in the docs repository while this open or not. I will create the changes in that repo after getting insight on how things usually goes on this PR. --- ### Additional Information Opened discussion is here: https://github.com/open-webui/open-webui/discussions/14257. I think few people including myself needs this features those I created here. - The implementation uses Google Drive service accounts which requires users to share their folders with the service account email - Sync intervals are configurable: 1-3 days in production mode, or minutes in development mode - The feature is controlled by the ENABLE_GOOGLE_DRIVE_FOLDER_SYNC environment variable - Google Workspace documents are automatically exported to compatible formats during sync - Files removed from Google Drive are automatically removed from the knowledge base during sync - Additionally Add Configurable Option for Set up DRIVE_ID and DRIVE_SECRET via Settings UI #### Local Testing Some of the local testing log: ``` 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:251 - Google Drive API response: 3 items returned - {} 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:258 - Google Drive item: 'Conduct: Offline Center - vApr 2025' (Type: application/vnd.google-apps.document) - {} 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:258 - Google Drive item: 'Copy of Kitab Suci V.2' (Type: application/vnd.google-apps.document) - {} 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:258 - Google Drive item: 'Kitab Suci V.2' (Type: application/vnd.google-apps.document) - {} 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:286 - Google Drive: Added file 'Conduct: Offline Center - vApr 2025' to results - {} 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:286 - Google Drive: Added file 'Copy of Kitab Suci V.2' to results - {} 2025-07-27 23:26:31.864 | INFO | open_webui.services.google_drive:_get_files_in_folder:286 - Google Drive: Added file 'Kitab Suci V.2' to results - {} 2025-07-27 23:26:32.376 | INFO | open_webui.services.google_drive:list_folder_files:156 - Google Drive: Found 3 total files before filtering - {} ``` ### Screenshots or Videos #### Settings UI <img width="1781" height="1085" alt="image" src="https://github.com/user-attachments/assets/eeeed936-dd7d-446e-a53f-c8d432cae674" /> #### Knowledge Base UI <img width="1787" height="456" alt="image" src="https://github.com/user-attachments/assets/f4fe296d-356e-4cf5-ad84-965b01189ebf" /> <img width="1782" height="927" alt="image" src="https://github.com/user-attachments/assets/4506813b-ed86-403a-9c4f-478e12018ba0" /> <img width="712" height="565" alt="image" src="https://github.com/user-attachments/assets/b1c55f2d-9321-4797-87f5-4796b89b682a" /> ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-11 19:14:42 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#10820