Skip to main content

LLM Mocks

Welcome to the llm-mocks Library! This library is designed to provide mock responses for Large Language Models (LLMs) from popular providers. Whether you are developing, testing, or integrating LLM-based solutions, this library offers a reliable and efficient way to simulate LLM responses without needing direct access to the actual services.

Key Features

  • Mock Responses: Predefined responses for various queries to simulate interactions with LLMs from providers like Anthropic and OpenAI.

  • Seamless Integration: Easy to integrate with your existing development and testing workflows such as Pytest.

  • Extensibility: Ability to customize mock responses to better match your specific use cases.

  • Performance: no network request, ensuring smooth development and testing processes.

Getting Started

To get started with LLM Library, follow the installation instructions and explore our examples to see how you can simulate LLM interactions in your projects. We provide detailed guides to help you quickly integrate the library and start benefiting from its features.

Installation

You can install the LLM Library using pip:

pip install llm-mocks

For more information on installation and setup, please refer to our Installation Guide.

Supported providers

  • OpenAI (Chat CompletionS, Images Regenerations, Embedding)
  • Anthropic (Messages)
  • Cohere (Chat, Embed, Rerank)
  • Groq specs
  • Cohere specs
  • Azure specs
  • AWS Bedrock specs
  • Gemini specs
  • VertexAI specs

Usage

The library will try to return mock response if the providers and apis are supported; otherwise it will fallback to vcrpy implementation of network mocking.

With Pytest Recording

Pytest recording already implement vcrpy. Simply initialise LLMMock to mock response.

from llm_mocks import LLMMock

...

LLMMock()

Normal mock

Follow vcrpy usage documentation for setting up vcr. Then initialise LLMMock class for reponse mocking.

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)

Contributing

We welcome contributions from the community! If you have ideas for new features, improvements, or bug fixes, please check out our Contributing Guide to get started.

Support

If you encounter any issues or have questions, please visit our Support Page or open an issue on our GitHub repository.

Thank you for using LLM Library! We hope it makes your development and testing processes smoother and more efficient.

Release files for llm-mocks 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-mocks 0.1.0
File Size Uploaded
llm_mocks-0.1.0.tar.gz 49.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-mocks 0.1.0
File Interpreter ABI Platform
llm_mocks-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 92.8 kB

Release files / llm_mocks-0.1.0.tar.gz

Download URL llm_mocks-0.1.0.tar.gz
Size 49.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6f6a05914a5a500caaead2ea5997716c1616e82d3229ff134edb52debe675b0f
BLAKE2b-256 checksum
How to use checksums
dbf0d7486bac903a69660f0b3e1e01cc3810840864538a7c4161adfb8ff490bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.6 Darwin/22.6.0

Release files / llm_mocks-0.1.0-py3-none-any.whl

Download URL llm_mocks-0.1.0-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04ba56bdc0568c05e2ec1645bfc2569acd24f1fbe3b5a7efee3254cf2cdfe2c1
BLAKE2b-256 checksum
How to use checksums
7f922f1d8191eb73aeda52e6848dce825af1ed2bb3ac90397577470861367e2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.6 Darwin/22.6.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page