How neo4j-graphacademy/llm-chatbot-python works
Project type and purpose
• This is a single-page, full-stack Python application built on Streamlit that implements an LLM-driven chatbot over a Neo4j graph database.
• Core functionality: accept natural-language queries via the UI, orchestrate calls to an LLM and to Neo4j tools (vector search, Cypher queries), then display answers.
File structure
Top-level files and folders:
• .devcontainer / .streamlit: development and secrets config for Codespaces and Streamlit.
• bot.py: the Streamlit entry point (UI + request routing).
• agent.py: high-level orchestration of tools (LLM, graph, vector, Cypher).
• llm.py / graph.py: wrappers around LLM API and Neo4j graph operations.
• tools/: implementations of specific “tool” plugins (cypher.py, vector.py).
• examples/ and solutions/: sample code and test suite illustrating tool usage and expected behavior.
• requirements.txt: Python dependencies (Streamlit, neo4j-driver, openai, etc.).
README for additional insights
• The application runs as streamlit run bot.py on localhost:8501.
• A Neo4j instance with the “recommendations” dataset plus an embedding index is required.
• Tests exercise the agents and tools via pytest.
1) User Interface (Streamlit front-end in bot.py)
2) Chatbot Orchestrator (agent.py)
3) Tooling Layer:
– LLM Tool (llm.py wrapping OpenAI or other LLM API)
– Graph Tool (graph.py + tools/cypher.py for Cypher queries)
– Vector Tool (tools/vector.py for embedding lookups)
4) Data Store (Neo4j graph database)
5) External Service (OpenAI API endpoint)
• User → Streamlit UI
• UI → Orchestrator (calls to agent.run or similar)
• Orchestrator → LLM Tool (for natural-language understanding or generation)
• Orchestrator → Graph Tool (for direct Cypher)
• Orchestrator → Vector Tool (for semantic search)
• Graph/Vector Tools → Neo4j
• LLM Tool → OpenAI API
• Tools return results → Orchestrator → UI → User
c. Architectural patterns and design principles:
– Layered architecture (UI / orchestration / tools / data).
– Plugin-style tool registry: agent dynamically loads tools from tools/*.py.
– Single-process, modular Python codebase.
– Separation of concerns: API wrappers (graph.py, llm.py), tool implementations, orchestration.
d. Key technologies and libraries:
– Streamlit (web UI)
– neo4j-python-driver (graph connectivity)
– OpenAI (LLM)
– pytest (testing)
– Python 3.x