forked from amosjyng/vcr-langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_usage.py
31 lines (23 loc) · 901 Bytes
/
test_usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pytest
from langchain.llms.openai import OpenAI
import vcr_langchain as vcr
from tests import TemporaryCassettePath
@pytest.mark.network
def test_use_as_with_context() -> None:
"""This test doubles as a test for successful serialization"""
cassette_path = "tests/context.yaml"
with TemporaryCassettePath(cassette_path):
with vcr.use_cassette(cassette_path, record_mode=vcr.mode.ONCE):
llm = OpenAI()
result = llm("Tell me a silly joke")
with vcr.use_cassette(cassette_path, record_mode=vcr.mode.NONE):
new_llm = OpenAI()
assert new_llm("Tell me a silly joke") == result
@vcr.use_cassette()
def test_use_as_test_decorator() -> None:
llm = OpenAI()
llm("Tell me a surreal joke")
@vcr.use_cassette("tests/custom.yaml")
def test_use_custom_file() -> None:
llm = OpenAI()
llm("Tell me a real joke")