mirror of https://github.com/HazyResearch/manifest
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
"""Cache test."""
|
|
import json
|
|
|
|
import numpy as np
|
|
|
|
from manifest.caches.serializers import ArraySerializer, NumpyByteSerializer
|
|
|
|
|
|
def test_response_to_key_array() -> None:
|
|
"""Test array serializer initialization."""
|
|
serializer = ArraySerializer()
|
|
arr = np.random.rand(4, 4)
|
|
res = {"response": {"choices": [{"array": arr}]}}
|
|
key = serializer.response_to_key(res)
|
|
key_dct = json.loads(key)
|
|
assert isinstance(key_dct["response"]["choices"][0]["array"], str)
|
|
|
|
res2 = serializer.key_to_response(key)
|
|
assert np.allclose(arr, res2["response"]["choices"][0]["array"])
|
|
|
|
|
|
def test_response_to_key_numpybytes() -> None:
|
|
"""Test array serializer initialization."""
|
|
serializer = NumpyByteSerializer()
|
|
arr = np.random.rand(4, 4)
|
|
res = {"response": {"choices": [{"array": arr}]}}
|
|
key = serializer.response_to_key(res)
|
|
key_dct = json.loads(key)
|
|
assert isinstance(key_dct["response"]["choices"][0]["array"], str)
|
|
|
|
res2 = serializer.key_to_response(key)
|
|
assert np.allclose(arr, res2["response"]["choices"][0]["array"])
|