# dorkalev/ai architecture

> Architecture diagram of the GitHub repository dorkalev/ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dorkalev/ai
- Repository: https://github.com/dorkalev/ai

## Overview

##### Main Components

a) Learning Progression Layer
- Basic LLM Integration (1-3)
- Chain Operations (4-6)
- Advanced Processing (7-9)
- Vector Operations (10-12)
- User Interface (14-15)

b) External Services Layer
- OpenAI/ChatGPT Integration
- Ollama Integration
- LangChain Framework
- Vector Stores (FAISS)

c) Processing Patterns Layer
- Synchronous Operations
- Asynchronous Operations
- Streaming Handlers
- Batch Processing

**┌─────────────────────────────────────────────┐**
- Client Layer                   │
- (HTML Forms, User Interfaces)              │
- ┤
- Processing Layer               │
- LLM Chains                              │
- Vector Operations                        │
- Async/Batch Processing                   │
- ┤
- Integration Layer              │
- External LLM Services                    │
- Vector Stores                           │
- ┘

##### Connection Types
- Double lines: Streaming connections

##### Component Details

For each major component, include:
- Input/Output formats
- Key dependencies
- Processing direction
- Integration points

##### Notes for Implementation

- Clear separation between educational examples
- Progression from basic to advanced concepts
- Notes about alternative implementations where relevant

- Vector database operations
- Multi-LLM interactions
- Streaming implementations
- Form-based interfaces

Remember to maintain a balance between showing the educational progression and the technical implementation details, as this is both a learning resource and a technical implementation guide.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI1["Single LLM UI"]:::ui
        UI2["Multi-LLM UI"]:::ui
        Forms["HTML Forms"]:::ui
    end

    subgraph Processing
        direction TB
        subgraph Basic["Basic Integration"]
            direction TB
            ChatGPT["ChatGPT Basic"]:::basic
            LangChain["LangChain Basic"]:::basic
            Ollama["Ollama Basic"]:::basic
            Streaming["Streaming"]:::basic
        end

        subgraph Chains["Chain Operations"]
            direction TB
            BasicChains["Basic Chains"]:::chains
            ChainComposition["Chain Composition"]:::chains
            Templates["Template Processing"]:::chains
        end

        subgraph Advanced["Advanced Processing"]
            direction TB
            BatchProc["Batch Processing"]:::advanced
            AsyncOps["Async Operations"]:::advanced
            WebCrawl["Web Crawling"]:::advanced
        end

        subgraph Vector["Vector Operations"]
            direction TB
            BasicEmbed["Basic Embeddings"]:::vector
            LangChainEmbed["LangChain Embeddings"]:::vector
            VectorDB["Vector Database"]:::vector
        end
    end

    subgraph External
        OpenAI["OpenAI/ChatGPT"]:::external
        OllamaService["Ollama Service"]:::external
        LangChainFW["LangChain Framework"]:::external
        FAISS["FAISS Vector Store"]:::external
    end

    %% Connections
    UI1 --> |Request| Basic
    UI2 --> |Request| Chains
    Forms --> |Input| Processing

    Basic --> |Integration| External
    Chains --> |Uses| Basic
    Advanced --> |Extends| Chains
    Vector --> |Enhances| Advanced

    Basic --> |Uses| LangChainFW
    Chains --> |Uses| LangChainFW
    Vector --> |Uses| FAISS

    %% Click Events
    click UI1 "https://github.com/dorkalev/ai/blob/main/14-form.py"
    click UI2 "https://github.com/dorkalev/ai/blob/main/15-form-two-llms.py"
    click ChatGPT "https://github.com/dorkalev/ai/blob/main/0-chatgpt.py"
    click LangChain "https://github.com/dorkalev/ai/blob/main/1-lang-chain.py"
    click Ollama "https://github.com/dorkalev/ai/blob/main/3-ollama.py"
    click Streaming "https://github.com/dorkalev/ai/blob/main/2-streaming.py"
    click BasicChains "https://github.com/dorkalev/ai/blob/main/4-two-chains.py"
    click ChainComposition "https://github.com/dorkalev/ai/blob/main/5-two-chains-composition.py"
    click Templates "https://github.com/dorkalev/ai/blob/main/6-simpler-templates.py"
    click BatchProc "https://github.com/dorkalev/ai/blob/main/7-batch-multi-model.py"
    click AsyncOps "https://github.com/dorkalev/ai/blob/main/8-async.py"
    click WebCrawl "https://github.com/dorkalev/ai/blob/main/9-crawler.py"
    click BasicEmbed "https://github.com/dorkalev/ai/blob/main/10-embed.py"
    click LangChainEmbed "https://github.com/dorkalev/ai/blob/main/11-embed-lang-chain.py"
    click VectorDB "https://github.com/dorkalev/ai/blob/main/12-poor-mans-vector-db.py"

    %% Styles
    classDef ui fill:#2374AB,stroke:#000,stroke-width:2px
    classDef basic fill:#7BC950,stroke:#000,stroke-width:2px
    classDef chains fill:#39A9DB,stroke:#000,stroke-width:2px
    classDef advanced fill:#F19953,stroke:#000,stroke-width:2px
    classDef vector fill:#B4436C,stroke:#000,stroke-width:2px
    classDef external fill:#FFD93D,stroke:#000,stroke-width:2px

    %% Legend
    subgraph Legend
        UI_L["UI Components"]:::ui
        Basic_L["Basic Integration"]:::basic
        Chains_L["Chain Operations"]:::chains
        Advanced_L["Advanced Processing"]:::advanced
        Vector_L["Vector Operations"]:::vector
        External_L["External Services"]:::external
    end
```
