Customisation
By default, the mock client always returns the same response. There are a few ways to customise response for testing and development:
Randomise response
You can pass faker
instance to LLMMock
for randomisation. If you want to control the level of randomness, simply add seed configuration
as Faker(seed=...)
.
from llm_mocks import LLMMock
from faker import Faker
faker = Faker()
LLMMock(faker=faker)
Provide your own response
If you would like the to return specific response, you can override response generate from mock client using reponse_overwrite
hook:
from llm_mocks import LLMMock
def response_overwrite(request, response):
...
LLMMock(reponse_overwrite=response_overwrite)
...
Use vcr for recording and replay
This library monkey patch vcrpy
to provide mock request before vcr cassette
read local file or make network request. To resume vcr
functionality, simply disable mock service:
LLMMock(mock_disabled)