-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mlverse/updates
Adds tests
- Loading branch information
Showing
14 changed files
with
256 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,4 @@ rsconnect/ | |
docs/ | ||
|
||
python/mall/src/ | ||
python/assets/style.css |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"Unit tests for mall" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
import mall | ||
import polars as pl | ||
import pyarrow | ||
import shutil | ||
import os | ||
|
||
if os._exists("_test_cache"): | ||
shutil.rmtree("_test_cache", ignore_errors=True) | ||
|
||
|
||
def test_classify(): | ||
df = pl.DataFrame(dict(x=["one", "two", "three"])) | ||
df.llm.use("test", "echo", _cache="_test_cache") | ||
x = df.llm.classify("x", ["one", "two"]) | ||
assert ( | ||
x.select("classify").to_pandas().to_string() | ||
== " classify\n0 one\n1 two\n2 None" | ||
) | ||
|
||
|
||
def test_classify_dict(): | ||
df = pl.DataFrame(dict(x=[1, 2, 3])) | ||
df.llm.use("test", "echo", _cache="_test_cache") | ||
x = df.llm.classify("x", {"one": 1, "two": 2}) | ||
assert ( | ||
x.select("classify").to_pandas().to_string() | ||
== " classify\n0 1.0\n1 2.0\n2 NaN" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
import mall | ||
import polars as pl | ||
import pyarrow | ||
|
||
import shutil | ||
import os | ||
if os._exists("_test_cache"): | ||
shutil.rmtree("_test_cache", ignore_errors=True) | ||
|
||
def test_extract_list(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache = "_test_cache") | ||
x = df.llm.extract("x", ["a", "b"]) | ||
assert ( | ||
x["extract"][0] | ||
== "You are a helpful text extraction engine. Extract the a, b being referred to on the text. I expect 2 items exactly. No capitalization. No explanations. Return the response exclusively in a pipe separated list, and no headers. The answer is based on the following text:\n{}" | ||
) | ||
|
||
|
||
def test_extract_dict(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache = "_test_cache") | ||
x = df.llm.extract("x", dict(a="one", b="two")) | ||
assert ( | ||
x["extract"][0] | ||
== "You are a helpful text extraction engine. Extract the one, two being referred to on the text. I expect 2 items exactly. No capitalization. No explanations. Return the response exclusively in a pipe separated list, and no headers. The answer is based on the following text:\n{}" | ||
) | ||
|
||
|
||
def test_extract_one(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache = "_test_cache") | ||
x = df.llm.extract("x", labels="a") | ||
assert ( | ||
x["extract"][0] | ||
== "You are a helpful text extraction engine. Extract the a being referred to on the text. I expect 1 item exactly. No capitalization. No explanations. The answer is based on the following text:\n{}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
import mall | ||
import polars as pl | ||
import pyarrow | ||
|
||
import shutil | ||
import os | ||
|
||
if os._exists("_test_cache"): | ||
shutil.rmtree("_test_cache", ignore_errors=True) | ||
|
||
|
||
def test_sentiment_simple(): | ||
data = mall.MallData | ||
reviews = data.reviews | ||
reviews.llm.use("test", "echo", _cache="_test_cache") | ||
x = reviews.llm.sentiment("review") | ||
assert ( | ||
x.select("sentiment").to_pandas().to_string() | ||
== " sentiment\n0 None\n1 None\n2 None" | ||
) | ||
|
||
|
||
def sim_sentiment(): | ||
df = pl.DataFrame(dict(x=["positive", "negative", "neutral", "not-real"])) | ||
df.llm.use("test", "echo", _cache="_test_cache") | ||
return df | ||
|
||
|
||
def test_sentiment_valid(): | ||
x = sim_sentiment() | ||
x = x.llm.sentiment("x") | ||
assert ( | ||
x.select("sentiment").to_pandas().to_string() | ||
== " sentiment\n0 positive\n1 negative\n2 neutral\n3 None" | ||
) | ||
|
||
|
||
def test_sentiment_valid2(): | ||
x = sim_sentiment() | ||
x = x.llm.sentiment("x", ["positive", "negative"]) | ||
assert ( | ||
x.select("sentiment").to_pandas().to_string() | ||
== " sentiment\n0 positive\n1 negative\n2 None\n3 None" | ||
) | ||
|
||
|
||
def test_sentiment_prompt(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache="_test_cache") | ||
x = df.llm.sentiment("x") | ||
assert ( | ||
x["sentiment"][0] | ||
== "You are a helpful sentiment engine. Return only one of the following answers: positive, negative, neutral . No capitalization. No explanations. The answer is based on the following text:\n{}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
import mall | ||
import polars as pl | ||
import pyarrow | ||
import shutil | ||
import os | ||
|
||
if os._exists("_test_cache"): | ||
shutil.rmtree("_test_cache", ignore_errors=True) | ||
|
||
|
||
def test_summarize_prompt(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache="_test_cache") | ||
x = df.llm.summarize("x") | ||
assert ( | ||
x["summary"][0] | ||
== "You are a helpful summarization engine. Your answer will contain no no capitalization and no explanations. Return no more than 10 words. The answer is the summary of the following text:\n{}" | ||
) | ||
|
||
|
||
def test_summarize_max(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache="_test_cache") | ||
x = df.llm.summarize("x", max_words=5) | ||
assert ( | ||
x["summary"][0] | ||
== "You are a helpful summarization engine. Your answer will contain no no capitalization and no explanations. Return no more than 5 words. The answer is the summary of the following text:\n{}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
import mall | ||
import polars as pl | ||
import pyarrow | ||
|
||
import shutil | ||
import os | ||
|
||
if os._exists("_test_cache"): | ||
shutil.rmtree("_test_cache", ignore_errors=True) | ||
|
||
|
||
def test_translate_prompt(): | ||
df = pl.DataFrame(dict(x="x")) | ||
df.llm.use("test", "content", _cache="_test_cache") | ||
x = df.llm.translate("x", language="spanish") | ||
assert ( | ||
x["translation"][0] | ||
== "You are a helpful translation engine. You will return only the translation text, no explanations. The target language to translate to is: spanish. The answer is the translation of the following text:\n{}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import mall | ||
import polars | ||
|
||
|
||
def test_use_init(): | ||
data = mall.MallData | ||
reviews = data.reviews | ||
x = reviews.llm.use() | ||
x == dict(backend="ollama", model="llama3.2", _cache="_mall_cache") | ||
|
||
|
||
def test_use_mod1(): | ||
data = mall.MallData | ||
reviews = data.reviews | ||
x = reviews.llm.use(options=dict(seed=100)) | ||
x == dict( | ||
backend="ollama", model="llama3.2", _cache="_mall_cache", options=dict(seed=100) | ||
) | ||
|
||
|
||
def test_use_mod2(): | ||
data = mall.MallData | ||
reviews = data.reviews | ||
x = reviews.llm.use(options=dict(seed=99)) | ||
x == dict( | ||
backend="ollama", model="llama3.2", _cache="_mall_cache", options=dict(seed=99) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
import mall | ||
import polars as pl | ||
import pyarrow | ||
import shutil | ||
import os | ||
|
||
if os._exists("_test_cache"): | ||
shutil.rmtree("_test_cache", ignore_errors=True) | ||
|
||
|
||
def test_verify(): | ||
df = pl.DataFrame(dict(x=[1, 1, 0, 2])) | ||
df.llm.use("test", "echo", _cache="_test_cache") | ||
x = df.llm.verify("x", "this is my question") | ||
assert ( | ||
x.select("verify").to_pandas().to_string() | ||
== " verify\n0 1.0\n1 1.0\n2 0.0\n3 NaN" | ||
) | ||
|
||
|
||
def test_verify_yn(): | ||
df = pl.DataFrame(dict(x=["y", "n", "y", "x"])) | ||
df.llm.use("test", "echo", _cache="_test_cache") | ||
x = df.llm.verify("x", "this is my question", ["y", "n"]) | ||
assert ( | ||
x.select("verify").to_pandas().to_string() | ||
== " verify\n0 y\n1 n\n2 y\n3 None" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters