Skip to main content

VCR LangChain

Patches VCR.py to include non-network tooling for use with LangChain. Refactor with confidence as you record and replay all your LLM logic in a contained environment, free from any and all side effects.

Quickstart

pip install vcr-langchain

Use it with pytest:

import vcr_langchain as vcr
from langchain.llms import OpenAI

@vcr.use_cassette()
def test_use_as_test_decorator():
    llm = OpenAI(model_name="text-ada-001")
    assert llm("Tell me a surreal joke") == "<put the output here>"

The next time you run it:

  • the output is now deterministic
  • it executes a lot faster by replaying from cache
  • no command executions or other side effects actually happen
  • you no longer need to have real API keys defined for test execution in CI environments

For more examples, see the usages test file.

If you're using the Langchain Playwright browser tools, you can also use get_sync_test_browser and get_async_test_browser to automatically get real browsers during recording but fake browsers on replay. This allows you to skip downloading and installing Playwright browsers on your remote CI server, while still being able to re-record sessions in a real browser when developing locally.

Pitfalls

Note that tools, if initialized outside of the vcr_langchain decorator, will not have recording capabilities patched in. This is true even if an agent using those tools is initialized within the decorator.

Documentation

For more information on how VCR works and what other options there are, please see the VCR docs.

For more information on how to use langchain, please see the langchain docs.

Please note that there is a lot of langchain functionality that I haven't gotten around to hijacking for recording. If there's anything you need to record in a cassette, please open a PR or issue.

Projects that use this

Release files for vcr-langchain 0.0.31

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

Source distribution (sdist)

Source distribution for vcr-langchain 0.0.31
File Size Uploaded
vcr_langchain-0.0.31.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vcr-langchain 0.0.31
File Interpreter ABI Platform
vcr_langchain-0.0.31-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / vcr_langchain-0.0.31.tar.gz

Download URL vcr_langchain-0.0.31.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fc7131fb66b4e09885fd6d50b37c72542e57aae113b5e303b8ff5d649307b7d2
BLAKE2b-256 checksum
How to use checksums
aeecf5cfc468a7e8699d9056f7d8408e7464a3f397a99bf0c7949af7228dabcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-91-generic

Release files / vcr_langchain-0.0.31-py3-none-any.whl

Download URL vcr_langchain-0.0.31-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65f4dea747c568181943c31e7c9436bb389ec26d10591e15b8a582ff12c2bdcd
BLAKE2b-256 checksum
How to use checksums
c108f814c49f291f6560bd77717ba8d4717b9df987c54e0219ed97dfd13f173b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-91-generic

Release history Release notifications | RSS feed

This release

0.0.31 This release

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

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