Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1import pytest2from utils import *3 4server = ServerPreset.jina_reranker_tiny()5 6 7@pytest.fixture(autouse=True)8def create_server():9 global server10 server = ServerPreset.jina_reranker_tiny()11 12 13TEST_DOCUMENTS = [14 "A machine is a physical system that uses power to apply forces and control movement to perform an action. The term is commonly applied to artificial devices, such as those employing engines or motors, but also to natural biological macromolecules, such as molecular machines.",15 "Learning is the process of acquiring new understanding, knowledge, behaviors, skills, values, attitudes, and preferences. The ability to learn is possessed by humans, non-human animals, and some machines; there is also evidence for some kind of learning in certain plants.",16 "Machine learning is a field of study in artificial intelligence concerned with the development and study of statistical algorithms that can learn from data and generalize to unseen data, and thus perform tasks without explicit instructions.",17 "Paris, capitale de la France, est une grande ville européenne et un centre mondial de l'art, de la mode, de la gastronomie et de la culture. Son paysage urbain du XIXe siècle est traversé par de larges boulevards et la Seine."18]19 20 21def test_rerank():22 global server23 server.start()24 res = server.make_request("POST", "/rerank", data={25 "query": "Machine learning is",26 "documents": TEST_DOCUMENTS,27 })28 assert res.status_code == 20029 assert len(res.body["results"]) == 430 31 most_relevant = res.body["results"][0]32 least_relevant = res.body["results"][0]33 for doc in res.body["results"]:34 if doc["relevance_score"] > most_relevant["relevance_score"]:35 most_relevant = doc36 if doc["relevance_score"] < least_relevant["relevance_score"]:37 least_relevant = doc38 39 assert most_relevant["relevance_score"] > least_relevant["relevance_score"]40 assert most_relevant["index"] == 241 assert least_relevant["index"] == 342 43 44def test_rerank_tei_format():45 global server46 server.start()47 res = server.make_request("POST", "/rerank", data={48 "query": "Machine learning is",49 "texts": TEST_DOCUMENTS,50 })51 assert res.status_code == 20052 assert len(res.body) == 453 54 most_relevant = res.body[0]55 least_relevant = res.body[0]56 for doc in res.body:57 if doc["score"] > most_relevant["score"]:58 most_relevant = doc59 if doc["score"] < least_relevant["score"]:60 least_relevant = doc61 62 assert most_relevant["score"] > least_relevant["score"]63 assert most_relevant["index"] == 264 assert least_relevant["index"] == 365 66 67@pytest.mark.parametrize("documents", [68 [],69 None,70 123,71 [1, 2, 3],72])73def test_invalid_rerank_req(documents):74 global server75 server.start()76 res = server.make_request("POST", "/rerank", data={77 "query": "Machine learning is",78 "documents": documents,79 })80 assert res.status_code == 40081 assert "error" in res.body82 83 84@pytest.mark.parametrize(85 "query,doc1,doc2,n_tokens",86 [87 ("Machine learning is", "A machine", "Learning is", 19),88 ("Which city?", "Machine learning is ", "Paris, capitale de la", 26),89 ]90)91def test_rerank_usage(query, doc1, doc2, n_tokens):92 global server93 server.start()94 95 res = server.make_request("POST", "/rerank", data={96 "query": query,97 "documents": [98 doc1,99 doc2,100 ]101 })102 assert res.status_code == 200103 assert res.body['usage']['prompt_tokens'] == res.body['usage']['total_tokens']104 assert res.body['usage']['prompt_tokens'] == n_tokens105 106 107@pytest.mark.parametrize("top_n,expected_len", [108 (None, len(TEST_DOCUMENTS)), # no top_n parameter109 (2, 2),110 (4, 4),111 (99, len(TEST_DOCUMENTS)), # higher than available docs112])113def test_rerank_top_n(top_n, expected_len):114 global server115 server.start()116 data = {117 "query": "Machine learning is",118 "documents": TEST_DOCUMENTS,119 }120 if top_n is not None:121 data["top_n"] = top_n122 123 res = server.make_request("POST", "/rerank", data=data)124 assert res.status_code == 200125 assert len(res.body["results"]) == expected_len126 127 128@pytest.mark.parametrize("top_n,expected_len", [129 (None, len(TEST_DOCUMENTS)), # no top_n parameter130 (2, 2),131 (4, 4),132 (99, len(TEST_DOCUMENTS)), # higher than available docs133])134def test_rerank_tei_top_n(top_n, expected_len):135 global server136 server.start()137 data = {138 "query": "Machine learning is",139 "texts": TEST_DOCUMENTS,140 }141 if top_n is not None:142 data["top_n"] = top_n143 144 res = server.make_request("POST", "/rerank", data=data)145 assert res.status_code == 200146 assert len(res.body) == expected_len147 