Skip to main content

Record and replay LLM interactions for langchain

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcr_langchain-0.0.31.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

vcr_langchain-0.0.31-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file vcr_langchain-0.0.31.tar.gz.

File metadata

  • Download URL: vcr_langchain-0.0.31.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-91-generic

File hashes

Hashes for vcr_langchain-0.0.31.tar.gz
Algorithm Hash digest
SHA256 fc7131fb66b4e09885fd6d50b37c72542e57aae113b5e303b8ff5d649307b7d2
MD5 9c0fd84b52c45f92b0b1daf6c723b1bf
BLAKE2b-256 aeecf5cfc468a7e8699d9056f7d8408e7464a3f397a99bf0c7949af7228dabcd

See more details on using hashes here.

File details

Details for the file vcr_langchain-0.0.31-py3-none-any.whl.

File metadata

  • Download URL: vcr_langchain-0.0.31-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-91-generic

File hashes

Hashes for vcr_langchain-0.0.31-py3-none-any.whl
Algorithm Hash digest
SHA256 65f4dea747c568181943c31e7c9436bb389ec26d10591e15b8a582ff12c2bdcd
MD5 52d0f5de09e9c7fb6bc26cbf505318ce
BLAKE2b-256 c108f814c49f291f6560bd77717ba8d4717b9df987c54e0219ed97dfd13f173b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page