1
1
# Mock LLM Server
2
2
3
- [ ![ CI] ( https://github.com/lukehinds /mockllm/actions/workflows/ci.yml/badge.svg )] ( https://github.com/lukehinds /mockllm/actions/workflows/ci.yml )
3
+ [ ![ CI] ( https://github.com/stacklok /mockllm/actions/workflows/ci.yml/badge.svg )] ( https://github.com/stacklok /mockllm/actions/workflows/ci.yml )
4
4
[ ![ PyPI version] ( https://badge.fury.io/py/mockllm.svg )] ( https://badge.fury.io/py/mockllm )
5
- [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
5
+ [ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( https://opensource.org/licenses/Apache-2.0 )
6
+
6
7
7
8
A FastAPI-based mock LLM server that mimics OpenAI and Anthropic API formats. Instead of calling actual language models,
8
9
it uses predefined responses from a YAML configuration file.
9
10
10
11
This is made for when you want a deterministic response for testing or development purposes.
11
12
12
- Check out the [ CodeGate] ( https://github.com/stacklok/codegate ) when you're done here!
13
-
14
- ## Project Structure
15
-
16
- ```
17
- mockllm/
18
- ├── src/
19
- │ └── mockllm/
20
- │ ├── __init__.py
21
- │ ├── config.py # Response configuration handling
22
- │ ├── models.py # Pydantic models for API
23
- │ └── server.py # FastAPI server implementation
24
- ├── tests/
25
- │ └── test_server.py # Test suite
26
- ├── example.responses.yml # Example response configuration
27
- ├── LICENSE # MIT License
28
- ├── MANIFEST.in # Package manifest
29
- ├── README.md # This file
30
- ├── pyproject.toml # Project configuration
31
- └── requirements.txt # Dependencies
32
- ```
13
+ Check out the [ CodeGate] ( https://github.com/stacklok/codegate ) project when you're done here!
33
14
34
15
## Features
35
16
@@ -53,7 +34,7 @@ pip install mockllm
53
34
54
35
1 . Clone the repository:
55
36
``` bash
56
- git clone https://github.com/lukehinds /mockllm.git
37
+ git clone https://github.com/stacklok /mockllm.git
57
38
cd mockllm
58
39
```
59
40
@@ -168,114 +149,49 @@ defaults:
168
149
169
150
The server automatically detects changes to ` responses.yml` and reloads the configuration without requiring a restart.
170
151
171
- # # API Format
172
-
173
- # ## OpenAI Format
174
-
175
- # ### Request Format
176
-
177
- ` ` ` json
178
- {
179
- "model": "mock-llm",
180
- "messages": [
181
- {"role": "user", "content": "what colour is the sky?"}
182
- ],
183
- "temperature": 0.7,
184
- "max_tokens": 150,
185
- "stream": false
186
- }
187
- ` ` `
188
-
189
- # ### Response Format
190
-
191
- Regular response :
192
- ` ` ` json
193
- {
194
- "id": "mock-123",
195
- "object": "chat.completion",
196
- "created": 1700000000,
197
- "model": "mock-llm",
198
- "choices": [
199
- {
200
- "message": {
201
- "role": "assistant",
202
- "content": "The sky is blue during a clear day due to a phenomenon called Rayleigh scattering."
203
- },
204
- "finish_reason": "stop"
205
- }
206
- ],
207
- "usage": {
208
- "prompt_tokens": 10,
209
- "completion_tokens": 5,
210
- "total_tokens": 15
211
- }
212
- }
213
- ` ` `
214
-
215
- Streaming response (Server-Sent Events format) :
216
- ` ` `
217
- data: {"id":"mock-123","object":"chat.completion.chunk","created":1700000000,"model":"mock-llm","choices":[{"delta":{"role":"assistant"},"index":0}]}
152
+ # # Development
218
153
219
- data: {"id":"mock-124","object":"chat.completion.chunk","created":1700000000,"model":"mock-llm","choices":[{"delta":{"content":"T"},"index":0}]}
154
+ The project includes a Makefile to help with common development tasks :
220
155
221
- data: {"id":"mock-125","object":"chat.completion.chunk","created":1700000000,"model":"mock-llm","choices":[{"delta":{"content":"h"},"index":0}]}
156
+ ` ` ` bash
157
+ # Set up development environment
158
+ make setup
222
159
223
- ... (character by character)
160
+ # Run all checks (setup, lint, test)
161
+ make all
224
162
225
- data: {"id":"mock-999","object":"chat.completion.chunk","created":1700000000,"model":"mock-llm","choices":[{"delta":{},"index":0,"finish_reason":"stop"}]}
163
+ # Run tests
164
+ make test
226
165
227
- data: [DONE]
228
- ` ` `
166
+ # Format code
167
+ make format
229
168
230
- # ## Anthropic Format
169
+ # Run all linting and type checking
170
+ make lint
231
171
232
- # ### Request Format
233
-
234
- ` ` ` json
235
- {
236
- "model": "claude-3-sonnet-20240229",
237
- "messages": [
238
- {"role": "user", "content": "what colour is the sky?"}
239
- ],
240
- "max_tokens": 1024,
241
- "stream": false
242
- }
243
- ` ` `
172
+ # Clean up build artifacts
173
+ make clean
244
174
245
- # ### Response Format
246
-
247
- Regular response :
248
- ` ` ` json
249
- {
250
- "id": "mock-123",
251
- "type": "message",
252
- "role": "assistant",
253
- "model": "claude-3-sonnet-20240229",
254
- "content": [
255
- {
256
- "type": "text",
257
- "text": "The sky is blue during a clear day due to a phenomenon called Rayleigh scattering."
258
- }
259
- ],
260
- "usage": {
261
- "input_tokens": 10,
262
- "output_tokens": 5,
263
- "total_tokens": 15
264
- }
265
- }
175
+ # See all available commands
176
+ make help
266
177
` ` `
267
178
268
- Streaming response (Server-Sent Events format) :
269
- ` ` `
270
- data: {"type":"message_delta","id":"mock-123","delta":{"type":"content_block_delta","index":0,"delta":{"text":"T"}}}
179
+ # ## Development Commands
271
180
272
- data: {"type":"message_delta","id":"mock-123","delta":{"type":"content_block_delta","index":0,"delta":{"text":"h"}}}
181
+ - `make setup` : Install all development dependencies
182
+ - `make test` : Run the test suite
183
+ - `make format` : Format code with black and isort
184
+ - `make lint` : Run all code quality checks (format, lint, type)
185
+ - `make build` : Build the package
186
+ - `make clean` : Remove build artifacts and cache files
187
+ - `make install-dev` : Install package with development dependencies
273
188
274
- ... (character by character)
189
+ For more details on available commands, run `make help`.
275
190
276
- data: [DONE]
277
- ` ` `
191
+ # # Contributing
278
192
193
+ Contributions are welcome! Please feel free to submit a Pull Request.
194
+ =======
279
195
# # Development
280
196
281
197
# ## Running Tests
@@ -301,8 +217,6 @@ ruff check .
301
217
302
218
# # Error Handling
303
219
304
- The server includes comprehensive error handling :
305
-
306
220
- Invalid requests return 400 status codes with descriptive messages
307
221
- Server errors return 500 status codes with error details
308
222
- All errors are logged using JSON format
@@ -319,6 +233,3 @@ The server uses JSON-formatted logging for:
319
233
320
234
Contributions are welcome! Please feel free to submit a Pull Request.
321
235
322
- # # License
323
-
324
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
0 commit comments