|
| 1 | +# Assert LLM |
| 2 | + |
| 3 | +A tool for lazy people that doesn't want to spend time on writing tests. |
| 4 | + |
| 5 | +(Just a project that I wrote for fun) |
| 6 | + |
| 7 | +## How to run |
| 8 | + |
| 9 | +Install the required packages with `pip install .` |
| 10 | + |
| 11 | +Load any model on [LM Studio](https://lmstudio.ai) and start the "Local Inference Server". |
| 12 | +Assuming it's configured to expose the port `1234` on localhost, you can use this tool |
| 13 | +on your unit tests like this: |
| 14 | + |
| 15 | +``` |
| 16 | +>>> from src.main import llm_assert |
| 17 | +>>> from src.engines.lmstudio import LMStudioEngine |
| 18 | +>>> engine = LMStudioEngine("http://localhost:1234/v1") |
| 19 | +>>> llm_assert(engine, "5", "this is a number") |
| 20 | +>>> llm_assert(engine, "5", "this is not a number") |
| 21 | +Traceback (most recent call last): |
| 22 | + File "<stdin>", line 1, in <module> |
| 23 | + File "/Users/jdiazsua/Documents/Projects/PoCs/assert-llm/src/main.py", line 49, in llm_assert |
| 24 | + assert answer == "True", f"'{sut}' doesn't match the prompt '{prompt}'" |
| 25 | + ^^^^^^^^^^^^^^^^ |
| 26 | +AssertionError: '5' doesn't match the prompt 'this is not a number' |
| 27 | +``` |
| 28 | + |
| 29 | +This looks like an overkill, but it can be useful for lazy checks like: |
| 30 | + |
| 31 | +``` |
| 32 | +>>> input_text = """ |
| 33 | +Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| 34 | +123 Elm Street, Springfield, IL 62704. |
| 35 | +Vivamus aliquet, augue id semper varius, ex tellus luctus justo, nec viverra metus lectus nec magna. |
| 36 | +""" |
| 37 | +>>> llm_assert(engine, input_text, "it contains an address") |
| 38 | +>>> llm_assert(engine, input_text, "it contains a telephone number") |
| 39 | +Traceback (most recent call last): |
| 40 | + File "<stdin>", line 1, in <module> |
| 41 | + File "/Users/jdiazsua/Documents/Projects/PoCs/assert-llm/src/main.py", line 49, in llm_assert |
| 42 | + assert answer == "True", f"'{sut}' doesn't match the prompt '{prompt}'" |
| 43 | + ^^^^^^^^^^^^^^^^ |
| 44 | +AssertionError: ' |
| 45 | +Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| 46 | +123 Elm Street, Springfield, IL 62704. |
| 47 | +Vivamus aliquet, augue id semper varius, ex tellus luctus justo, nec viverra metus lectus nec magna. |
| 48 | +' doesn't match the prompt 'it contains a telephone number' |
| 49 | +``` |
| 50 | + |
| 51 | +## Contributing |
| 52 | + |
| 53 | +Feel free to add new engines to the [engines](src/engines/) package. The only requirement is that |
| 54 | +they must implement the `Engine` interface, as it will be used by the `llm_assert` function. |
| 55 | + |
| 56 | +You can also contribute by adding new functions with different `system_message` and `prompt` |
| 57 | +or calling different APIs. |
0 commit comments