function integrate_docchat
One-line integration function that configures and registers the DocChat component into a Flask application, handling dependency checking, configuration, and blueprint registration.
/tf/active/vicechatdev/docchat/integration.py
187 - 229
moderate
Purpose
This function provides a simplified integration point for adding DocChat functionality to a Flask-based PlanningTool application. It orchestrates the complete setup process including dependency verification, configuration application, and blueprint registration. It's designed to be called once during application initialization to enable document chat features with minimal setup code.
Source Code
def integrate_docchat(app, check_deps=True, **config_overrides):
"""
One-line integration of DocChat into PlanningTool.
Args:
app: Flask application instance
check_deps: Whether to check dependencies (default: True)
**config_overrides: Configuration overrides
Returns:
bool: True if integration successful
Example:
from docchat.integration import integrate_docchat
app = create_app()
integrate_docchat(app, chroma_host='localhost', chroma_port=8000)
"""
try:
# Check dependencies
if check_deps:
deps = check_dependencies(app)
if not deps['all_installed']:
logger.warning("⚠️ Proceeding with missing dependencies - some features may not work")
# Configure
configure_docchat(app, **config_overrides)
# Register blueprint
bp = register_docchat(app)
if bp:
logger.info("✅ DocChat integration complete!")
logger.info(f" Access at: {app.config.get('APPLICATION_ROOT', '')}/docchat")
return True
else:
logger.error("❌ DocChat integration failed")
return False
except Exception as e:
logger.error(f"❌ DocChat integration error: {e}")
logger.exception("Full error:")
return False
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
app |
- | - | positional_or_keyword |
check_deps |
- | True | positional_or_keyword |
**config_overrides |
- | - | var_keyword |
Parameter Details
app: Flask application instance that DocChat will be integrated into. This should be a fully initialized Flask app object before calling this function.
check_deps: Boolean flag controlling whether to verify required dependencies are installed before proceeding with integration. Defaults to True. Set to False to skip dependency checking if you're certain all requirements are met.
config_overrides: Keyword arguments for configuration overrides that will be passed to configure_docchat(). Common overrides include 'chroma_host' (ChromaDB host address), 'chroma_port' (ChromaDB port number), and other DocChat-specific settings that override default configuration values.
Return Value
Returns a boolean value: True if the DocChat integration completed successfully (dependencies checked, configuration applied, and blueprint registered), False if any step failed or an exception occurred during the integration process.
Dependencies
flaskloggingpathlib
Required Imports
from docchat.integration import integrate_docchat
Conditional/Optional Imports
These imports are only needed under specific conditions:
from blueprint import docchat_bp
Condition: required internally by the function for blueprint registration
Required (conditional)from import config as docchat_config
Condition: required internally by the function for configuration
Required (conditional)Usage Example
from flask import Flask
from docchat.integration import integrate_docchat
# Create Flask app
app = Flask(__name__)
app.config['APPLICATION_ROOT'] = '/myapp'
# Integrate DocChat with custom configuration
success = integrate_docchat(
app,
check_deps=True,
chroma_host='localhost',
chroma_port=8000
)
if success:
print('DocChat is ready at /myapp/docchat')
app.run()
else:
print('DocChat integration failed')
Best Practices
- Call this function during application initialization, before starting the Flask server
- Always check the return value to ensure integration succeeded before relying on DocChat features
- Use check_deps=True (default) in development to catch missing dependencies early
- Provide configuration overrides as keyword arguments rather than modifying config files directly for better maintainability
- Ensure the logger object is properly configured in the module before calling this function
- Handle the False return value appropriately - decide whether to fail fast or continue with degraded functionality
- Review warning logs if proceeding with missing dependencies to understand which features may not work
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_integration_status 78.9% similar
-
function register_docchat 72.4% similar
-
function check_dependencies 68.7% similar
-
function configure_docchat 68.6% similar
-
function on_load 54.2% similar