How nikeyes/genai-security-demo works
Project Type and Purpose
• This is a Python-based chatbot project built to demonstrate and implement security defenses (leveraging Meta Llama tools) in a generative AI context.
• Its core functionality is to interact with various LLM providers (Amazon Bedrock, Groq, OpenAI, and Anthropic) while enforcing security policies via specialized security bot modules.
Analyzing the File Structure
• The primary source code resides in the "src" directory, which is sub-divided into:
• chatbot: Contains the main business logic, including different versions of bots (e.g., input guardrail bot, output guardrail bot, secure bot, unprotected bot, and a RAG implementation). These encapsulate different security or functionality aspects.
• config: Holds configuration modules for different LLM providers, overall LLM configuration (including security family switches), and logger configuration.
• data: Includes sample data and information (e.g., database_info.txt, jorge.txt) which might feed into the chatbot or help with testing the logic.
• ui: Provides the user interface components – different UI variations aligning with the chatbot modules (e.g., input_guardrail_ui, output_guardrail_ui, basic_ui, etc.).
• Additionally, there is a central entry point (chatbot_webui.py) in src that ties everything together.
• Top-level files like Makefile, pyproject.toml, and the README provide build, dependency management, and project usage instructions.
Key Components
a. Chatbot Logic:
• A "Chatbot Core" block that includes the various implementations:
• Input Guardrail Bot
• Output Guardrail Bot
• Secure Bot
• Unprotected Bot
• RAG (Retrieval-Augmented Generation) Bot
• That these modules manage the processing of incoming requests and security filtering mechanisms.
b. Configuration Layer:
• A "Configuration" block that encompasses the LLM configuration settings, provider-specific modules (Amazon Bedrock, Groq, OpenAI, Anthropic), and logger configurations.
c. User Interface (UI):
• Design a "User Interface" component that contains the various UI modules from the "src/ui" folder.
• This part handles user interactions and displays responses from the chatbot logic.
d. External LLM Providers:
e. Data and Prompts:
• A "Data Layer" that stores prompt definitions (src/prompts.py) and supporting data files from "src/data" which might be used for tailoring the responses or as reference material.
Architectural Relationships and Interactions
• From the UI to the Chatbot Core: Users input text which the chatbot processes.
• From Chatbot Core to Configuration: The core queries configuration for selecting security settings and provider-specific parameters.
• From Chatbot Core to External LLM Providers: Show API calls for generating responses.
• That security modules (Llama PromptGuard & Purple-Llama CodeShield) are integrated within the Chatbot Core to filter requests and responses.
• That the UI and core modules are decoupled from explicit provider implementations via the configuration, facilitating easier adaptation or replacement of LLM providers.