Skip to main content

Record and replay LLM interactions for langchain

Project description

VCR langchain

Adapts VCR.py for use with langchain so that you can record and replay all your expensive LLM interactions for tests.

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
  • you no longer need to have the real OpenAI API key defined

For more examples, see the usages test file.

Why not just use VCR.py directly?

This offers higher-level, more human-readable recordings for inspection. Additionally, I plan to support recording of utilities as well, which includes non-network requests such as command executions inside Bash or the Python REPL.

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.

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.3.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

vcr_langchain-0.0.3-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

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