{"id":48883969,"url":"https://github.com/codeer-ai/lybot","last_synced_at":"2026-04-16T04:06:16.133Z","repository":{"id":302669883,"uuid":"1012900215","full_name":"codeer-ai/lybot","owner":"codeer-ai","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-13T08:11:53.000Z","size":408,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-13T10:11:58.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://codeer-ai.github.io/lybot/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeer-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-07-03T04:13:32.000Z","updated_at":"2025-07-13T08:11:56.000Z","dependencies_parsed_at":"2025-07-13T10:07:40.250Z","dependency_job_id":null,"html_url":"https://github.com/codeer-ai/lybot","commit_stats":null,"previous_names":["codeer-ai/lybot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codeer-ai/lybot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeer-ai%2Flybot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeer-ai%2Flybot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeer-ai%2Flybot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeer-ai%2Flybot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeer-ai","download_url":"https://codeload.github.com/codeer-ai/lybot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeer-ai%2Flybot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31870528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"online","status_checked_at":"2026-04-16T02:00:06.042Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2026-04-16T04:06:15.177Z","updated_at":"2026-04-16T04:06:16.125Z","avatar_url":"https://github.com/codeer-ai.png","language":"Python","readme":"# LyBot - 台灣立法院研究助理 🏛️\n\nA comprehensive AI-powered research assistant for querying Taiwan's Legislative Yuan (立法院) data. Built with Google's Gemini 2.5 Pro model and the pydantic-ai framework, it provides conversational access to legislative information through CLI, web interface, and API.\n\n🚀 **Live Demo**: [https://andydai.github.io/lybot/](https://andydai.github.io/lybot/) | **API**: [https://lybot-z5pc.onrender.com/v1](https://lybot-z5pc.onrender.com/v1)\n\n## ✨ Features\n\n- **40+ Specialized Tools** for comprehensive legislative data analysis\n- **Traditional Chinese Interface** with natural language understanding\n- **Modern Web UI** with real-time streaming responses and tool visualization\n- **OpenAI-Compatible API** for seamless integration with existing tools\n- **CLI Tool** for terminal-based interactions\n- **Comprehensive Coverage**: \n  - 👥 Legislators: profiles, committees, attendance\n  - 📜 Bills: search, details, co-signers, progress tracking\n  - 🗳️ Voting Records: extraction from gazette PDFs\n  - 💬 Interpellations: speeches and position analysis\n  - 📊 Analytics: party statistics, cross-party cooperation, performance metrics\n\n## Quick Start\n\n### Prerequisites\n\n- Python \u003e=3.12\n- Node.js 18+ (for web frontend)\n- Google API Key for Gemini model\n\n### Installation\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/yourusername/lybot.git\ncd lybot\n```\n\n2. Install Python dependencies using `uv` (modern Python package manager):\n```bash\n# Install uv if you haven't already\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# Install project dependencies\nuv sync\n```\n\n3. Set up your API key and LLM MODEL:\n\n```bash\n# GOOGLE\nexport GEMINI_API_KEY=\"your-api-key-here\"    \n# OPENAI\nexport OPENAI_API_KEY=\"...\"\n\n# AZURE\nexport AZURE_OPENAI_ENDPOINT=\"...\"\nexport AZURE_OPENAI_API_KEY=\"...\"\nexport OPENAI_API_VERSION=\"...\"\n\n# LLM Model\nexport LLM_MODEL=\"azure:gpt-4.1\"     # AZURE\nexport LLM_MODEL=\"google-gla:gemini-2.5-flash\"   # GOOGLE   \nexport LLM_MODEL=\"openai:gpt-4o\"  # OpenAI\n```\n\n4. Run\n```\nuv run python api.py\n```\n\n### Configuration\n\n#### API URL Configuration\n\nThe LyBot API can be accessed locally or via the deployed instance:\n\n**Default Production URL**: `https://lybot-z5pc.onrender.com/v1`\n\n**For Frontend (Web UI)**:\n```bash\n# Create a .env file in the frontend directory\ncd frontend\necho \"VITE_API_BASE_URL=http://localhost:8000/v1\" \u003e .env\n\n# Or use a custom deployment\necho \"VITE_API_BASE_URL=https://your-custom-api.com/v1\" \u003e .env\n```\n\n**For Python Clients**:\n```python\n# Using OpenAI client\nfrom openai import OpenAI\n\n# Local development\nclient = OpenAI(\n    base_url=\"http://localhost:8000/v1/\",\n    api_key=\"not-needed\"  # No API key required for local\n)\n\n# Production deployment\nclient = OpenAI(\n    base_url=\"https://lybot-z5pc.onrender.com/v1/\",\n    api_key=\"not-needed\"\n)\n```\n\n### Running the Application\n\n#### Option 1: CLI Mode\n```bash\npython main.py\n```\n\n#### Option 2: Web Interface\n1. Start the API server:\n```bash\n./run_api.sh\n# or manually: uvicorn api:app --host 0.0.0.0 --port 8000\n```\n\n2. In a new terminal, start the frontend:\n```bash\ncd frontend\nnpm install  # first time only\n./run_frontend.sh\n# or manually: npm run dev\n```\n\n3. Open http://localhost:5173 in your browser\n\n#### Option 3: API Client\n```python\n# See example_client.py for comprehensive examples\nfrom openai import OpenAI\n\n# Configure the client with your API URL\nclient = OpenAI(\n    base_url=\"http://localhost:8000/v1/\",  # Local development\n    # base_url=\"https://lybot-z5pc.onrender.com/v1/\",  # Production\n    api_key=\"not-needed\"  # No API key required\n)\n\nresponse = client.chat.completions.create(\n    model=\"gemini-2.0-flash-thinking-exp-01-21\",\n    messages=[{\"role\": \"user\", \"content\": \"誰是台北市第七選區的立委？\"}]\n)\nprint(response.choices[0].message.content)\n```\n\n## Available Tools\n\n### Legislator Tools\n- Search by constituency, party, or name\n- Get detailed profiles and committee memberships\n- Track proposed bills and meeting attendance\n- Analyze party statistics\n\n### Bill and Proposal Tools\n- Search bills by keyword, proposer, or session\n- Get bill details and co-signers\n- Analyze legislator bill proposals\n- Track bill progress\n\n### Meeting and Voting Tools\n- Search gazette records\n- Extract voting records from PDFs\n- Calculate attendance rates\n- Compare legislator performance\n\n### Analysis Tools\n- Cross-party cooperation analysis\n- Voting alignment tracking\n- Activity ranking\n- Performance comparisons\n\n## 📁 Project Structure\n\n```\nlybot/\n├── main.py              # CLI entry point with pydantic-ai agent\n├── api.py               # FastAPI server with OpenAI-compatible endpoints\n├── tools/               # Legislative data tools (40+ tools)\n│   ├── legislators.py   # Legislator queries and profiles\n│   ├── bills.py         # Bill search and analysis\n│   ├── gazettes.py      # Gazette and voting records\n│   ├── interpellations.py # Speech records\n│   ├── meetings.py      # Meeting attendance\n│   └── analysis.py      # Advanced analytics\n├── prompts/             # Agent system prompts (Traditional Chinese)\n├── models.py            # Data models and types\n├── frontend/            # React + TypeScript web interface\n│   ├── src/\n│   │   ├── components/  # UI components (shadcn/ui)\n│   │   └── lib/         # API client and utilities\n│   └── dist/            # Production build\n├── example_client.py    # API usage examples\n├── run_api.sh          # API server launcher\n└── pyproject.toml      # Project dependencies (managed by uv)\n```\n\n## 🛠️ Development\n\n### Tech Stack\n\n- **Backend**: Python 3.12+, FastAPI, pydantic-ai, asyncio\n- **AI Model**: Google Gemini 2.5 Pro (with experimental thinking mode)\n- **Frontend**: React, TypeScript, Vite, shadcn/ui, Tailwind CSS v4\n- **Package Management**: uv (Python), npm (Node.js)\n- **Data Source**: [Taiwan Legislative Yuan API](https://ly.govapi.tw/)\n\n### Adding New Tools\n\n1. Create a new tool in the `tools/` directory\n2. Follow the existing async pattern with proper error handling\n3. Register the tool in the agent configuration\n4. Update type definitions if needed\n\n### Frontend Development\n\n```bash\ncd frontend\nnpm run dev    # Development server with hot reload\nnpm run build  # Production build\nnpm run preview # Preview production build\n```\n\n**Key Features:**\n- Real-time streaming with Server-Sent Events (SSE)\n- Tool call visualization showing AI's reasoning process\n- Responsive design with mobile support\n- Dark/light theme toggle\n- Enhanced markdown rendering for legislative transcripts\n\n### API Development\n\nThe API follows OpenAI's chat completions format, making it compatible with most LLM client libraries.\n\n**Endpoints:**\n- `POST /v1/chat/completions` - Main chat endpoint\n- `GET /v1/models` - List available models\n- Full CORS support for web clients\n\n## API Endpoints\n\n- `POST /v1/chat/completions` - Main chat endpoint (streaming/non-streaming)\n- `GET /v1/models` - List available models\n\n## Configuration\n\n- **GOOGLE_API_KEY**: Required for Gemini model access\n- **Frontend**: Configure in `frontend/.env` if needed\n- **API Port**: Default 8000, configurable in `run_api.sh`\n\n## 💡 Examples\n\n### CLI Usage\n```bash\n# Interactive mode\npython main.py\n\n# Example queries:\n\u003e 誰是台北市第七選區的立委？\n\u003e 民進黨有多少席次？\n\u003e 最近有哪些關於環保的法案？\n\u003e 分析國民黨和民進黨在勞工議題上的立場差異\n\u003e 找出跨黨派合作的法案\n```\n\n### Web Interface\n- Modern chat interface with message history\n- Real-time streaming responses with thinking process\n- Tool call visualization showing data sources\n- Professional Taiwan Legislative Yuan branding\n- Dark/light theme support\n- Optimized for Chinese typography\n\n### API Usage Examples\n\n**Using the Production Deployment**:\n```python\n# No local setup required - use the deployed API\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"https://lybot-z5pc.onrender.com/v1/\",\n    api_key=\"not-needed\"\n)\n\n# Basic query\nresponse = client.chat.completions.create(\n    model=\"gemini-2.0-flash-thinking-exp-01-21\",\n    messages=[{\"role\": \"user\", \"content\": \"民進黨有幾位立委？\"}]\n)\nprint(response.choices[0].message.content)\n\n# Streaming example\nfor chunk in client.chat.completions.create(\n    model=\"gemini-2.0-flash-thinking-exp-01-21\",\n    messages=[{\"role\": \"user\", \"content\": \"分析立委出席率\"}],\n    stream=True\n):\n    if chunk.choices[0].delta.content:\n        print(chunk.choices[0].delta.content, end=\"\")\n```\n\n**Using httpx for direct API calls**:\n```python\nimport httpx\n\n# Production API\nresponse = httpx.post(\n    \"https://lybot-z5pc.onrender.com/v1/chat/completions\",\n    json={\n        \"model\": \"gemini-2.0-flash-thinking-exp-01-21\",\n        \"messages\": [{\"role\": \"user\", \"content\": \"誰是高雄市第一選區立委？\"}],\n        \"stream\": False\n    }\n)\nprint(response.json()[\"choices\"][0][\"message\"][\"content\"])\n```\n\n## License\n\nThis project is licensed under the MIT License - see LICENSE file for details.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n### Development Guidelines\n- Follow existing code patterns and async conventions\n- Add tests for new features\n- Update documentation as needed\n- Use Traditional Chinese for user-facing strings\n- Ensure compatibility with the 11th Legislative Yuan term data\n\n## 🙏 Acknowledgments\n\n- **Data Source**: [Taiwan Legislative Yuan Open Data](https://ly.govapi.tw/)\n- **AI Model**: Google Gemini 2.5 Pro with experimental thinking mode\n- **UI Components**: [shadcn/ui](https://ui.shadcn.com/)\n- **Framework**: [pydantic-ai](https://docs.pydantic.dev/ai/latest/) for structured AI interactions\n\n## 🔗 Related Projects\n\n- [Taiwan Legislative Yuan API Documentation](https://ly.govapi.tw/)\n- [pydantic-ai Documentation](https://docs.pydantic.dev/ai/latest/)\n- [Gemini API Documentation](https://ai.google.dev/)\n\n---\n\n\u003cp align=\"center\"\u003eMade with ❤️ for Taiwan's democratic transparency\u003c/p\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeer-ai%2Flybot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeer-ai%2Flybot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeer-ai%2Flybot/lists"}