swarmauri_measurement_tokencountestimator 0.6.0.dev154__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,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: swarmauri_measurement_tokencountestimator
3
+ Version: 0.6.0.dev154
4
+ Summary: This repository includes an example of a First Class Swarmauri Example.
5
+ License: Apache-2.0
6
+ Author: Jacob Stewart
7
+ Author-email: jacob@swarmauri.com
8
+ Requires-Python: >=3.10,<3.13
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: swarmauri_base (>=0.6.0.dev154,<0.7.0)
15
+ Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
16
+ Requires-Dist: tiktoken (>=0.8.0,<0.9.0)
17
+ Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Swarmauri Example Community Package
@@ -0,0 +1 @@
1
+ # Swarmauri Example Community Package
@@ -0,0 +1,56 @@
1
+ [tool.poetry]
2
+ name = "swarmauri_measurement_tokencountestimator"
3
+ version = "0.6.0.dev154"
4
+ description = "This repository includes an example of a First Class Swarmauri Example."
5
+ authors = ["Jacob Stewart <jacob@swarmauri.com>"]
6
+ license = "Apache-2.0"
7
+ readme = "README.md"
8
+ repository = "http://github.com/swarmauri/swarmauri-sdk"
9
+ classifiers = [
10
+ "License :: OSI Approved :: Apache Software License",
11
+ "Programming Language :: Python :: 3.10",
12
+ "Programming Language :: Python :: 3.11",
13
+ "Programming Language :: Python :: 3.12"
14
+ ]
15
+
16
+ [tool.poetry.dependencies]
17
+ python = ">=3.10,<3.13"
18
+
19
+ # Swarmauri
20
+ swarmauri_core = {version = "^0.6.0.dev154"}
21
+ swarmauri_base = {version = "^0.6.0.dev154"}
22
+
23
+ # Dependencies
24
+ tiktoken = "^0.8.0"
25
+
26
+ [tool.poetry.group.dev.dependencies]
27
+ flake8 = "^7.0"
28
+ pytest = "^8.0"
29
+ pytest-asyncio = ">=0.24.0"
30
+ pytest-xdist = "^3.6.1"
31
+ pytest-json-report = "^1.5.0"
32
+ python-dotenv = "*"
33
+ requests = "^2.32.3"
34
+
35
+ [build-system]
36
+ requires = ["poetry-core>=1.0.0"]
37
+ build-backend = "poetry.core.masonry.api"
38
+
39
+ [tool.pytest.ini_options]
40
+ norecursedirs = ["combined", "scripts"]
41
+
42
+ markers = [
43
+ "test: standard test",
44
+ "unit: Unit tests",
45
+ "integration: Integration tests",
46
+ "acceptance: Acceptance tests",
47
+ "experimental: Experimental tests"
48
+ ]
49
+ log_cli = true
50
+ log_cli_level = "INFO"
51
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
52
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
53
+ asyncio_default_fixture_loop_scope = "function"
54
+
55
+ [tool.poetry.plugins."swarmauri.measurements"]
56
+ TokenCountEstimatorMeasurement = "swarmauri_measurement_tokencountestimator.TokenCountEstimatorMeasurement:TokenCountEstimatorMeasurement"
@@ -0,0 +1,34 @@
1
+ from typing import Literal
2
+ from swarmauri_core.ComponentBase import ComponentBase
3
+ import tiktoken
4
+ from swarmauri_base.measurements.MeasurementBase import MeasurementBase
5
+ from swarmauri_base.measurements.MeasurementCalculateMixin import (
6
+ MeasurementCalculateMixin,
7
+ )
8
+
9
+
10
+ @ComponentBase.register_type(MeasurementBase, "TokenCountEstimatorMeasurement")
11
+ class TokenCountEstimatorMeasurement(MeasurementBase, MeasurementCalculateMixin):
12
+ """
13
+ A measurement class to estimate the number of tokens in a given text.
14
+ """
15
+
16
+ unit: str = "tokens"
17
+ type: Literal["TokenCountEstimatorMeasurement"] = "TokenCountEstimatorMeasurement"
18
+
19
+ def calculate(self, text: str, encoding="cl100k_base") -> int:
20
+ """
21
+ Calculate the number of tokens in the given text.
22
+ Args:
23
+ text (str): The input text to calculate token count for.
24
+ Returns:
25
+ int: The number of tokens in the text, or None if an error occurs.
26
+ """
27
+ try:
28
+ encoding = tiktoken.get_encoding(encoding)
29
+ except ValueError as e:
30
+ print(f"Error: {e}")
31
+ return None
32
+
33
+ tokens = encoding.encode(text)
34
+ return len(tokens)
@@ -0,0 +1,14 @@
1
+ from .TokenCountEstimatorMeasurement import TokenCountEstimatorMeasurement
2
+
3
+ __version__ = "0.6.0.dev26"
4
+ __long_desc__ = """
5
+
6
+ # Swarmauri TokenCountEstimator Plugin
7
+
8
+ This repository includes a TokenCountEstimator of a Swarmauri Plugin.
9
+
10
+ Visit us at: https://swarmauri.com
11
+ Follow us at: https://github.com/swarmauri
12
+ Star us at: https://github.com/swarmauri/swarmauri-sdk
13
+
14
+ """