function main_v45
Orchestrates and executes a series of example demonstrations for the DocChat system, including document indexing, RAG queries, and conversation modes.
/tf/active/vicechatdev/docchat/example_usage.py
167 - 198
simple
Purpose
This function serves as a comprehensive demonstration runner for the DocChat application. It sequentially executes multiple example functions to showcase different features: document indexing, basic RAG (Retrieval-Augmented Generation), extensive mode querying, full reading mode (commented out by default), and conversation with history. It includes error handling and provides user feedback about setup requirements if failures occur.
Source Code
def main():
"""Run all examples"""
print("=" * 80)
print("DocChat - Example Usage")
print("=" * 80)
try:
# 1. Index documents
index_documents_example()
# 2. Basic RAG
basic_rag_example()
# 3. Extensive mode
extensive_mode_example()
# 4. Full reading mode (commented out by default as it's slow)
# full_reading_example()
# 5. Conversation with history
conversation_example()
print("\n" + "=" * 80)
print("Examples completed!")
print("=" * 80)
except Exception as e:
print(f"\nā Error: {e}")
print("\nMake sure:")
print(" 1. You have set OPENAI_API_KEY in .env")
print(" 2. You have indexed some documents")
print(" 3. Dependencies are installed")
Return Value
This function does not return any value (implicitly returns None). It produces side effects by printing output to the console and executing example functions that demonstrate the DocChat system's capabilities.
Dependencies
pathlibdocument_indexerrag_engineconfig
Required Imports
from pathlib import Path
from document_indexer import DocumentIndexer
from rag_engine import DocChatRAG
import config
Usage Example
if __name__ == '__main__':
main()
Best Practices
- Ensure OPENAI_API_KEY is set in environment variables before running
- Index documents before executing this function to avoid errors
- The full_reading_example() is commented out by default due to performance considerations - uncomment only when needed
- This function is designed to be called as the main entry point of an example/demo script
- Error messages provide clear guidance on setup requirements if execution fails
- Each example function should be independently executable and handle its own errors gracefully
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v38 71.7% similar
-
function basic_rag_example 68.5% similar
-
function extensive_mode_example 67.6% similar
-
function main_v22 64.5% similar
-
class DocChatRAG 63.9% similar