Files
NexQuant/test/oai/test_embedding_and_similarity.py
T
Xu Yang 6b626eb56d New Framework for idea proposal and implementation on RD-Agent (#34)
* Commit init framework

* Co-authored-by: Yuante Li (FESCO Adecco Human Resources) <v-yuanteli@microsoft.com>
Co-authored-by: XianBW <XianBW@users.noreply.github.com>

* add an import

* refine the whole framework

* benchmark related framework

* fix black and isort errors

* move requirements to folder

* fix black again

---------

Co-authored-by: Young <afe.young@gmail.com>
Co-authored-by: xuyang1 <xuyang1@microsoft.com>
2024-06-28 11:45:23 +08:00

26 lines
718 B
Python

import unittest
from rdagent.oai.llm_utils import (
APIBackend,
calculate_embedding_distance_between_str_list,
)
class TestEmbedding(unittest.TestCase):
def test_embedding(self) -> None:
emb = APIBackend().create_embedding("hello")
assert emb is not None
assert isinstance(emb, list)
assert len(emb) > 0
def test_embedding_similarity(self) -> None:
similarity = calculate_embedding_distance_between_str_list(["Hello"], ["Hi"])[0][0]
assert similarity is not None
assert isinstance(similarity, float)
min_similarity_threshold = 0.8
assert similarity >= min_similarity_threshold
if __name__ == "__main__":
unittest.main()