-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_usage.py
31 lines (23 loc) · 1022 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_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(model_name="text-ada-001")
result = llm.invoke("Tell me a silly joke")
with vcr.use_cassette(cassette_path, record_mode=vcr.mode.NONE):
new_llm = OpenAI(model_name="text-ada-001")
assert new_llm.invoke("Tell me a silly joke") == result
@vcr.use_cassette()
def test_use_as_test_decorator() -> None:
llm = OpenAI(model_name="babbage-002")
llm.invoke("Tell me a surreal joke")
@vcr.use_cassette("tests/custom.yaml")
def test_use_custom_file() -> None:
llm = OpenAI(model_name="babbage-002")
llm.invoke("Tell me a real joke")