How yeonghun1675/chatmof works
Project Type and Purpose
• ChatMOF is an open-source, Python-based AI toolkit (CLI + library) for metal-organic framework (MOF) search, prediction, and generation.
• It is not a web full-stack app but a command-line application and library that orchestrates a planning “Agent,” a set of “Toolkits,” and an “Evaluator,” backed by external LLMs and local data.
High-Level Architecture from File Structure & README
• Top-level CLI layer (chatmof/cli) provides commands: install-griday, setup, run, etc.
• Core package “chatmof”:
– agents/ : orchestrates the plan (Agent) → agent.py, prompt templates → prompt.py
– llm/ : wrappers for OpenAI, LLaMA, CodeLlama (API clients, utils)
– tools/ : individual tool adapters (search_csv, predictor, genetic_algorithm, ase_repl, unit_converter, visualizer, python_repl, etc.)
– database/ : Excel-based tables, structure loaders, MOF data structures
– evaluator: post-processes and formats final responses
– config.py, utils.py, setup_module.py hold shared settings and initialization code.
• External services:
– LLM APIs (OpenAI, local LLaMA model via HuggingFace)
– Google Search (optional)
– GRIDAY for MOF generation
– MOFTransformer and PyTorch Lightning for ML-based prediction
Main Components & Their Interactions
A. User Interface / CLI Layer
• chatmof run (or streamlit app) invokes the ChatMOF application entrypoint (app.py → main.py).
• Passes user query, options (model name, temperature).
B. Agent Layer
• The Agent module reads the query, constructs a plan via prompt templates, and decides which Toolkit(s) to invoke.
• Sequence: receive user input → generate “plan” (e.g., “search CSV → parse results”) → dispatch to Toolkit.
C. Toolkit Layer
• Each Toolkit implements a standardized interface:
– base.py defines how to receive plan instructions and call LLM or local logic
– prompt.py holds tool-specific prompt templates
– tool.py orchestrates data retrieval, LLM calls, or local computations
• Toolkits may interact with:
– database module for structure lookup or parameter loading
– llm module for LLM calls
– external packages (ase_repl, GRIDAY, unit converter)
D. LLM Service Layer
• llm/openai.py, llama.py, codellama.py expose API methods to send prompts and get completions.
E. Data Layer
• database/tables/*.xlsx and database/structures core load static MOF data into in-memory Python objects.
F. Evaluator Layer
• evaluator (in main or in app.py) collects toolkit outputs, runs validation, scoring, and composes the final user response.
G. External Dependencies
• OpenAI API, HuggingFace models, Google Search API, GRIDAY library, MOFTransformer (PyTorch), etc.
Architectural Patterns & Design Principles
• Modular “Agent–Tool” pipeline: Agent is a dispatcher, Toolkits are interchangeable plugins.
• Interface segregation: each toolkit implements a common interface (inherit from base classes).
• Dependency injection: llm wrappers and database loaders are injected into toolkits via config.
• Separation of concerns: CLI, agent logic, tool implementations, data, and evaluation are each in their own package.