{"id":34989419,"url":"https://github.com/sapientpants/chatbot.ex","last_synced_at":"2026-04-15T13:31:15.775Z","repository":{"id":325713943,"uuid":"1102143282","full_name":"sapientpants/chatbot.ex","owner":"sapientpants","description":"Modern AI chatbot built with Phoenix LiveView and Elixir that connects to LM Studio for local LLM inference. Features real-time streaming, conversation management, and multi-model support.","archived":false,"fork":false,"pushed_at":"2025-11-30T20:42:07.000Z","size":1388,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-01T11:49:55.844Z","etag":null,"topics":["ai","chatbot","elixir","liveview","llm","lm-studio","phoenix","postgresql","streaming","tailwindcss"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sapientpants.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-11-22T22:33:02.000Z","updated_at":"2025-11-30T20:42:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sapientpants/chatbot.ex","commit_stats":null,"previous_names":["sapientpants/chatbot.ex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sapientpants/chatbot.ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sapientpants%2Fchatbot.ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sapientpants%2Fchatbot.ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sapientpants%2Fchatbot.ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sapientpants%2Fchatbot.ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sapientpants","download_url":"https://codeload.github.com/sapientpants/chatbot.ex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sapientpants%2Fchatbot.ex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31842840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T13:28:40.153Z","status":"ssl_error","status_checked_at":"2026-04-15T13:28:29.396Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chatbot","elixir","liveview","llm","lm-studio","phoenix","postgresql","streaming","tailwindcss"],"created_at":"2025-12-27T01:49:35.505Z","updated_at":"2026-04-15T13:31:15.758Z","avatar_url":"https://github.com/sapientpants.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Chatbot with Phoenix LiveView \u0026 LM Studio\n\nA modern, real-time AI chatbot application built with Phoenix LiveView that connects to LM Studio for local LLM\ninference. Features include streaming responses, conversation management, multiple model selection, and export\ncapabilities.\n\n## Features\n\n- 🔐 **User Authentication** - Secure email/password authentication with session management\n- 💬 **Real-time Streaming** - Token-by-token streaming responses from LM Studio\n- 📝 **Conversation Management** - Create, view, and delete conversation threads\n- 🤖 **Model Selection** - Choose from available LM Studio models\n- 📤 **Export Conversations** - Download chats as Markdown or JSON\n- 🎨 **Modern UI** - Built with Tailwind CSS and daisyUI components\n- 🌓 **Theme Support** - Light and dark theme toggle\n\n## Quick Start with Docker\n\nThe fastest way to get started is using Docker:\n\n```bash\n# Clone and enter the repository\ngit clone \u003crepo-url\u003e \u0026\u0026 cd chatbot\n\n# Create environment file with secrets\ncp .env.example .env\nopenssl rand -base64 48  # Copy output to SECRET_KEY_BASE in .env\n\n# Start the application\ndocker compose up --build\n```\n\nThe app will be available at [`http://localhost:4000`](http://localhost:4000).\n\nMake sure both are running on your host machine:\n\n- **LM Studio** at `localhost:1234` (for chat completions)\n- **Ollama** at `localhost:11434` (for embeddings)\n\n## Prerequisites\n\nFor local development without Docker, ensure you have:\n\n- **Elixir** 1.15 or later\n- **Erlang/OTP** 27 or later\n- **PostgreSQL** 14 or later (with pgvector extension for memory features)\n- **Node.js** (for asset compilation)\n- **LM Studio** - Download from [lmstudio.ai](https://lmstudio.ai/) (for chat completions)\n- **Ollama** - Download from [ollama.com](https://ollama.com/) (for embeddings)\n\n## Setup Instructions (Local Development)\n\n### 1. Install Dependencies\n\n```bash\nmix deps.get\ncd assets \u0026\u0026 npm install\ncd ..\n```\n\n### 1.5. Setup Pre-commit Hooks (Recommended)\n\nInstall [pre-commit](https://pre-commit.com/) to automatically run comprehensive code quality checks before committing:\n\n```bash\n# Install pre-commit framework (if not already installed)\n# On macOS with Homebrew:\nbrew install pre-commit\n\n# On other systems:\npip install pre-commit\n\n# Install the git hooks\npre-commit install\n```\n\nThe pre-commit framework runs these checks automatically:\n\n- **Security audit** - Checks for vulnerable dependencies with `mix hex.audit`\n- **Code formatting** - Validates formatting with `mix format`\n- **Compilation** - Strict compilation with warnings as errors\n- **Static analysis** - Code quality checks with Credo\n- **Security scanning** - Phoenix-specific security analysis with Sobelow\n- **Tests with coverage** - Full test suite with 10% minimum coverage (goal: 80%)\n- **YAML/Markdown linting** - Validates documentation and config files\n- **GitHub Actions validation** - Ensures workflow files are valid\n\nYou can also run all checks manually:\n\n```bash\n# Run all pre-commit hooks\npre-commit run --all-files\n\n# Or use the mix alias\nmix precommit\n\n# Or use ex_check for a unified experience\nmix check\n```\n\n### 2. Configure Database\n\nThe default database configuration uses:\n\n- Host: `localhost`\n- Username: `postgres`\n- Password: `postgres`\n- Database: `chatbot_dev`\n\nIf you need to change these, edit `config/dev.exs`.\n\n### 3. Create and Migrate Database\n\n```bash\nmix ecto.setup\n```\n\nThis will:\n\n- Create the database\n- Run migrations\n- Run seeds (if any)\n\n### 4. Setup LM Studio\n\n1. **Download and Install LM Studio**\n   - Visit [lmstudio.ai](https://lmstudio.ai/)\n   - Download and install for your platform\n\n2. **Download a Model**\n   - Open LM Studio\n   - Browse the model catalog\n   - Download a model (e.g., Llama 2, Mistral, etc.)\n\n3. **Start the Local Server**\n   - In LM Studio, go to the \"Local Server\" tab\n   - Load your downloaded model\n   - Click \"Start Server\"\n   - The server should start on `http://localhost:1234` by default\n\n4. **Configure LM Studio URL (Optional)**\n\n   If LM Studio is running on a different port, set the environment variable:\n\n   ```bash\n   export LM_STUDIO_URL=\"http://localhost:YOUR_PORT/v1\"\n   ```\n\n   Or edit `config/dev.exs`:\n\n   ```elixir\n   config :chatbot, :lm_studio_url, \"http://localhost:YOUR_PORT/v1\"\n   ```\n\n### 5. Start Phoenix Server\n\n```bash\nmix phx.server\n```\n\nOr run inside IEx for interactive development:\n\n```bash\niex -S mix phx.server\n```\n\nThe application will be available at [`http://localhost:4000`](http://localhost:4000)\n\n## Usage\n\n### 1. Register an Account\n\n- Navigate to \u003chttp://localhost:4000/register\u003e\n- Enter your email and password (minimum 12 characters)\n- Click \"Create an account\"\n\n### 2. Log In\n\n- Navigate to \u003chttp://localhost:4000/login\u003e\n- Enter your credentials\n- Click \"Log in\"\n\n### 3. Start Chatting\n\n- You'll be redirected to the chat interface at `/chat`\n- Select a model from the dropdown (if multiple models are available)\n- Type your message in the input field\n- Press Send or hit Enter\n- Watch as the AI responds in real-time with streaming\n\n### 4. Manage Conversations\n\n- **New Chat**: Click the \"New Chat\" button in the sidebar\n- **Switch Conversations**: Click on any conversation in the sidebar\n- **Delete Conversation**: Open a conversation, click \"Actions\" → \"Delete Conversation\"\n\n### 5. Export Conversations\n\n- Open a conversation\n- Click \"Actions\" in the header\n- Choose \"Export as Markdown\" or \"Export as JSON\"\n- The file will download automatically\n\n## Project Structure\n\n```text\nchatbot/\n├── lib/\n│   ├── chatbot/\n│   │   ├── accounts/          # User authentication\n│   │   │   └── user.ex        # User schema\n│   │   ├── chat/              # Chat functionality\n│   │   │   ├── conversation.ex\n│   │   │   └── message.ex\n│   │   ├── accounts.ex        # Accounts context\n│   │   ├── chat.ex            # Chat context\n│   │   ├── lm_studio.ex       # LM Studio API client\n│   │   └── repo.ex            # Database repository\n│   └── chatbot_web/\n│       ├── live/\n│       │   ├── auth/          # Authentication LiveViews\n│       │   │   ├── login_live.ex\n│       │   │   └── registration_live.ex\n│       │   └── chat/          # Chat LiveViews\n│       │       ├── index.ex   # New conversation\n│       │       └── show.ex    # Existing conversation\n│       ├── components/        # Reusable components\n│       ├── controllers/       # Traditional controllers\n│       ├── router.ex          # Route definitions\n│       └── user_auth.ex       # Authentication plugs\n├── priv/\n│   └── repo/\n│       └── migrations/        # Database migrations\n├── assets/                    # Frontend assets\n│   ├── css/\n│   └── js/\n└── config/                    # Configuration files\n```\n\n## Database Schema\n\nThe application uses UUIDv7 for all primary keys:\n\n### Users Table\n\n- `id` (binary_id, UUIDv7)\n- `email` (string, unique)\n- `hashed_password` (string)\n- `inserted_at`, `updated_at` (timestamps)\n\n### Conversations Table\n\n- `id` (binary_id, UUIDv7)\n- `user_id` (foreign key to users)\n- `title` (string)\n- `model_name` (string)\n- `inserted_at`, `updated_at` (timestamps)\n\n### Messages Table\n\n- `id` (binary_id, UUIDv7)\n- `conversation_id` (foreign key to conversations)\n- `role` (string: \"user\", \"assistant\", \"system\")\n- `content` (text)\n- `tokens_used` (integer, nullable)\n- `inserted_at`, `updated_at` (timestamps)\n\n## Development\n\n### Running Tests\n\n```bash\nmix test\n```\n\n### Code Formatting\n\n```bash\nmix format\n```\n\n### Pre-commit Checks\n\nRun all quality checks before committing:\n\n```bash\n# Recommended: Use pre-commit framework (runs all checks)\npre-commit run --all-files\n\n# Or use the mix alias (Elixir checks only)\nmix precommit\n\n# Or use ex_check for unified output\nmix check\n```\n\nThe comprehensive check suite includes:\n\n1. **Security audit** - `mix hex.audit` (checks for retired/vulnerable packages)\n2. **Code formatting** - `mix format --check-formatted`\n3. **Compilation** - `mix compile --warning-as-errors`\n4. **Static analysis** - `mix credo --strict` (code quality and consistency)\n5. **Security scanning** - `mix sobelow --config` (Phoenix security best practices)\n6. **Test coverage** - `mix coveralls` (enforces 10% minimum via coveralls.json; goal: 80%)\n7. **Dependency cleanup** - `mix deps.unlock --unused`\n\nAdditional tools available:\n\n- **Type checking** - `mix dialyzer` (slower, runs in CI by default)\n- **Unused deps** - `mix deps.audit` (finds unused dependencies)\n\n### Database Management\n\n```bash\n# Create database\nmix ecto.create\n\n# Run migrations\nmix ecto.migrate\n\n# Rollback last migration\nmix ecto.rollback\n\n# Reset database (drop, create, migrate, seed)\nmix ecto.reset\n```\n\n## Troubleshooting\n\n### LM Studio Connection Issues\n\n#### Error: \"Could not connect to LM Studio. Is it running?\"\n\nSolutions:\n\n1. Ensure LM Studio is running\n2. Verify the local server is started in LM Studio\n3. Check that a model is loaded\n4. Confirm the server is running on `http://localhost:1234`\n5. Check firewall settings\n\n### Database Connection Issues\n\n#### Error: \"Connection refused\" or \"Database does not exist\"\n\nSolutions:\n\n1. Ensure PostgreSQL is running\n2. Verify credentials in `config/dev.exs`\n3. Run `mix ecto.create` to create the database\n4. Run `mix ecto.migrate` to apply migrations\n\n### Asset Compilation Issues\n\n#### Error: \"esbuild not found\" or \"tailwind not found\"\n\nSolutions:\n\n```bash\nmix assets.setup\n```\n\n## Configuration\n\n### Environment Variables\n\n- `LM_STUDIO_URL` - LM Studio API endpoint (default: `http://localhost:1234/v1`)\n- `PORT` - Phoenix server port (default: `4000`)\n- `DATABASE_URL` - PostgreSQL connection string (optional, uses config/dev.exs by default)\n\n### Customizing Themes\n\nThe application uses daisyUI themes configured in `assets/css/app.css`. You can customize colors by editing the theme definitions.\n\n## Production Deployment\n\nFor production deployment:\n\n1. Set environment variables:\n\n   ```bash\n   export SECRET_KEY_BASE=\"your-secret-key\"\n   export DATABASE_URL=\"your-database-url\"\n   export LM_STUDIO_URL=\"your-lm-studio-url\"\n   ```\n\n2. Build assets:\n\n   ```bash\n   mix assets.deploy\n   ```\n\n3. Run migrations:\n\n   ```bash\n   mix ecto.migrate\n   ```\n\n4. Start the server:\n\n   ```bash\n   mix phx.server\n   ```\n\nFor more detailed deployment instructions, see the [Phoenix deployment guide](https://hexdocs.pm/phoenix/deployment.html).\n\n## Technology Stack\n\n### Core Application\n\n- **Backend**: Phoenix Framework 1.8, Elixir 1.15\n- **Database**: PostgreSQL with Ecto\n- **Real-time**: Phoenix LiveView 1.1\n- **Authentication**: bcrypt_elixir\n- **HTTP Client**: Req\n- **Frontend**: Tailwind CSS v4, daisyUI\n- **Icons**: Heroicons\n- **Markdown**: Earmark\n- **Syntax Highlighting**: Makeup\n\n### Code Quality \u0026 Development Tools\n\n- **Pre-commit Framework**: Automated git hooks for quality checks\n- **Credo**: Static code analysis for Elixir\n- **Dialyzer**: Type checking and static analysis\n- **Sobelow**: Security-focused static analysis for Phoenix\n- **ExCoveralls**: Test coverage tracking (10% minimum enforced; goal: 80%)\n- **ex_check**: Unified tool runner for all checks\n- **mix_audit**: Dependency auditing\n\n## License\n\nThis project is available under the MIT License.\n\n## Learn More\n\n### Phoenix Framework\n\n- Official website: \u003chttps://www.phoenixframework.org/\u003e\n- Guides: \u003chttps://hexdocs.pm/phoenix/overview.html\u003e\n- Docs: \u003chttps://hexdocs.pm/phoenix\u003e\n- Forum: \u003chttps://elixirforum.com/c/phoenix-forum\u003e\n- Source: \u003chttps://github.com/phoenixframework/phoenix\u003e\n\n### LM Studio\n\n- Website: \u003chttps://lmstudio.ai/\u003e\n- Documentation: \u003chttps://lmstudio.ai/docs\u003e\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsapientpants%2Fchatbot.ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsapientpants%2Fchatbot.ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsapientpants%2Fchatbot.ex/lists"}