{"id":27182821,"url":"https://github.com/stackloklabs/mockllm","last_synced_at":"2025-08-30T22:13:08.822Z","repository":{"id":277445601,"uuid":"932453085","full_name":"StacklokLabs/mockllm","owner":"StacklokLabs","description":"MockLLM, when you want it to do what you tell it to do!","archived":false,"fork":false,"pushed_at":"2025-04-08T11:58:30.000Z","size":1237,"stargazers_count":48,"open_issues_count":8,"forks_count":0,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-09T15:17:48.755Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StacklokLabs.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}},"created_at":"2025-02-13T23:53:06.000Z","updated_at":"2025-04-09T10:12:52.000Z","dependencies_parsed_at":"2025-03-03T10:24:05.493Z","dependency_job_id":"c36d7210-2741-4442-9fd1-426b2cdaa1ff","html_url":"https://github.com/StacklokLabs/mockllm","commit_stats":null,"previous_names":["lukehinds/mockllm","stacklok/mockllm","stackloklabs/mockllm"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StacklokLabs%2Fmockllm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StacklokLabs%2Fmockllm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StacklokLabs%2Fmockllm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StacklokLabs%2Fmockllm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StacklokLabs","download_url":"https://codeload.github.com/StacklokLabs/mockllm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055269,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2025-04-09T15:18:03.141Z","updated_at":"2025-04-09T15:18:03.856Z","avatar_url":"https://github.com/StacklokLabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mock LLM Server\n\n[![CI](https://github.com/stacklok/mockllm/actions/workflows/ci.yml/badge.svg)](https://github.com/stacklok/mockllm/actions/workflows/ci.yml)\n[![PyPI version](https://badge.fury.io/py/mockllm.svg)](https://badge.fury.io/py/mockllm)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n![mockllm-logo](assets/logo.png)\n\nAn LLM simulator that mimics OpenAI and Anthropic API formats. Instead of calling\na large language model, it uses predefined responses from a YAML configuration\nfile. \n\nThis is made for when you want a deterministic response for testing, demos or development purposes.\n\n## Features\n\n- OpenAI and Anthropic compatible API endpoints\n- Streaming support (character-by-character response streaming)\n- Configurable responses via YAML file\n- Hot-reloading of response configurations\n- Mock token counting\n\n## Configuration\n\n### Response Configuration\n\nResponses are configured in `responses.yml`. The file has three main sections:\n\n1. `responses`: Maps input prompts to predefined responses\n2. `defaults`: Contains default configurations like the unknown response message\n3. `settings`: Contains server behavior settings like network lag simulation\n\nExample `responses.yml`:\n```yaml\nresponses:\n  \"write a python function to calculate factorial\": \"def factorial(n):\\n    if n == 0:\\n        return 1\\n    return n * factorial(n - 1)\"\n  \"what colour is the sky?\": \"The sky is purple except on Tuesday when it is  hue green.\"\n  \"what is 2+2?\": \"2+2 equals 9.\"\n\ndefaults:\n  unknown_response: \"I don't know the answer to that. This is a mock response.\"\n\nsettings:\n  lag_enabled: true\n  lag_factor: 10  # Higher values = faster responses (10 = fast, 1 = slow)\n```\n\n### Network Lag Simulation\n\nThe server can simulate network latency for more realistic testing scenarios. This is controlled by two settings:\n\n- `lag_enabled`: When true, enables artificial network lag\n- `lag_factor`: Controls the speed of responses\n  - Higher values (e.g., 10) result in faster responses\n  - Lower values (e.g., 1) result in slower responses\n  - Affects both streaming and non-streaming responses\n\nFor streaming responses, the lag is applied per-character with slight random variations to simulate realistic network conditions.\n\n### Hot Reloading\n\nThe server automatically detects changes to `responses.yml` and reloads the configuration without restarting the server.\n\n## Installation\n\n### From PyPI\n\n```bash\npip install mockllm\n```\n\n### From Source\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/stacklok/mockllm.git\ncd mockllm\n```\n\n2. Install Poetry (if not already installed):\n```bash\ncurl -sSL https://install.python-poetry.org | python3 -\n```\n\n3. Install dependencies:\n```bash\npoetry install  # Install with all dependencies\n# or\npoetry install --without dev  # Install without development dependencies\n```\n\n## Usage\n\n### CLI Commands\n\nMockLLM provides a command-line interface for managing the server and validating configurations:\n\n```bash\n# Show available commands and options\nmockllm --help\n\n# Show version\nmockllm --version\n\n# Start the server with default settings\nmockllm start\n\n# Start with custom responses file\nmockllm start --responses custom_responses.yml\n\n# Start with custom host and port\nmockllm start --host localhost --port 3000\n\n# Validate a responses file\nmockllm validate responses.yml\n```\n\n### Quick Start\n\n1. Set up the responses.yml:\n```bash\ncp example.responses.yml responses.yml\n```\n\n2. Validate your responses file (optional):\n```bash\nmockllm validate responses.yml\n```\n\n3. Start the server:\n```bash\nmockllm start --responses responses.yml\n```\n\nThe server will start on `http://localhost:8000` by default.\n\n### API Endpoints\n\n#### OpenAI Format\n\nRegular request:\n```bash\ncurl -X POST http://localhost:8000/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"mock-llm\",\n    \"messages\": [\n      {\"role\": \"user\", \"content\": \"what colour is the sky?\"}\n    ]\n  }'\n```\n\nStreaming request:\n```bash\ncurl -X POST http://localhost:8000/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"mock-llm\",\n    \"messages\": [\n      {\"role\": \"user\", \"content\": \"what colour is the sky?\"}\n    ],\n    \"stream\": true\n  }'\n```\n\n#### Anthropic Format\n\nRegular request:\n```bash\ncurl -X POST http://localhost:8000/v1/messages \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"claude-3-sonnet-20240229\",\n    \"messages\": [\n      {\"role\": \"user\", \"content\": \"what colour is the sky?\"}\n    ]\n  }'\n```\n\nStreaming request:\n```bash\ncurl -X POST http://localhost:8000/v1/messages \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"claude-3-sonnet-20240229\",\n    \"messages\": [\n      {\"role\": \"user\", \"content\": \"what colour is the sky?\"}\n    ],\n    \"stream\": true\n  }'\n```\n\n## Testing\n\nTo run the tests:\n```bash\npoetry run pytest\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a PR.\n\nCheck out the [CodeGate](https://github.com/stacklok/codegate) project when you're done here!\n\n## License\n\nThis project is licensed under the [Apache 2.0 License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackloklabs%2Fmockllm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackloklabs%2Fmockllm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackloklabs%2Fmockllm/lists"}