2023-05-25 20:42:44 +00:00
|
|
|
"""Test C Transformers wrapper."""
|
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.llms import CTransformers
|
2023-05-25 20:42:44 +00:00
|
|
|
from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler
|
|
|
|
|
|
|
|
|
|
|
|
def test_ctransformers_call() -> None:
|
|
|
|
"""Test valid call to C Transformers."""
|
|
|
|
config = {"max_new_tokens": 5}
|
|
|
|
callback_handler = FakeCallbackHandler()
|
|
|
|
|
|
|
|
llm = CTransformers(
|
|
|
|
model="marella/gpt-2-ggml",
|
|
|
|
config=config,
|
|
|
|
callbacks=[callback_handler],
|
|
|
|
)
|
|
|
|
|
|
|
|
output = llm("Say foo:")
|
|
|
|
assert isinstance(output, str)
|
|
|
|
assert len(output) > 1
|
|
|
|
assert 0 < callback_handler.llm_streams <= config["max_new_tokens"]
|
2023-07-10 08:23:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_ctransformers_async_inference() -> None:
|
|
|
|
config = {"max_new_tokens": 5}
|
|
|
|
callback_handler = FakeCallbackHandler()
|
|
|
|
|
|
|
|
llm = CTransformers(
|
|
|
|
model="marella/gpt-2-ggml",
|
|
|
|
config=config,
|
|
|
|
callbacks=[callback_handler],
|
|
|
|
)
|
|
|
|
|
|
|
|
output = await llm._acall(prompt="Say foo:")
|
|
|
|
assert isinstance(output, str)
|
|
|
|
assert len(output) > 1
|
|
|
|
assert 0 < callback_handler.llm_streams <= config["max_new_tokens"]
|