assert-llm-tools 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.1
2
+ Name: assert_llm_tools
3
+ Version: 0.0.3
4
+ Summary: A library for generating test assertions using Large Language Models
5
+ Author-email: Charlie Douglas <cdouglas@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yourusername/assert-llm
8
+ Project-URL: Bug Tracker, https://github.com/yourusername/assert-llm/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Testing
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: anthropic>=0.3.0
19
+ Requires-Dist: openai>=1.0.0
20
+ Requires-Dist: python-dotenv>=0.19.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0; extra == "dev"
23
+ Requires-Dist: black>=23.0.0; extra == "dev"
24
+ Requires-Dist: isort>=5.0.0; extra == "dev"
25
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
26
+ Requires-Dist: build>=0.10.0; extra == "dev"
27
+ Requires-Dist: twine>=4.0.0; extra == "dev"
28
+
29
+ # ASSERT TOOLS LLM
30
+
31
+ This repository contains tools for evaluating the quality of summaries generated by LLMs.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install assert-tools-llm
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ # test_assert.py
43
+ from assert_tools_llm.core import evaluate_summary
44
+
45
+ # Example text from an article
46
+ full_text = """
47
+ Artificial intelligence is rapidly transforming the world economy. Companies
48
+ are investing billions in AI research and development, leading to breakthroughs
49
+ in automation, data analysis, and decision-making processes. While this
50
+ technology offers immense benefits, it also raises concerns about job
51
+ displacement and ethical considerations.
52
+ """
53
+
54
+ # Example summary
55
+ summary = """
56
+ AI is transforming the economy through major investments, bringing advances in
57
+ automation and analytics while raising job and ethical concerns.
58
+ """
59
+
60
+ # Get evaluation metrics
61
+ metrics = evaluate_summary(full_text, summary)
62
+
63
+ # Print results
64
+ print("\nOriginal Text:")
65
+ print(full_text)
66
+ print("\nSummary:")
67
+ print(summary)
68
+ print("\nEvaluation Metrics:")
69
+ for metric, score in metrics.items():
70
+ print(f"{metric}: {score:.4f}")
71
+
72
+ ```
73
+
74
+ ## LICENSE
75
+
76
+ MIT License
77
+
78
+ Copyright (c) 2024
79
+
80
+ Permission is hereby granted, free of charge, to any person obtaining a copy
81
+ of this software and associated documentation files (the "Software"), to deal
82
+ in the Software without restriction, including without limitation the rights
83
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
84
+ copies of the Software, and to permit persons to whom the Software is
85
+ furnished to do so, subject to the following conditions:
86
+
87
+ The above copyright notice and this permission notice shall be included in all
88
+ copies or substantial portions of the Software.
89
+
90
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
93
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
95
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
96
+ SOFTWARE.
97
+
98
+ ## Acknowledgements
99
+
100
+ - [ROUGE](https://github.com/google-research/google-research/tree/master/rouge)
101
+ - [NLTK](https://www.nltk.org/)
@@ -0,0 +1,73 @@
1
+ # ASSERT TOOLS LLM
2
+
3
+ This repository contains tools for evaluating the quality of summaries generated by LLMs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install assert-tools-llm
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ # test_assert.py
15
+ from assert_tools_llm.core import evaluate_summary
16
+
17
+ # Example text from an article
18
+ full_text = """
19
+ Artificial intelligence is rapidly transforming the world economy. Companies
20
+ are investing billions in AI research and development, leading to breakthroughs
21
+ in automation, data analysis, and decision-making processes. While this
22
+ technology offers immense benefits, it also raises concerns about job
23
+ displacement and ethical considerations.
24
+ """
25
+
26
+ # Example summary
27
+ summary = """
28
+ AI is transforming the economy through major investments, bringing advances in
29
+ automation and analytics while raising job and ethical concerns.
30
+ """
31
+
32
+ # Get evaluation metrics
33
+ metrics = evaluate_summary(full_text, summary)
34
+
35
+ # Print results
36
+ print("\nOriginal Text:")
37
+ print(full_text)
38
+ print("\nSummary:")
39
+ print(summary)
40
+ print("\nEvaluation Metrics:")
41
+ for metric, score in metrics.items():
42
+ print(f"{metric}: {score:.4f}")
43
+
44
+ ```
45
+
46
+ ## LICENSE
47
+
48
+ MIT License
49
+
50
+ Copyright (c) 2024
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a copy
53
+ of this software and associated documentation files (the "Software"), to deal
54
+ in the Software without restriction, including without limitation the rights
55
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56
+ copies of the Software, and to permit persons to whom the Software is
57
+ furnished to do so, subject to the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be included in all
60
+ copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68
+ SOFTWARE.
69
+
70
+ ## Acknowledgements
71
+
72
+ - [ROUGE](https://github.com/google-research/google-research/tree/master/rouge)
73
+ - [NLTK](https://www.nltk.org/)
@@ -0,0 +1,37 @@
1
+ import nltk
2
+ import os
3
+ from pathlib import Path
4
+
5
+
6
+ def initialize_nltk():
7
+ """
8
+ Initialize required NLTK data, downloading if necessary.
9
+ Creates a data directory in the user's home directory if needed.
10
+ """
11
+ try:
12
+ # Set NLTK data path to user's home directory
13
+ nltk_data_dir = str(Path.home() / ".assert_tools" / "nltk_data")
14
+ os.makedirs(nltk_data_dir, exist_ok=True)
15
+ nltk.data.path.append(nltk_data_dir)
16
+
17
+ # List of required NLTK resources
18
+ required_resources = ["punkt", "punkt_tab"]
19
+
20
+ # Download all required resources
21
+ for resource in required_resources:
22
+ try:
23
+ nltk.data.find(f"tokenizers/{resource}")
24
+ except LookupError:
25
+ print(f"Downloading {resource}...")
26
+ nltk.download(resource, download_dir=nltk_data_dir, quiet=False)
27
+
28
+ return True
29
+ except Exception as e:
30
+ print(f"Warning: Failed to initialize NLTK data: {str(e)}")
31
+ return False
32
+
33
+
34
+ # Initialize when the package is imported
35
+ print("Initializing NLTK resources...")
36
+ initialize_nltk()
37
+ print("NLTK initialization complete.")
@@ -0,0 +1,26 @@
1
+ from typing import Dict, Union, List
2
+ from .metrics.rouge import calculate_rouge
3
+ from .metrics.bleu import calculate_bleu
4
+
5
+
6
+ def evaluate_summary(full_text: str, summary: str) -> Dict[str, float]:
7
+ """
8
+ Evaluate a summary against the original text using ROUGE and BLEU scores.
9
+
10
+ Args:
11
+ full_text (str): The original full text
12
+ summary (str): The summary to evaluate
13
+
14
+ Returns:
15
+ Dict[str, float]: Dictionary containing various evaluation metrics
16
+ """
17
+ # Calculate ROUGE scores
18
+ rouge_scores = calculate_rouge(full_text, summary)
19
+
20
+ # Calculate BLEU score
21
+ bleu_score = calculate_bleu(full_text, summary)
22
+
23
+ # Combine all metrics
24
+ metrics = {**rouge_scores, "bleu": bleu_score}
25
+
26
+ return metrics
@@ -0,0 +1,16 @@
1
+ from nltk.translate.bleu_score import sentence_bleu
2
+ from nltk.tokenize import word_tokenize
3
+ from .. import initialize_nltk
4
+
5
+
6
+ def calculate_bleu(reference: str, candidate: str) -> float:
7
+ """
8
+ Calculate BLEU score for a candidate summary against a reference text.
9
+ """
10
+ # Ensure NLTK is initialized before calculating scores
11
+ initialize_nltk()
12
+
13
+ reference_tokens = [word_tokenize(reference)]
14
+ candidate_tokens = word_tokenize(candidate)
15
+
16
+ return sentence_bleu(reference_tokens, candidate_tokens)
@@ -0,0 +1,15 @@
1
+ from rouge_score import rouge_scorer
2
+
3
+
4
+ def calculate_rouge(reference: str, candidate: str) -> dict[str, float]:
5
+ """
6
+ Calculate ROUGE scores for a candidate summary against a reference text.
7
+ """
8
+ scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeL"], use_stemmer=True)
9
+ scores = scorer.score(reference, candidate)
10
+
11
+ return {
12
+ "rouge1": scores["rouge1"].fmeasure,
13
+ "rouge2": scores["rouge2"].fmeasure,
14
+ "rougeL": scores["rougeL"].fmeasure,
15
+ }
@@ -0,0 +1,9 @@
1
+ def preprocess_text(text: str) -> str:
2
+ """
3
+ Preprocess text by cleaning and normalizing it.
4
+ """
5
+ # Remove extra whitespace
6
+ text = " ".join(text.split())
7
+ # Convert to lowercase
8
+ text = text.lower()
9
+ return text
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.1
2
+ Name: assert_llm_tools
3
+ Version: 0.0.3
4
+ Summary: A library for generating test assertions using Large Language Models
5
+ Author-email: Charlie Douglas <cdouglas@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yourusername/assert-llm
8
+ Project-URL: Bug Tracker, https://github.com/yourusername/assert-llm/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Testing
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: anthropic>=0.3.0
19
+ Requires-Dist: openai>=1.0.0
20
+ Requires-Dist: python-dotenv>=0.19.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0; extra == "dev"
23
+ Requires-Dist: black>=23.0.0; extra == "dev"
24
+ Requires-Dist: isort>=5.0.0; extra == "dev"
25
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
26
+ Requires-Dist: build>=0.10.0; extra == "dev"
27
+ Requires-Dist: twine>=4.0.0; extra == "dev"
28
+
29
+ # ASSERT TOOLS LLM
30
+
31
+ This repository contains tools for evaluating the quality of summaries generated by LLMs.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install assert-tools-llm
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ # test_assert.py
43
+ from assert_tools_llm.core import evaluate_summary
44
+
45
+ # Example text from an article
46
+ full_text = """
47
+ Artificial intelligence is rapidly transforming the world economy. Companies
48
+ are investing billions in AI research and development, leading to breakthroughs
49
+ in automation, data analysis, and decision-making processes. While this
50
+ technology offers immense benefits, it also raises concerns about job
51
+ displacement and ethical considerations.
52
+ """
53
+
54
+ # Example summary
55
+ summary = """
56
+ AI is transforming the economy through major investments, bringing advances in
57
+ automation and analytics while raising job and ethical concerns.
58
+ """
59
+
60
+ # Get evaluation metrics
61
+ metrics = evaluate_summary(full_text, summary)
62
+
63
+ # Print results
64
+ print("\nOriginal Text:")
65
+ print(full_text)
66
+ print("\nSummary:")
67
+ print(summary)
68
+ print("\nEvaluation Metrics:")
69
+ for metric, score in metrics.items():
70
+ print(f"{metric}: {score:.4f}")
71
+
72
+ ```
73
+
74
+ ## LICENSE
75
+
76
+ MIT License
77
+
78
+ Copyright (c) 2024
79
+
80
+ Permission is hereby granted, free of charge, to any person obtaining a copy
81
+ of this software and associated documentation files (the "Software"), to deal
82
+ in the Software without restriction, including without limitation the rights
83
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
84
+ copies of the Software, and to permit persons to whom the Software is
85
+ furnished to do so, subject to the following conditions:
86
+
87
+ The above copyright notice and this permission notice shall be included in all
88
+ copies or substantial portions of the Software.
89
+
90
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
93
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
95
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
96
+ SOFTWARE.
97
+
98
+ ## Acknowledgements
99
+
100
+ - [ROUGE](https://github.com/google-research/google-research/tree/master/rouge)
101
+ - [NLTK](https://www.nltk.org/)
@@ -0,0 +1,12 @@
1
+ README.md
2
+ pyproject.toml
3
+ assert_llm_tools/__init__.py
4
+ assert_llm_tools/core.py
5
+ assert_llm_tools/utils.py
6
+ assert_llm_tools.egg-info/PKG-INFO
7
+ assert_llm_tools.egg-info/SOURCES.txt
8
+ assert_llm_tools.egg-info/dependency_links.txt
9
+ assert_llm_tools.egg-info/requires.txt
10
+ assert_llm_tools.egg-info/top_level.txt
11
+ assert_llm_tools/metrics/bleu.py
12
+ assert_llm_tools/metrics/rouge.py
@@ -0,0 +1,11 @@
1
+ anthropic>=0.3.0
2
+ openai>=1.0.0
3
+ python-dotenv>=0.19.0
4
+
5
+ [dev]
6
+ pytest>=7.0
7
+ black>=23.0.0
8
+ isort>=5.0.0
9
+ flake8>=4.0.0
10
+ build>=0.10.0
11
+ twine>=4.0.0
@@ -0,0 +1 @@
1
+ assert_llm_tools
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "assert_llm_tools"
7
+ version = "0.0.3"
8
+ description = "A library for generating test assertions using Large Language Models"
9
+ authors = [
10
+ {name = "Charlie Douglas", email = "cdouglas@gmail.com"},
11
+ ]
12
+ readme = "README.md"
13
+ license = {text = "MIT"}
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.8",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Development Status :: 3 - Alpha",
20
+ "Intended Audience :: Developers",
21
+ "Topic :: Software Development :: Testing",
22
+ ]
23
+ dependencies = [
24
+ "anthropic>=0.3.0",
25
+ "openai>=1.0.0",
26
+ "python-dotenv>=0.19.0",
27
+ ]
28
+ requires-python = ">=3.8"
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "pytest>=7.0",
33
+ "black>=23.0.0",
34
+ "isort>=5.0.0",
35
+ "flake8>=4.0.0",
36
+ "build>=0.10.0",
37
+ "twine>=4.0.0",
38
+ ]
39
+
40
+ [project.urls]
41
+ "Homepage" = "https://github.com/yourusername/assert-llm"
42
+ "Bug Tracker" = "https://github.com/yourusername/assert-llm/issues"
43
+
44
+ [tool.setuptools]
45
+ packages = [
46
+ "assert_llm_tools",
47
+ "assert_llm_tools.metrics"
48
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+