How honestsoul/generative_ai_project works
Project type and purpose
• This is an open-source “Generative AI Project Template” that provides a modular foundation for building LLM-powered applications. It is neither a web front-end nor a traditional back-end service, but rather a library/toolkit that coordinates prompt engineering, LLM clients, caching, rate-limiting, logging, and error handling to streamline AI integrations.
File structure
• Top-level directories:
• config/ – YAML files for model settings, prompts, and logging.
• src/ – Core modules organized into llm clients, prompt_engineering, utils, and handlers.
• data/ – Persistent storage for caches, prompt definitions, embeddings, and outputs.
• examples/ & notebooks/ – Entry points showing how to drive the library (scripts and Jupyter labs).
README for additional insights
• The README confirms support for multiple providers (Anthropic Claude & OpenAI GPT), details pre-configured utilities (rate limiter, token counter, caching, logging), and outlines best practices (YAML configs, modularity, error handling).
Main components & interactions
a. Components
• Entry Layer: Examples & Notebooks
• Configuration Loader (config/*.yaml)
• Prompt Engineering Module (src/prompt_engineering)
• LLM Client Layer (src/llm/base.py, claude_client.py, openai_client.py, utils.py)
• Utility Services (src/utils: rate_limiter, token_counter, cache, logger)
• Error Handler (src/handlers/error_handler.py)
• Data Storage (data/cache, data/prompts, data/outputs, data/embeddings)
• External LLM APIs (Anthropic Claude, OpenAI GPT)
b. Relationships & Data Flows
1. User (scripts/notebooks) → loads YAML configs
2. User → selects or builds prompt via Prompt Engineering module
3. Prompt Engine → invokes LLM Client (base client + provider plugin)
4. LLM Client → applies utils: rate_limit → token_counter → cache_lookup
• On cache miss, Client → External API → receives response → cache_store
5. Response → passes back up through error_handler wrapping
6. Final output → written to data/outputs and returned to the entry layer
7. Logger records each stage (loading, request/response, errors)
c. Architectural patterns & design principles
• Plugin pattern for LLM providers (base class + concrete subclasses)
• Separation of concerns: prompt templates, client logic, utilities, error handling
• Layered architecture: Entry → Config → Prompt Engine → Client → External
• Caching and rate-limiting as cross-cutting concerns injected via utils
d. Key technologies & libraries
• YAML for configuration (PyYAML or ruamel.yaml)
• HTTP client (requests or httpx) within LLM clients
• JSON for data serialization in data/
• Jupyter for notebooks
• Python logging module configured via logging_config.yaml