Model Theater: A Lightweight PHP Framework for Local LLMs
The Concept: The Stage, the Actor, and the Script
Core Features and Architecture
Why PHP for LLM Orchestration?
Conclusion
The rise of local Large Language Models (LLMs) has opened up new opportunities for developers who prioritize privacy, low latency, and modularity. However, managing the interaction between raw data, systemic personas, and model execution often requires complex frameworks.
Enter Model Theater, a lightweight PHP framework designed specifically for `llama-server`. It treats the interaction between human and AI as a staged performance, where the environment, the actor (persona), and the script (RAG context) are seamlessly integrated.
Model Theater operates like a theater, with three distinct components working together to create a cohesive user experience:
1. The Actor (Persona Selection)
Users can define specific roles for the LLM. Whether it is an academic, a creative writer, or a technical debugger, the framework handles system prompts that define these personalities.
2. The Script (PRRS Integration)
Utilizing the PHP Raw RAG System (PRRS), the framework dynamically injects relevant context into the conversation. It "feeds the actor the right lines" by fetching data from your local knowledge base.
3. The Stage (Dynamic UI)
Unlike generic chat interfaces, Model Theater allows the UI to adapt based on the chosen persona. A "hacker" persona might trigger a dark, terminal-style interface, while a "poet" persona might offer a minimalist, serif-heavy writing environment.
1. Seamless llama-server Integration
Model Theater is built to communicate directly with the llama-cpp server (or any OpenAI-compatible local endpoint). This keeps the infrastructure entirely local, ensuring that your data — and the context retrieved via PRRS — never leaves your machine.
2. Contextual Precision with PRRS
By integrating the PHP Raw RAG System, Model Theater solves the "memory" problem of LLMs. Before the model generates a response, the framework:
- Scans the user’s input.
- Queries the PRRS library to find the most relevant vector-matched chunks from your .csv or SQLite database.
- Constructs a composite prompt that grounds the "actor" in factual, proprietary data.
3. Persona-Driven UI Customization
One of the unique aspects of Model Theater is the tight coupling between the "system prompt" and the "frontend". By defining a persona in a simple PHP configuration file, developers can specify CSS classes or themes. This provides immediate visual feedback to the user, signaling which "mode" the assistant is currently operating in.
While the AI world is dominated by Python, Model Theater leverages the strengths of PHP for the "orchestration layer":
- Ease of Deployment: It runs on standard Apache/Nginx setups.
- State Management: PHP’s ability to handle sessions and database interactions makes managing conversation history and persona settings straightforward.
- Template Logic: Using PHP for the UI allows for rapid, server-side rendering of the customized "stage" for each actor.
Model Theater is more than a chat interface; it is a management system for local intelligence. By combining the deterministic nature of PRRS with a flexible persona and UI engine, it provides PHP developers with a professional-grade tool to build sophisticated AI applications. Whether you are building an internal knowledge assistant or a creative writing tool, Model Theater provides the stage for your models to shine.